private static SpriterEntity FetchOrCacheSpriterEntityDataFromFile(string path, string entityName, SpriterDotNetBehaviour spriterDotNetBehaviour) { if (SpriterEntityDatas.TryGetValue(new PathToEntity(path, entityName), out SpriterEntityData cachedEntityData)) { spriterDotNetBehaviour.SpriterData = cachedEntityData.data; return(cachedEntityData.entity); } string data = File.ReadAllText(path); Spriter spriter = SpriterReader.Default.Read(data); string rootFolder = Path.GetDirectoryName(path); SpriterEntity requestedEntity = null; foreach (SpriterEntity entity in spriter.Entities) { bool isRequestedEntity = entity.Name == entityName; SpriterData spriterData = CreateSpriterData(spriter, rootFolder, spriterDotNetBehaviour, isRequestedEntity); SpriterEntityData entityData = new SpriterEntityData(entity, spriterData); SpriterEntityDatas[new PathToEntity(path, entity.Name)] = entityData; if (isRequestedEntity) { requestedEntity = entity; spriterDotNetBehaviour.SpriterData = spriterData; } } return(requestedEntity); }
private static SpriterData CreateSpriterData(Spriter spriter, string rootFolder, SpriterDotNetBehaviour spriterDotNetBehaviour, bool andAssignAudioClips) { SpriterData data = ScriptableObject.CreateInstance <SpriterData>(); data.Spriter = spriter; data.FileEntries = LoadAssets(spriter, rootFolder, spriterDotNetBehaviour, andAssignAudioClips).ToArray(); return(data); }
private static SpriterData CreateSpriterData(Spriter spriter, string rootFolder, string name) { SpriterData data = ScriptableObject.CreateInstance <SpriterData>(); data.Spriter = spriter; data.FileEntries = LoadAssets(spriter, rootFolder).ToArray(); AssetDatabase.CreateAsset(data, rootFolder + "/" + name + ".asset"); AssetDatabase.SaveAssets(); return(data); }
private static void CreateSpriter(string path) { string data = File.ReadAllText(path); Spriter spriter = SpriterReader.Default.Read(data); string rootFolder = Path.GetDirectoryName(path); string name = Path.GetFileNameWithoutExtension(path); SpriterData spriterData = CreateSpriterData(spriter, rootFolder, name); foreach (SpriterEntity entity in spriter.Entities) { GameObject go = new GameObject(entity.Name); GameObject sprites = new GameObject(ObjectNameSprites); GameObject metadata = new GameObject(ObjectNameMetadata); SpriterDotNetBehaviour behaviour = go.AddComponent <SpriterDotNetBehaviour>(); behaviour.UseNativeTags = UseNativeTags; if (HasSound(entity)) { go.AddComponent <AudioSource>(); } sprites.SetParent(go); metadata.SetParent(go); ChildData cd = new ChildData(); CreateSprites(entity, cd, spriter, sprites); CreateCollisionRectangles(entity, cd, spriter, metadata); CreatePoints(entity, cd, spriter, metadata); behaviour.EntityIndex = entity.Id; behaviour.enabled = true; behaviour.SpriterData = spriterData; behaviour.ChildData = cd; GameObject prefab = CreatePrefab(go, rootFolder); EntityImported(entity, prefab); } if (UseNativeTags) { CreateTags(spriter); } }
public Effect(GameObject go1, SpriterDotNetUnity.SpriterData go2 = null) { prefab = go1; data = go2; }
public SpriterEntityData(SpriterEntity entity, SpriterData data) { this.entity = entity; this.data = data; }