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);
            }
        }
    //绘制数据传输策略类功能面板
    protected void DrawDataTransmitStrategyField()
    {
        if (!Application.isPlaying)
        {
            dtsEnum = (EditorDTSEnum)EditorGUILayout.EnumPopup("Data Transmit Strategy", dtsEnum);

            EditorGUILayout.BeginHorizontal();
            if (dtsEnum == EditorDTSEnum.CustomStrategy)
            {
                strategyName = EditorGUILayout.TextField("Strategy Name", strategyName);
            }
            else
            {
                strategyName = dtsEnum2Name(dtsEnum);
            }

            if (dtsEnum == EditorDTSEnum.EveryNFrame)
            {
                int       interval = 2;
                string [] paras;
                FduDTS_EveryNFrame.InterpolationOption interOp = FduDTS_EveryNFrame.InterpolationOption.Disable;
                FduDTS_EveryNFrame.ExtrapolationOption extraOp = FduDTS_EveryNFrame.ExtrapolationOption.Disable;
                int cachedPropertyCount = 1;
                int lerpSpeed           = 1;
                try
                {
                    paras               = parameter.Split('&');
                    interval            = int.Parse(paras[0]);
                    interOp             = (FduDTS_EveryNFrame.InterpolationOption) int.Parse(paras[1]);
                    extraOp             = (FduDTS_EveryNFrame.ExtrapolationOption) int.Parse(paras[2]);
                    cachedPropertyCount = int.Parse(paras[3]);
                    lerpSpeed           = int.Parse(paras[4]);
                }
                catch (System.Exception)
                {
                    interval = 2;
                }
                EditorGUILayout.EndHorizontal();


                interval            = EditorGUILayout.IntSlider("Frame Interval", interval, 2, FduGlobalConfig.EVERY_N_FRAME_MAX_FRAME);
                interOp             = (FduDTS_EveryNFrame.InterpolationOption)EditorGUILayout.EnumPopup("Interpolation Option", interOp);
                extraOp             = (FduDTS_EveryNFrame.ExtrapolationOption)EditorGUILayout.EnumPopup("Extrapolation Option", extraOp);
                cachedPropertyCount = EditorGUILayout.IntSlider("Cached Property Max Count", cachedPropertyCount, 1, 10);
                if (interOp == FduDTS_EveryNFrame.InterpolationOption.Lerp)
                {
                    lerpSpeed = EditorGUILayout.IntSlider("Lerp Speed", lerpSpeed, 1, 60);
                }
                parameter = interval + "&" + (int)interOp + "&" + (int)extraOp + "&" + cachedPropertyCount + "&" + lerpSpeed;
                EditorGUILayout.BeginHorizontal();
            }
            else
            {
                if (dtsEnum == EditorDTSEnum.OnClusterCommand)
                {
                    parameter = EditorGUILayout.TextField("Command Name", parameter);
                }
                else if (dtsEnum == EditorDTSEnum.CustomStrategy)
                {
                    parameter = EditorGUILayout.TextField("Custom string Parameter", parameter);
                }
                states[FduGlobalConfig.BIT_MASK[31]] = false;
            }

            EditorGUILayout.EndHorizontal();
        }
        else
        {
            FduObserverBase m_target = (FduObserverBase)target;
            if (m_target.getDataTransmitStrategy() != null)
            {
                EditorGUILayout.LabelField("Strategy Class Name", m_target.getDataTransmitStrategy().GetType().FullName);
            }
            else
            {
                EditorGUILayout.LabelField("Data-transmit-strategy class instance is null");
            }
        }
    }
        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);
            }
        }
Exemple #4
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);
            }
        }