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); } }
public MovinShape(MovinLayer layer, BodymovinShape content) { this.content = content; if (content.paths == null || content.paths.Length < 1) { Debug.Log("DON'T DRAW SHAPE -> NO PTS"); return; } this.layer = layer; movin = layer.movin; Transform parent = layer.transform; /* FIRST SHAPE PROPS */ points = (BodyPoint[])content.paths[0].points.Clone(); motionSet = content.paths[0].animSets; closed = content.paths[0].closed; /* ANIM SETUP */ MotionSetup(ref animated, ref motion, motionSet); MotionSetup(ref strokeColorAnimated, ref mstrokec, content.strokeColorSets); MotionSetup(ref fillColorAnimated, ref mfillc, content.fillColorSets); /* GAMEOBJECT, MESH, MATERIAL */ transform = new RectTransform(); transform.SetParent(parent, false); transform.localPosition = -layer.content.anchorPoint; /* SETUP VECTOR */ Color stClr = (content.strokeColor == null) ? new Color(1, 1, 1) : new Color(content.strokeColor[0], content.strokeColor[1], content.strokeColor[2]); Color flClr = (content.fillColor == null) ? new Color(1, 1, 1) : new Color(content.fillColor[0], content.fillColor[1], content.fillColor[2]); currentStrokeColor = new Vector3(stClr.r, stClr.g, stClr.b); currentFillColor = new Vector3(flClr.r, flClr.g, flClr.b); fill = content.fillHidden || content.fillColor == null ? null : new SolidFill() { Color = flClr }; stroke = content.strokeHidden || content.strokeColor == null ? null : new Stroke() { Color = stClr, HalfThickness = content.strokeWidth * movin.strokeWidth }; props = new PathProperties() { Stroke = stroke }; shape = new Shape() { Fill = fill, PathProps = props, FillTransform = Matrix3.I() }; UpdateMesh(); // ADDITIONAL SHAPE PATHS slaves = new MovinShapeSlave[content.paths.Length - 1]; for (int i = 1; i <= slaves.Length; i++) { slaves[i - 1] = new MovinShapeSlave(this, content.paths[i], movin.strokeWidth); } }