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); }
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; }