I'm trying to create component that builds SkeletonDataAsset at runtime. The input for this component are: atlas json file, skeleton data json file, and array of required materials. I don't want to use scriptable objects that spine provides me with (I don't want to put it in asset bundles).
I have latest spine-unity and spite-csharp taken from git repository (last commit to master 5 apr 2016)
[RequireComponent(typeof(SkeletonRenderer))]
public class SpineRendererRuntimeBuilder : MonoBehaviour
{
private SkeletonRenderer _skeletonRenderer;
[SerializeField]
[FormerlySerializedAs("Atlas Json File")]
private TextAsset _atlasJsonFile;
[SerializeField]
[FormerlySerializedAs("Skeleton Json File")]
private TextAsset _skeletonJsonFile;
[SerializeField]
[FormerlySerializedAs("Atlas Materials")]
private Material[] _atlasMaterials;
private void Awake()
{
_skeletonRenderer = GetComponent<SkeletonRenderer>();
}
private void Start()
{
var atlasAsset = ScriptableObject.CreateInstance<AtlasAsset>();
atlasAsset.atlasFile = _atlasJsonFile;
atlasAsset.materials = _atlasMaterials;
var skeletonDataAsset = ScriptableObject.CreateInstance<SkeletonDataAsset>();
skeletonDataAsset.atlasAssets = new[] { atlasAsset };
skeletonDataAsset.skeletonJSON = _skeletonJsonFile;
skeletonDataAsset.scale = 0.1f;
skeletonDataAsset.fromAnimation = new string[0];
skeletonDataAsset.toAnimation = new string[0];
_skeletonRenderer.skeletonDataAsset = skeletonDataAsset;
_skeletonRenderer.Initialize(false);
}
}
I've exported my model from Spine and provided necessary JSON's and materials to this component. But when i hit play i get exception. AtlasAsset unable to read atlas data from provided json:
Error reading atlas file for atlas asset:
Object reference not set to an instance of an object
at Spine.Atlas.ReadTuple (System.IO.TextReader reader, System.String[] tuple) [0x00007] in X:\rumyancevpavel\SpineTest\SpineTest\Assets\Spine\Spine\spine-csharp\src\Atlas.cs:203
at Spine.Atlas.Load (System.IO.TextReader reader, System.String imagesDir, TextureLoader textureLoader) [0x0005d] in X:\rumyancevpavel\SpineTest\SpineTest\Assets\Spine\Spine\spine-csharp\src\Atlas.cs:113
at Spine.Atlas..ctor (System.IO.TextReader reader, System.String dir, TextureLoader textureLoader) [0x0001c] in X:\rumyancevpavel\SpineTest\SpineTest\Assets\Spine\Spine\spine-csharp\src\Atlas.cs:89
at Spine.Unity.AtlasAsset.GetAtlas () [0x00077] in X:\rumyancevpavel\SpineTest\SpineTest\Assets\Spine\Spine\spine-unity\Asset Types\AtlasAsset.cs:66
UnityEngine.Debug:LogError(Object, Object)
Spine.Unity.AtlasAsset:GetAtlas() (at Assets/Spine/Spine/spine-unity/Asset Types/AtlasAsset.cs:70)
Spine.Unity.SkeletonDataAsset:GetSkeletonData(Boolean) (at Assets/Spine/Spine/spine-unity/Asset Types/SkeletonDataAsset.cs:97)
Spine.Unity.SkeletonRenderer:Initialize(Boolean) (at Assets/Spine/Spine/spine-unity/SkeletonRenderer.cs:181)
Spine.Unity.SkeletonAnimation:Initialize(Boolean) (at Assets/Spine/Spine/spine-unity/SkeletonAnimation.cs:137)
06 Apr 2016, 14:03
Sorry, my fail. This code actually works well. Didn't set TextAsset fields right.