Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (!Spline)
     {
         return;
     }
     // Runtime processing
     if (Application.isPlaying)
     {
         // Move at a constant speed?
         if (MoveByWorldUnits)
         {
             // either used cached values(slightly faster) or interpolate position now (more exact)
             // Note that we pass mTF and mDir by reference. These values will be changed by the Move methods
             mTransform.position = (FastInterpolation) ?
                                   Spline.MoveByFast(ref mTF, ref mDir, Speed * Time.deltaTime, Clamping) : // linear interpolate cached values
                                   Spline.MoveBy(ref mTF, ref mDir, Speed * Time.deltaTime, Clamping);      // interpolate now
         }
         else                                                                                               // Move at constant F
                // either used cached values(slightly faster) or interpolate position now (more exact)
                // Note that we pass mTF and mDir by reference. These values will be changed by the Move methods
         {
             mTransform.position = (FastInterpolation) ?
                                   Spline.MoveFast(ref mTF, ref mDir, Speed * Time.deltaTime, Clamping) : // linear interpolate cached values
                                   Spline.Move(ref mTF, ref mDir, Speed * Time.deltaTime, Clamping);      // interpolate now
         }
         // Rotate the transform to match the spline's orientation
         if (SetOrientation)
         {
             transform.rotation = Spline.GetOrientationFast(mTF);
         }
     }
     else // Editor processing: continuously place the transform to reflect property changes in the editor
     {
         InitPosAndRot();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Alter TF to reflect a movement over a certain portion of the spline, using connections if conditions match
 /// </summary>
 /// <param name="spline">the current spline</param>
 /// <param name="tf">the current TF value</param>
 /// <param name="direction">the current direction, 1 or -1</param>
 /// <param name="fDistance">the percentage of the spline to move</param>
 /// <param name="clamping">clamping mode</param>
 /// <param name="minMatchesNeeded">minimum number of tags that must match to use a connection</param>
 /// <param name="tags">list of tags to match</param>
 /// <returns>the interpolated position</returns>
 public Vector3 MoveConnection(ref CurvySpline spline, ref float tf, ref int direction, float fDistance, CurvyClamping clamping, int minMatchesNeeded, params string[] tags)
 {
     List<CurvyConnection> cons = GetConnectionsWithin(tf, direction, fDistance, minMatchesNeeded,true, tags);
     if (cons.Count > 0) {
         CurvyConnection con;
         if (cons.Count == 1)
             con = cons[0];
         else
             con = CurvyConnection.GetBestMatchingConnection(cons, tags);
         CurvySplineSegment cp=con.GetFromSpline(this);
         float cptf = SegmentToTF(cp);
         fDistance-= cptf-tf;
         CurvySplineSegment counterp=con.GetCounterpart(cp);
         tf = counterp.LocalFToTF(0);
         spline = counterp.Spline;
         return spline.MoveConnection(ref spline, ref tf, ref direction, fDistance, clamping, minMatchesNeeded, tags);
     }
     else
         return spline.Move(ref tf, ref direction, fDistance, clamping);
 }