Example #1
0
        private static void CreateChildren(SpriterDotNetBehaviour sdnBehaviour, Spriter spriter, GameObject parent)
        {
            SpriterEntity entity = spriter.Entities[0];
            int maxObjects = 0;

            foreach (SpriterAnimation animation in entity.Animations)
            {
                foreach (SpriterMainLineKey mainKey in animation.MainlineKeys)
                {
                    maxObjects = Math.Max(maxObjects, mainKey.ObjectRefs.Length);
                }
            }

            sdnBehaviour.Children = new GameObject[maxObjects];
            sdnBehaviour.Pivots = new GameObject[maxObjects];

            for (int i = 0; i < maxObjects; ++i)
            {
                GameObject pivot = new GameObject();
                GameObject child = new GameObject();

                sdnBehaviour.Pivots[i] = pivot;
                sdnBehaviour.Children[i] = child;

                pivot.transform.SetParent(parent.transform);
                child.transform.SetParent(pivot.transform);
                child.transform.localPosition = new Vector3(0, 0, DeltaZ * i);

                pivot.name = "pivot " + i;
                child.name = "child " + i;

                child.AddComponent<SpriteRenderer>();
            }
        }
        public static void Init(Spriter spriter)
        {
            foreach (SpriterEntity entity in spriter.Entities)
            {
                entity.Spriter = spriter;
                foreach (SpriterAnimation animation in entity.Animations)
                {
                    animation.Entity = entity;

                    InitInfos(animation);
                    InitVarDefs(animation);
                }
            }
        }
Example #3
0
        public static void Init(Spriter spriter)
        {
            foreach (SpriterEntity entity in spriter.Entities)
            {
                entity.Spriter = spriter;
                if (entity.ObjectInfos == null) entity.ObjectInfos = new SpriterObjectInfo[0];
                foreach (SpriterAnimation animation in entity.Animations)
                {
                    animation.Entity = entity;

                    InitInfos(animation);
                    InitVarDefs(animation);
                }
            }
        }
Example #4
0
        private static void LoadSprites(SpriterDotNetBehaviour sdnBehaviour, Spriter spriter, string rootFolder)
        {
            sdnBehaviour.Folders = new SdnFolder[spriter.Folders.Length];

            for (int i = 0; i < spriter.Folders.Length; ++i)
            {
                SpriterFolder folder = spriter.Folders[i];
                SdnFolder sdnFolder = new SdnFolder();
                sdnFolder.Files = new Sprite[folder.Files.Length];
                sdnBehaviour.Folders[i] = sdnFolder;

                for (int j = 0; j < folder.Files.Length; ++j)
                {
                    SpriterFile file = folder.Files[j];
                    string spritePath = rootFolder;
                    spritePath += "/";
                    spritePath += file.Name;

                    Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(spritePath);
                    if (sprite == null)
                    {
                        Debug.LogWarning("Unable to load sprite: " + spritePath);
                        continue;
                    }

                    sdnFolder.Files[j] = sprite;
                }
            }
        }
Example #5
0
        private static void SetDefaultPivots(Spriter spriter)
        {
            var infos = from e in spriter.Entities
                        from a in e.Animations
                        from t in a.Timelines
                        from k in t.Keys
                        let o = k.ObjectInfo
                        where o != null && (float.IsNaN(o.PivotX) || float.IsNaN(o.PivotY))
                        select o;

            foreach (SpriterObjectInfo info in infos)
            {
                SpriterFile file = spriter.Folders[info.FolderId].Files[info.FileId];
                info.PivotX = file.PivotX;
                info.PivotY = file.PivotY;
            }
        }