Beispiel #1
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;
            }
        }
        void DoInterpolate()
        {
            if (!mSegment.Spline.IsInitialized)
            {
                return;
            }
            bool calc = !Input.IsNone;

            if (calc)
            {
                System.Type metaType = System.Type.GetType(MetaDataType.Value);
                float       inputF   = (UseWorldUnits.Value) ? mSegment.DistanceToLocalF(Input.Value) : Input.Value;

                if (StorePosition.IsNone == false)
                {
                    StorePosition.Value = (UseCache.Value) ? mSegment.InterpolateFast(inputF) : mSegment.Interpolate(inputF);
                }

                if (StoreTangent.IsNone == false)
                {
                    StoreTangent.Value = mSegment.GetTangent(inputF);
                }

                if (StoreUpVector.IsNone == false)
                {
                    StoreUpVector.Value = mSegment.GetOrientationUpFast(inputF);
                }

                if (StoreRotation.IsNone == false)
                {
                    StoreRotation.Value = (StoreUpVector.IsNone) ? mSegment.GetOrientationFast(inputF) : Quaternion.LookRotation(mSegment.GetTangent(inputF), StoreUpVector.Value);
                }

                if (StoreScale.IsNone == false)
                {
                    CurvySplineSegment nextControlPoint = mSegment.Spline.GetNextControlPoint(mSegment);
                    StoreScale.Value = nextControlPoint
                        ? Vector3.Lerp(mSegment.transform.lossyScale, nextControlPoint.transform.lossyScale, inputF)
                        : mSegment.transform.lossyScale;
                }

                if (StoreTF.IsNone == false)
                {
                    StoreTF.Value = mSegment.LocalFToTF(inputF);
                }

                if (StoreSegmentDistance.IsNone == false)
                {
                    StoreSegmentDistance.Value = mSegment.LocalFToDistance(inputF);
                }

                if (StoreDistance.IsNone == false)
                {
                    StoreDistance.Value = (StoreSegmentDistance.IsNone == false) ? StoreSegmentDistance.Value + mSegment.Distance : mSegment.LocalFToDistance(inputF) + mSegment.Distance;
                }

                if (StoreSegmentF.IsNone == false)
                {
                    StoreSegmentF.Value = inputF;
                }

                if (metaType != null)
                {
                    if (metaType.IsSubclassOf(typeof(CurvyMetadataBase)) == false)
                    {
                        //this if statement's branch does not exclude classes inheriting from CurvyMetadataBase but not from CurvyInterpolatableMetadataBase, but that's ok, those classes are handled below
                        Debug.LogError("Meta data type " + metaType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>");
                    }
                    else
                    {
                        if (StoreMetadata.IsNone == false)
                        {
                            MethodInfo genericMethodInfo = mSegment.GetType().GetMethod("GetMetadata").MakeGenericMethod(metaType);
                            StoreMetadata.Value = (Object)genericMethodInfo.Invoke(mSegment, new System.Object[] { false });
                        }
                        if (StoreInterpolatedMetadata.IsNone == false)
                        {
                            Type argumentType = CurvyGetValue.GetInterpolatableMetadataGenericType(metaType);

                            if (argumentType == null)
                            {
                                Debug.LogError("Meta data type " + metaType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>");
                            }
                            else
                            {
                                MethodInfo genericMethodInfo = mSegment.GetType().GetMethod("GetInterpolatedMetadata").MakeGenericMethod(metaType, argumentType);
                                StoreInterpolatedMetadata.SetValue(genericMethodInfo.Invoke(mSegment, new System.Object[] { inputF }));
                            }
                        }
                    }
                }
            }
            // General
            if (StoreLength.IsNone == false)
            {
                StoreLength.Value = mSegment.Length;
            }

            if (StoreSegmentIndex.IsNone == false)
            {
                StoreSegmentIndex.Value = mSegment.Spline.GetSegmentIndex(mSegment);
            }
            if (StoreControlPointIndex.IsNone == false)
            {
                StoreControlPointIndex.Value = mSegment.Spline.GetControlPointIndex(mSegment);
            }
        }
        void DoInterpolate()
        {
            if (!mSegment.Spline.IsInitialized)
            {
                return;
            }
            bool calc = !Input.IsNone;

            if (calc)
            {
                System.Type metaType = System.Type.GetType(MetaDataType.Value);
                float       inputF   = (UseWorldUnits.Value) ? mSegment.DistanceToLocalF(Input.Value) : Input.Value;

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

                if (StoreTangent.UseVariable)
                {
                    StoreTangent.Value = mSegment.GetTangent(inputF);
                }

                if (StoreUpVector.UseVariable)
                {
                    StoreUpVector.Value = mSegment.GetOrientationUpFast(inputF);
                }

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

                if (StoreScale.UseVariable)
                {
                    StoreScale.Value = mSegment.InterpolateScale(inputF);
                }

                if (StoreTF.UseVariable)
                {
                    StoreTF.Value = mSegment.LocalFToTF(inputF);
                }

                if (StoreSegmentDistance.UseVariable)
                {
                    StoreSegmentDistance.Value = mSegment.LocalFToDistance(inputF);
                }

                if (StoreDistance.UseVariable)
                {
                    StoreDistance.Value = (StoreSegmentDistance.UseVariable) ? StoreSegmentDistance.Value + mSegment.Distance : mSegment.LocalFToDistance(inputF) + mSegment.Distance;
                }

                if (StoreSegmentF.UseVariable)
                {
                    StoreSegmentF.Value = inputF;
                }

                if (metaType != null)
                {
                    if (StoreMetadata.UseVariable)
                    {
                        StoreMetadata.Value = mSegment.GetMetaData(metaType);
                    }
                    if (StoreInterpolatedMetadata.useVariable)
                    {
                        StoreInterpolatedMetadata.SetValue(mSegment.InterpolateMetadata(metaType, inputF));
                    }
                }
            }
            // General
            if (StoreLength.UseVariable)
            {
                StoreLength.Value = mSegment.Length;
            }

            if (StoreSegmentIndex.UseVariable)
            {
                StoreSegmentIndex.Value = mSegment.SegmentIndex;
            }
            if (StoreControlPointIndex.UseVariable)
            {
                StoreControlPointIndex.Value = mSegment.ControlPointIndex;
            }
        }
        void DoInterpolate()
        {
            if (!mSpline.IsInitialized)
            {
                return;
            }

            System.Type metaDataType;
            {
                if (String.IsNullOrEmpty(MetaDataType.Value))
                {
                    metaDataType = null;
                }
                else
                {
#if NETFX_CORE
                    Type[] knownTypes = this.GetType().GetAllTypes();
#else
                    Type[] knownTypes = TypeExt.GetLoadedTypes();
#endif
                    metaDataType = knownTypes.FirstOrDefault(t => t.FullName == MetaDataType.Value);
                }
            }

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

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

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

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

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

                if (StoreScale.IsNone == false)
                {
                    float localF;
                    CurvySplineSegment segment          = mSpline.TFToSegment(f, out localF);
                    CurvySplineSegment nextControlPoint = segment.Spline.GetNextControlPoint(segment);
                    if (ReferenceEquals(segment, null) == false)
                    {
                        StoreScale.Value = nextControlPoint
                            ? Vector3.Lerp(segment.transform.lossyScale, nextControlPoint.transform.lossyScale, localF)
                            : segment.transform.lossyScale;
                    }
                    else
                    {
                        StoreScale.Value = Vector3.zero;
                    }
                }

                if (StoreTF.IsNone == false)
                {
                    StoreTF.Value = f;
                }

                if (StoreDistance.IsNone == false)
                {
                    StoreDistance.Value = (UseWorldUnits.Value) ? Input.Value : mSpline.TFToDistance(f);
                }
                if (metaDataType != null)
                {
                    if (metaDataType.IsSubclassOf(typeof(CurvyMetadataBase)) == false)
                    {
                        //this if statement's branch does not exclude classes inheriting from CurvyMetadataBase but not from CurvyInterpolatableMetadataBase, but that's ok, those classes are handled below
                        Debug.LogError("Meta data type " + metaDataType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>");
                    }
                    else
                    {
                        if (StoreMetadata.IsNone == false)
                        {
                            MethodInfo genericMethodInfo = mSpline.GetType().GetMethod("GetMetadata").MakeGenericMethod(metaDataType);
                            StoreMetadata.Value = (Object)genericMethodInfo.Invoke(mSpline, new System.Object[] { f });
                        }
                        if (StoreInterpolatedMetadata.IsNone == false)
                        {
                            Type argumentType = GetInterpolatableMetadataGenericType(metaDataType);

                            if (argumentType == null)
                            {
                                Debug.LogError("Meta data type " + metaDataType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>");
                            }
                            else
                            {
                                MethodInfo genericMethodInfo = mSpline.GetType().GetMethod("GetInterpolatedMetadata").MakeGenericMethod(metaDataType, argumentType);
                                StoreInterpolatedMetadata.SetValue(genericMethodInfo.Invoke(mSpline, new System.Object[] { f }));
                            }
                        }
                    }
                }


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

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

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

            if (StoreCount.IsNone == false)
            {
                StoreCount.Value = mSpline.Count;
            }
        }