public SpriteMetaData[] GetSpriteSheet(SpriteAlignment spriteAlignment, float customX, float customY)
        {
            SpriteMetaData[] metaData = new SpriteMetaData[frames.Count];

            for (int i = 0; i < frames.Count; i++)
            {
                ImportedSpriteInfo spriteInfo     = frames[i];
                SpriteMetaData     spriteMetaData = new SpriteMetaData();

                // sprite alignment
                spriteMetaData.alignment = (int)spriteAlignment;
                if (spriteAlignment == SpriteAlignment.Custom)
                {
                    spriteMetaData.pivot.x = customX;
                    spriteMetaData.pivot.y = customY;
                }

                spriteMetaData.name = spriteInfo.name;
                spriteMetaData.rect = new Rect(spriteInfo.x, spriteInfo.y, spriteInfo.width, spriteInfo.height);

                metaData[i] = spriteMetaData;
            }

            return(metaData);
        }
Beispiel #2
0
        private static bool GetSpritesFromJSON(JSONObject root, ImportedAnimationInfo importedInfos)
        {
            var list = root["frames"].Array;

            if (list == null)
            {
                Debug.LogWarning("No 'frames' array found in JSON created by Aseprite.");
                IssueVersionWarning();
                return(false);
            }

            foreach (var item in list)
            {
                ImportedSpriteInfo frame = new ImportedSpriteInfo();
                frame.name = item.Obj["filename"].Str.Replace(".ase", "");

                var frameValues = item.Obj["frame"].Obj;
                frame.width  = (int)frameValues["w"].Number;
                frame.height = (int)frameValues["h"].Number;
                frame.x      = (int)frameValues["x"].Number;
                frame.y      = importedInfos.height - (int)frameValues["y"].Number - frame.height;            // unity has a different coord system

                frame.duration = (int)item.Obj["duration"].Number;

                importedInfos.frames.Add(frame);
            }

            return(true);
        }