コード例 #1
0
    void doUpdate()
    {
        if (!Spline || !Spline.IsInitialized)
        {
            return;
        }
        // Runtime processing
        if (Application.isPlaying)
        {
            int dir = Dir;
            // get the TF of the current distance.
            // Note: It's recommended to use the TF based methods in consecutive calls, as the distance based
            // methods need to convert distance to TF internally each time!
            float tf = Spline.DistanceToTF(mDistance);

            // Move using 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 tf, ref dir, Speed * Time.deltaTime, Clamping) :
                                  Spline.MoveBy(ref tf, ref dir, Speed * Time.deltaTime, Clamping);
            mDistance = Spline.TFToDistance(tf);
            // Rotate the transform to match the spline's orientation
            if (SetOrientation)
            {
                transform.rotation = Spline.GetOrientationFast(tf);
            }
            Dir = dir;
        }
        else  // Editor processing: continuously place the transform to reflect property changes in the editor
        {
            InitPosAndRot();
        }
    }
コード例 #2
0
ファイル: SplineWalker.cs プロジェクト: miccall/xwjl
    // Update is called once per frame
    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.MoveByFast(ref mTF, ref dir, Speed * Time.deltaTime, Clamping) : // linear interpolate cached values
                                      Spline.MoveBy(ref mTF, ref dir, 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 dir, Speed * Time.deltaTime, Clamping) : // linear interpolate cached values
                                      Spline.Move(ref mTF, ref dir, Speed * Time.deltaTime, Clamping);      // 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();
        }
    }