public static GameObject CreateFromPiskelFile(string piskelJson, PiskelSpriteSettings spriteSettings)
        {
            var piskel = PiskelDocument.FromPiskelJson(piskelJson);
            var root   = new GameObject(piskel.name);

            for (int i = 0; i < piskel.layers.Length; i++)
            {
                var piskelLayer = piskel.layers[i];
                var layer       = new GameObject(piskelLayer.name);
                layer.transform.parent = root.transform;

                var player = layer.AddComponent <PiskelRuntimePlayer>();
                player.frameRate = piskel.fps;
                piskel.GenerateTexturesAndSpritesForLayer(i, out player.textures, out player.sprites, spriteSettings);
            }
            return(root);
        }
示例#2
0
        public static PiskelDocument FromAnimation(AnimationClip animation)
        {
            var document = new PiskelDocument();

            document.name = animation.name;
            document.fps  = (int)animation.frameRate;

            var curves = AnimationUtility.GetObjectReferenceCurveBindings(animation);

            document.layers = new PiskelLayer[curves.Length];
            for (int i = 0; i < curves.Length; i++)
            {
                document.layers[i] = new PiskelLayer();
                var keyFramesList = AnimationUtility.GetObjectReferenceCurve(animation, curves[i]);
                var firstSprite   = (Sprite)keyFramesList[0].value;
                document.width  = (int)firstSprite.rect.width;
                document.height = (int)firstSprite.rect.height;
                document.layers[i].FillFromAnimationCurve(keyFramesList, curves[i]);
            }

            return(document);
        }
示例#3
0
        public static PiskelDocument FromPiskelJson(string json)
        {
            var jsonParse   = JsonUtility.FromJson <PiskelJsonFile>(json);
            var layoutFixer = new Regex(@"(""layout"":\[)(?:(\[[0-9,]+\])(,?))+(\],)");

            var piskelDocument = new PiskelDocument()
            {
                name        = jsonParse.piskel.name,
                description = jsonParse.piskel.description,
                fps         = jsonParse.piskel.fps,
                height      = jsonParse.piskel.height,
                width       = jsonParse.piskel.width,
            };

            piskelDocument.layers = new PiskelLayer[jsonParse.piskel.layers.Length];
            for (int i = 0; i < jsonParse.piskel.layers.Length; i++)
            {
                var jsonFixed = layoutFixer.Replace(jsonParse.piskel.layers[i], match =>
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append(match.Groups[1]);
                    for (int j = 0; j < match.Groups[2].Captures.Count; j++)
                    {
                        builder.Append("{\"array\":");
                        builder.Append(match.Groups[2].Captures[j]);
                        builder.Append("}");
                        builder.Append(match.Groups[3].Captures[j]);
                    }
                    builder.Append(match.Groups[4]);
                    return(builder.ToString());
                });
                piskelDocument.layers[i] = JsonUtility.FromJson <PiskelLayer>(jsonFixed);
            }

            return(piskelDocument);
        }