Ejemplo n.º 1
0
        /// <summary>
        /// Create path curve base on anchors.
        /// </summary>
        public virtual void CreateCurve()
        {
            if (anchors.Count == 0)
            {
                curve = null;
                return;
            }

            curve             = new VectorAnimationCurve();
            curve.preWrapMode = curve.postWrapMode = wrapmode;

            //Add frame keys to curve.
            float time = 0;

            for (int i = 0; i < anchors.Count - 1; i++)
            {
                curve.AddKey(time, anchors[i]);
                time += Vector3.Distance(anchors[i], anchors[i + 1]);
            }

            //Add last key.
            curve.AddKey(time, anchors[anchors.Count - 1]);

            if (isClose)
            {
                //Add close key[the first key]
                time += Vector3.Distance(anchors[anchors.Count - 1], anchors[0]);
                curve.AddKey(time, anchors[0]);
            }

            //Smooth curve keys out tangent.
            curve.SmoothTangents(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the curve base on anchors.
        /// </summary>
        public virtual void CreateCurve()
        {
            curve             = new VectorAnimationCurve();
            curve.preWrapMode = curve.postWrapMode = WrapMode.Loop;

            //Add frame keys to curve.
            float time = 0;

            for (int i = 0; i < anchorRoot.childCount - 1; i++)
            {
                curve.AddKey(time, anchorRoot.GetChild(i).localPosition);
                time += Vector3.Distance(anchorRoot.GetChild(i).position, anchorRoot.GetChild(i + 1).position);
            }

            //Add last key and loop key(the first key).
            curve.AddKey(time, anchorRoot.GetChild(anchorRoot.childCount - 1).localPosition);
            time += Vector3.Distance(anchorRoot.GetChild(anchorRoot.childCount - 1).position, anchorRoot.GetChild(0).position);
            curve.AddKey(time, anchorRoot.GetChild(0).localPosition);

            //Smooth the in and out tangents of curve keyframes.
            curve.SmoothTangents(0);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Rebuild path.
 /// </summary>
 public override void Rebuild()
 {
     curve = VectorAnimationCurve.FromAnchors(anchors.ToArray(), close);
 }
Ejemplo n.º 4
0
 protected virtual void Reset()
 {
     curve = null;
 }