I guess, in theory, something like this is useful for automating things and not cluttering up the project folder with material, SkeletonData and Atlas assets.
Just to humor/explore the use case.
I got this:
Missing SkeletonData asset.
UnityEngine.Debug:LogError(Object, Object)
SkeletonRenderer:Reset() (at Assets/Spine/SkeletonRenderer.cs:81)
SkeletonAnimation:Reset() (at Assets/Spine/SkeletonAnimation.cs:65)
SkeletonRenderer:Awake() (at Assets/Spine/SkeletonRenderer.cs:99)
UnityEngine.GameObject:AddComponent()
SpineAssembler:GenerateCharacter() (at Assets/SpineAssembler.cs:33)
SpineAssembler:Start() (at Assets/SpineAssembler.cs:13)
and then this:
NullReferenceException: Object reference not set to an instance of an object
SkeletonDataAsset.GetSkeletonData (Boolean quiet) (at Assets/Spine/SkeletonDataAsset.cs:87)
SkeletonRenderer.Reset () (at Assets/Spine/SkeletonRenderer.cs:84)
SkeletonAnimation.Reset () (at Assets/Spine/SkeletonAnimation.cs:65)
SpineAssembler.GenerateCharacter () (at Assets/SpineAssembler.cs:36)
SpineAssembler.Start () (at Assets/SpineAssembler.cs:14)
Looks like it just has a few issues. Some seem easier to address than others.
I'm not sure why after this whole process, the mesh isn't generated until I click on the new object in the inspector. (at which point, it throws some inspector-related errors.)
I think these are the same three errors OP got.
Here's the SpineAssembler class I made but it's not working yet.
using UnityEngine;
using System.Collections;
public class SpineAssembler : MonoBehaviour {
// INSPECTOR ASSIGNED STUFF FOR TESTING
public Texture textureAsset;
public TextAsset atlasFile;
public TextAsset jsonFile;
GameObject characterObject;
SkeletonAnimation skeletonAnimation;
void Start ()
{
GenerateCharacter();
}
void GenerateCharacter ()
{
var atlasAsset = ScriptableObject.CreateInstance<AtlasAsset>();
atlasAsset.atlasFile = atlasFile;
var atlasMaterial = new Material(Shader.Find("Spine/Skeleton"));
atlasMaterial.mainTexture = textureAsset;
atlasAsset.materials = new[] { atlasMaterial };
var skeletonDataAsset = ScriptableObject.CreateInstance<SkeletonDataAsset>();
skeletonDataAsset.atlasAsset = atlasAsset;
skeletonDataAsset.skeletonJSON = jsonFile;
skeletonDataAsset.scale = 0.01f;
characterObject = new GameObject("0 THINGY");
skeletonAnimation = characterObject.AddComponent<SkeletonAnimation>();
skeletonAnimation.skeletonDataAsset = skeletonDataAsset;
skeletonAnimation.Reset();
skeletonAnimation.state.SetAnimation(0, "walk_0", true);
}
}