Ejemplo n.º 1
0
    void doUpdate()
    {
        if (!Spline || !Spline.IsInitialized)
        {
            return;
        }
        // Runtime processing
        if (Application.isPlaying)
        {
            int dir = Dir;
            // 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.MoveByConnectionFast(ref Spline, ref mTF, ref dir, Speed * Time.deltaTime, Clamping, MinTagMatches, buildTags()) : // linear interpolate cached values
                                      Spline.MoveByConnection(ref Spline, ref mTF, ref dir, Speed * Time.deltaTime, Clamping, MinTagMatches, buildTags());      // interpolate now
            }
            else                                                                                                                                                // Move at constant F
                   // either used cached values(slightly faster) or interpolate position now (more exact)
                   // Note that we pass Spline, mTF and mDir by reference. These values will be changed by the MoveConnection methods
            {
                mTransform.position = (FastInterpolation) ?
                                      Spline.MoveConnectionFast(ref Spline, ref mTF, ref dir, Speed * Time.deltaTime, Clamping, MinTagMatches, buildTags()): // interpolate now
                                      Spline.MoveConnection(ref Spline, ref mTF, ref dir, Speed * Time.deltaTime, Clamping, MinTagMatches, buildTags());     // interpolate now
            }
            // Rotate the transform to match the spline's orientation
            if (SetOrientation)
            {
                transform.rotation = Spline.GetOrientationFast(mTF);
            }

            Dir = dir;
        }
        else // Editor processing: continuously place the transform to reflect property changes in the editor
        {
            InitPosAndRot();
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Alter TF to reflect a movement over a certain portion of the spline, using connections if conditions match. Unlike MoveConnection() a linear approximation will be used
 /// </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 MoveConnectionFast(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.MoveConnectionFast(ref spline, ref tf, ref direction, fDistance, clamping, minMatchesNeeded, tags);
     }
     else
         return MoveFast(ref tf, ref direction, fDistance, clamping);
 }