public static Vector3 getNextScaleValue_Ex(Vector3 now, FduTransformObserver_Ex observer)
        {
            var dts = observer.getDataTransmitStrategy();

            if (dts == null || !dts.GetType().Equals(typeof(FduDTS_EveryNFrame)))
            {
                return(Vector3.zero);
            }
            FduDTS_EveryNFrame dtsN = (FduDTS_EveryNFrame)dts;

            try
            {
                FduDTS_EveryNFrame.InterpolationOption interOp = dtsN.getInterPolationOption();
                FduDTS_EveryNFrame.ExtrapolationOption extraOp = dtsN.getExtrapolationOption();

                int interval = dtsN.getInterval();
                int cur      = dtsN.getCurFrame();

                Vector3 offset    = Vector3.zero;
                Vector3 lastValue = observer.getCachedScale(observer.getCachedScaleCount() - 1);
                if (extraOp != FduDTS_EveryNFrame.ExtrapolationOption.Disable)
                {
                    int count = observer.getCachedScaleCount();
                    if (count >= 2)
                    {
                        if (extraOp == FduDTS_EveryNFrame.ExtrapolationOption.CachedEarliest)
                        {
                            offset = (lastValue - observer.getCachedScale(0)) / (count - 1.0f);
                        }
                        else if (extraOp == FduDTS_EveryNFrame.ExtrapolationOption.CachedLatest)
                        {
                            offset = (lastValue - observer.getCachedScale(count - 2));
                        }
                    }
                }
                lastValue = lastValue + offset;
                if (interOp == FduDTS_EveryNFrame.InterpolationOption.Disable)
                {
                    return(lastValue);
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.EstimateStep)
                {
                    int count = observer.getCachedScaleCount();
                    if (count >= 2)
                    {
                        float step = Vector3.Distance(lastValue - offset, observer.getCachedScale(count - 2)) / interval;
                        return(Vector3.MoveTowards(now, lastValue, step));
                    }
                    return(lastValue);
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.FixedStep)
                {
                    if ((interval - cur + 1) > 0)
                    {
                        var res = Vector3.Lerp(now, lastValue, 1.0f / (interval - cur + 1));
                        return(res);
                    }
                    else
                    {
                        return(lastValue);
                    }
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.Lerp)
                {
                    return(Vector3.Lerp(now, lastValue, Time.deltaTime * dtsN.getLerpSpeed()));
                }
                return(lastValue);
            }
            catch (System.Exception)
            {
                return(Vector3.zero);
            }
        }
        public static Quaternion getNextQuaternionValue_Ex(Quaternion now, FduTransformObserver_Ex observer)
        {
            var dts = observer.getDataTransmitStrategy();

            if (dts == null || !dts.GetType().Equals(typeof(FduDTS_EveryNFrame)))
            {
                return(Quaternion.identity);
            }
            FduDTS_EveryNFrame dtsN = (FduDTS_EveryNFrame)dts;

            try
            {
                FduDTS_EveryNFrame.InterpolationOption interOp = dtsN.getInterPolationOption();
                FduDTS_EveryNFrame.ExtrapolationOption extraOp = dtsN.getExtrapolationOption();

                int interval = dtsN.getInterval();
                int cur      = dtsN.getCurFrame();

                Vector3    offset     = Vector3.zero;
                Quaternion lastValue  = observer.getCachedRotation(observer.getCachedRotationCount() - 1);
                Vector3    eulerValue = lastValue.eulerAngles;
                if (extraOp != FduDTS_EveryNFrame.ExtrapolationOption.Disable)
                {
                    int count = observer.getCachedRotationCount();
                    if (count >= 2)
                    {
                        if (extraOp == FduDTS_EveryNFrame.ExtrapolationOption.CachedEarliest)
                        {
                            offset = (eulerValue - (observer.getCachedRotation(0).eulerAngles)) / (count - 1.0f);
                        }
                        else if (extraOp == FduDTS_EveryNFrame.ExtrapolationOption.CachedLatest)
                        {
                            offset = (eulerValue - (observer.getCachedRotation(count - 2)).eulerAngles);
                        }
                    }
                }
                eulerValue = eulerValue + offset;
                if (interOp == FduDTS_EveryNFrame.InterpolationOption.Disable)
                {
                    return(Quaternion.Euler(eulerValue));
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.FixedStep || interOp == FduDTS_EveryNFrame.InterpolationOption.EstimateStep)
                {
                    if ((interval - cur + 1) > 0)
                    {
                        var res = Quaternion.Lerp(now, Quaternion.Euler(eulerValue), 1.0f / (interval - cur + 1));
                        return(res);
                    }
                    else
                    {
                        return(Quaternion.Euler(eulerValue));
                    }
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.Lerp)
                {
                    return(Quaternion.Lerp(now, Quaternion.Euler(eulerValue), Time.deltaTime * dtsN.getLerpSpeed()));
                }
                return(Quaternion.Euler(eulerValue));
            }
            catch (System.Exception)
            {
                return(Quaternion.identity);
            }
        }
Exemplo n.º 3
0
        //计算下一个Float值
        public static float getNextFloatValue_new(float now, int propertyIndex, FduMultiAttributeObserverBase observer)
        {
            var dts = observer.getDataTransmitStrategy();

            if (dts == null || !dts.GetType().Equals(typeof(FduDTS_EveryNFrame)))
            {
                return(0);
            }
            FduDTS_EveryNFrame dtsN = (FduDTS_EveryNFrame)dts;

            try
            {
                FduDTS_EveryNFrame.InterpolationOption interOp = dtsN.getInterPolationOption();
                FduDTS_EveryNFrame.ExtrapolationOption extraOp = dtsN.getExtrapolationOption();

                int interval = dtsN.getInterval();
                int cur      = dtsN.getCurFrame();

                float offset    = 0;
                float lastValue = (float)observer.getCachedProperty_lastElement(propertyIndex);

                if (extraOp != FduDTS_EveryNFrame.ExtrapolationOption.Disable)
                {
                    int count = observer.getCachedProperytyCount(propertyIndex);
                    if (count >= 2)
                    {
                        if (extraOp == FduDTS_EveryNFrame.ExtrapolationOption.CachedEarliest)
                        {
                            offset = (lastValue - (float)observer.getCachedProperty_firstElement(propertyIndex)) / (count - 1);
                        }
                        else if (extraOp == FduDTS_EveryNFrame.ExtrapolationOption.CachedLatest)
                        {
                            offset = (lastValue - (float)observer.getCachedProperty_atArrayIndex(propertyIndex, count - 2));
                        }
                    }
                }
                lastValue = lastValue + offset;
                if (interOp == FduDTS_EveryNFrame.InterpolationOption.Disable)
                {
                    return(lastValue);
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.EstimateStep)
                {
                    int count = observer.getCachedProperytyCount(propertyIndex);
                    if (count >= 2)
                    {
                        float step = ((lastValue - offset) - (float)observer.getCachedProperty_atArrayIndex(propertyIndex, count - 2)) / interval;
                        return(now + step);
                    }
                    return(lastValue);
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.FixedStep)
                {
                    if ((interval - cur + 1) > 0)
                    {
                        float res = Mathf.Lerp(now, lastValue, 1.0f / (interval - cur + 1));
                        return(res);
                    }
                    else
                    {
                        return(lastValue);
                    }
                }
                else if (interOp == FduDTS_EveryNFrame.InterpolationOption.Lerp)
                {
                    return(Mathf.Lerp(now, lastValue, Time.deltaTime * dtsN.getLerpSpeed()));
                }
                return(lastValue);
            }
            catch (System.Exception)
            {
                return(0);
            }
        }