コード例 #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
        void DoInterpolate()
        {
            if (!mSpline.IsInitialized)
            {
                return;
            }
            System.Type metaType = System.Type.GetType(MetaDataType.Value);
            bool        calc     = !Input.IsNone;

            if (calc)
            {
                float f = (UseWorldUnits.Value) ? mSpline.DistanceToTF(Input.Value) : Input.Value;

                if (StorePosition.UseVariable)
                {
                    StorePosition.Value = (UseCache.Value) ? mSpline.InterpolateFast(f) : mSpline.Interpolate(f);
                }

                if (StoreTangent.UseVariable)
                {
                    StoreTangent.Value = mSpline.GetTangent(f);
                }

                if (StoreUpVector.UseVariable)
                {
                    StoreUpVector.Value = mSpline.GetOrientationUpFast(f);
                }

                if (StoreRotation.UseVariable)
                {
                    StoreRotation.Value = (StoreUpVector.IsNone) ? mSpline.GetOrientationFast(f) : Quaternion.LookRotation(mSpline.GetTangent(f), StoreUpVector.Value);
                }

                if (StoreScale.UseVariable)
                {
                    StoreScale.Value = mSpline.InterpolateScale(f);
                }

                if (StoreTF.UseVariable)
                {
                    StoreTF.Value = f;
                }

                if (StoreDistance.UseVariable)
                {
                    StoreDistance.Value = (UseWorldUnits.Value) ? Input.Value : mSpline.TFToDistance(f);
                }
                if (metaType != null)
                {
                    if (StoreMetadata.UseVariable)
                    {
                        StoreMetadata.Value = mSpline.GetMetadata(metaType, f);
                    }
                    if (StoreInterpolatedMetadata.useVariable)
                    {
                        StoreInterpolatedMetadata.SetValue(mSpline.InterpolateMetadata(metaType, f));
                    }
                }


                CurvySplineSegment seg = null;
                float segF             = 0;
                if (StoreSegment.UseVariable)
                {
                    seg = getSegment(f, out segF);
                    StoreSegment.Value = seg.gameObject;
                }

                if (StoreSegmentF.UseVariable)
                {
                    if (!seg)
                    {
                        seg = getSegment(f, out segF);
                    }
                    StoreSegmentF.Value = segF;
                }

                if (StoreSegmentDistance.UseVariable)
                {
                    if (!seg)
                    {
                        seg = getSegment(f, out segF);
                    }
                    StoreSegmentDistance.Value = seg.LocalFToDistance(segF);
                }
            }
            // General
            if (StoreLength.UseVariable)
            {
                StoreLength.Value = mSpline.Length;
            }

            if (StoreCount.UseVariable)
            {
                StoreCount.Value = (mSpline is CurvySplineGroup) ? ((CurvySplineGroup)mSpline).Count : ((CurvySpline)mSpline).Count;
            }
        }
コード例 #3
0
    void Prepare()
    {
#if UNITY_EDITOR
        mPerfWatch.Reset();
        mPerfWatch.Start();
#endif
        if (Spline && StartMesh && ExtrusionParameter > 0)
        {
            StartMeshInfo = new MeshInfo(StartMesh, true, false);
            if (EndMesh)
            {
                EndMeshInfo = new MeshInfo(EndMesh, false, true);
            }
            else
            {
                EndMeshInfo = new MeshInfo(StartMesh, false, true);
            }



            // Calculate Steps
            float tf = FromTF;
            mSegmentInfo.Clear();
            FromTF = Mathf.Clamp01(FromTF);
            ToTF   = Mathf.Max(FromTF, Mathf.Clamp01(ToTF));
            Vector3 scale;
            if (FromTF != ToTF)
            {
                switch (Extrusion)
                {
                case MeshExtrusion.FixedF:
                    while (tf < ToTF)
                    {
                        scale = getScale(tf);
                        mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale));
                        tf += ExtrusionParameter;
                    }
                    break;

                case MeshExtrusion.FixedDistance:
                    float d = Spline.TFToDistance(FromTF);
                    tf = Spline.DistanceToTF(d);
                    while (tf < ToTF)
                    {
                        scale = getScale(tf);
                        mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, d, scale));
                        d += ExtrusionParameter;
                        tf = Spline.DistanceToTF(d);
                    }
                    break;

                case MeshExtrusion.Adaptive:
                    while (tf < ToTF)
                    {
                        scale = getScale(tf);
                        mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale));
                        int dir = 1;
                        Spline.MoveByAngle(ref tf, ref dir, ExtrusionParameter, CurvyClamping.Clamp, 0.005f);
                    }

                    break;
                }
                if (!Mathf.Approximately(tf, ToTF))
                {
                    tf = ToTF;
                }
                scale = getScale(tf);
                mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, scale));
            }
        }
#if UNITY_EDITOR
        mPerfWatch.Stop();
        DebugPerfPrepare = mPerfWatch.ElapsedTicks / (double)System.TimeSpan.TicksPerMillisecond;
        mPerfWatch.Reset();
#endif
    }