コード例 #1
0
ファイル: BodymovinContent.cs プロジェクト: UIWidgets/Movin
        public static BodymovinContent init(string jsonPath)
        {
            if (Resources.Load <TextAsset>(jsonPath) == null)
            {
                Debug.Log(">>>>  JSON NOT FOUND  <<<<");
                return(new BodymovinContent()
                {
                });
            }

            string json = Resources.Load <TextAsset>(jsonPath).text;

            JSONNode         data    = JSON.Parse(json);
            BodymovinContent content = new BodymovinContent {
                nm = data["nm"],
                v  = data["v"],
                fr = data["fr"],
                ip = data["ip"],
                op = data["op"],
                w  = data["w"],
                h  = data["h"]
            };

            content.w = Mathf.FloorToInt(content.w);
            content.h = Mathf.FloorToInt(content.h);

            ParseLayers(ref content, data);
            return(content);
        }
コード例 #2
0
ファイル: Movin.cs プロジェクト: UIWidgets/Movin
        private void MovinInit(string path, int sort = 0, float scale = 1f, float strokeWidth = 0.5f)
        {
            scale *= 0.1f; // Reduce default scale

            this.sort        = sort;
            this.scale       = scale;
            this.strokeWidth = strokeWidth;

            content = BodymovinContent.init(path);

            if (content.layers == null || content.layers.Length <= 0)
            {
                Debug.Log(">>>>  NO CONTENT LAYERS, ABORT!  <<<<");
                return;
            }

            transform.localScale     = Vector3.one * this.scale;
            transform.localPosition -= new Vector3(content.w / 2, -(content.h / 2), 0) * scale;

            frameRate   = content.fr;
            totalFrames = content.op;
            layers      = new MovinLayer[content.layers.Length];


            /* ----- CREATE LAYERS ----- */

            layersByIndex = new MovinLayer[content.highestLayerIndex + 1];

            for (int i = 0; i < content.layers.Length; i++)
            {
                MovinLayer layer = new MovinLayer(this, content.layers[i], content.layers.Length - i);

                layers[i] = layer;
                layersByIndex[layer.content.ind] = layers[i];
            }


            /* ----- SET PARENTS ----- */

            for (int i = 0; i < layers.Length; i++)
            {
                MovinLayer layer = layers[i];
                int        p     = layer.content.parent;
                if (p <= 0)
                {
                    continue;
                }

                layer.transform.SetParent(
                    layersByIndex[p].content.shapes.Length > 0
                        ? layersByIndex[p].transform.GetChild(0)
                        : layersByIndex[p].transform, false);
            }
        }
コード例 #3
0
ファイル: BodymovinContent.cs プロジェクト: UIWidgets/Movin
        public static void ParseLayers(ref BodymovinContent b, JSONNode n)
        {
            int assetLayers  = 0;
            int highestIndex = 0;

            if (n["assets"].Count > 0)
            {
                for (int q = 0; q < n["layers"].Count; q++)
                {
                    JSONNode d = n["layers"][q];

                    string r = d["refId"];
                    if (r != null)
                    {
                        for (int s = 0; s < n["assets"].Count; s++)
                        {
                            JSONNode a = n["assets"][s];
                            if (r == a["id"])
                            {
                                assetLayers += a["layers"].Count;
                                break;
                            }
                        }
                    }
                }
            }


            int j = 0;

            b.layers = new BodymovinLayer[n["layers"].Count + assetLayers];

            for (int q = 0; q < n["layers"].Count; q++)
            {
                JSONNode d = n["layers"][q];

                BodymovinLayer layer = ParseLayer(d);
                highestIndex = layer.ind > highestIndex ? layer.ind : highestIndex;
                b.layers[j]  = layer;

                if (layer.refId != null)
                {
                    for (int c = 0; c < n["assets"].Count; c++)
                    {
                        JSONNode a = n["assets"][c];

                        if (a["id"] == layer.refId)
                        {
                            for (int z = 0; z < a["layers"].Count; z++)
                            {
                                JSONNode e = a["layers"][z];
                                j++;

                                BodymovinLayer i = ParseLayer(e);
                                i.id         = a["id"];
                                i.ind       += b.layers.Length + j;
                                highestIndex = i.ind > highestIndex ? i.ind : highestIndex;
                                i.startTime  = layer.startTime;

                                if (i.parent > 0)
                                {
                                    i.parent += b.layers.Length + j + 1;
                                }
                                else
                                {
                                    i.parent         = layer.ind;
                                    i.positionOffset = -layer.anchorPoint;
                                }

                                b.layers[j] = i;
                            }

                            break;
                        }
                    }
                }

                j++;
            }

            b.highestLayerIndex = highestIndex;
        }