コード例 #1
0
        private static bool GetFramesFromJSON(ImportedAnimationSheet animationSheet, JSONObject root)
        {
            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)
            {
                ImportedAnimationFrame frame = new ImportedAnimationFrame();
                frame.name = Path.GetFileNameWithoutExtension(item.Obj["filename"].Str);

                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      = animationSheet.height - (int)frameValues["y"].Number - frame.height;            // unity has a different coord system

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

                animationSheet.frames.Add(frame);
            }

            return(true);
        }
コード例 #2
0
        private static bool GetFramesFromJson(ImportedAnimationSheet animationSheet, JsonObject root)
        {
            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)
            {
                ImportedAnimationFrame frame = new ImportedAnimationFrame();

                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      = animationSheet.Height - (int)frameValues["y"].Number - frame.Height;            // Unity has a different coord system

                var sourceSizeValues = item.Obj["sourceSize"].Obj;
                animationSheet.SourceSize = new Vector2Int((int)sourceSizeValues["w"].Number, (int)sourceSizeValues["h"].Number);

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

                animationSheet.Frames.Add(frame);
            }

            return(true);
        }
コード例 #3
0
        private static bool GetFramesFromJSON(ImportedAnimationSheet animationSheet, JSONObject root)
        {
            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)
            {
                ImportedAnimationFrame frame = new ImportedAnimationFrame();

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

                frame.trimmed = item.Obj["trimmed"].Boolean;

                var sourceSize = item.Obj["sourceSize"].Obj;
                frame.sourceSize.x = (int)sourceSize["w"].Number;
                frame.sourceSize.y = (int)sourceSize["h"].Number;

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

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

                animationSheet.frames.Add(frame);
            }

            return(true);
        }
コード例 #4
0
        private static ImportedAnimationSheet GetAnimationInfo(PyxelEditData data)
        {
            if (data == null)
            {
                return(null);
            }

            int tileWidth  = data.tileset.tileWidth;
            int tileHeight = data.tileset.tileHeight;

            int maxTileIndex = 0;

            ImportedAnimationSheet animationSheet = new ImportedAnimationSheet();

            animationSheet.width  = data.canvas.width;
            animationSheet.height = data.canvas.height;

            // animations
            animationSheet.animations = new List <ImportedAnimation>();
            for (int i = 0; i < data.animations.Count; i++)
            {
                var animationData = data.animations[i];

                ImportedAnimation importAnimation = new ImportedAnimation();

                importAnimation.name = animationData.name;

                importAnimation.firstSpriteIndex = animationData.baseTile;
                importAnimation.lastSpriteIndex  = animationData.baseTile + animationData.length - 1;

                maxTileIndex = Mathf.Max(maxTileIndex, importAnimation.lastSpriteIndex);

                ImportedAnimationFrame[] frames = new ImportedAnimationFrame[animationData.length];
                for (int frameIndex = 0; frameIndex < animationData.length; frameIndex++)
                {
                    ImportedAnimationFrame frame = new ImportedAnimationFrame();

                    frame.duration = animationData.frameDuration;
                    if (animationData.frameDurationMultipliers[i] != 100)
                    {
                        frame.duration *= (int)(animationData.frameDurationMultipliers[i] / 100f);
                    }

                    int tileIndex = animationData.baseTile + frameIndex;

                    int columnCount = data.canvas.width / tileWidth;

                    int column = tileIndex % columnCount;
                    int row    = tileIndex / columnCount;

                    frame.rect.y      = row * tileHeight;
                    frame.rect.x      = column * tileWidth;
                    frame.rect.width  = tileWidth;
                    frame.rect.height = tileHeight;

                    frames[frameIndex] = frame;
                }

                importAnimation.SetFrames(frames);

                animationSheet.animations.Add(importAnimation);
            }

            // gather all frames used by animations for the sprite sheet
            animationSheet.frames = new List <ImportedAnimationFrame>();
            foreach (var anim in animationSheet.animations)
            {
                foreach (var frame in anim.frames)
                {
                    animationSheet.frames.Add(frame);
                }
            }

            return(animationSheet);
        }