Exemplo n.º 1
0
        ///Evaluate the curve keyframes if any
        void Evaluate_1_Curves(float time, float previousTime, float weight = 1f)
        {
            if (!HasAnyKey())
            {
                return;
            }

#if UNITY_EDITOR
            {
                if (!Application.isPlaying)
                {
                    if (time == previousTime && HasChanged())
                    {
                        if (!Prefs.autoKey)     //in case of no Auto-Key, store changed params
                        {
                            var    _value         = GetCurrentValueAsObject();
                            Action restore        = () => { SetCurrentValue(_value); };
                            Action commit         = () => { TryAutoKey(time); };
                            var    paramCallbacks = new CutsceneUtility.ChangedParameterCallbacks(restore, commit);
                            CutsceneUtility.changedParameterCallbacks[this] = paramCallbacks;
                        }
                        return; //auto-key or not, return if the parameter changed
                    }
                    if (!Prefs.autoKey)
                    {
                        CutsceneUtility.changedParameterCallbacks.Remove(this);
                    }
                }
            }
#endif


            //set lastEval by lerp snapshot to curves
            for (var i = 0; i < curves.Length; i++)
            {
                lastEval[i] = Mathf.LerpUnclamped(snapshot[i], curves[i].Evaluate(time), weight);
            }

            //set object value
            SetCurrentValue(lastEval);
        }
Exemplo n.º 2
0
        ////EDITOR EVAL////
        void Internal_Evaluate_Editor(float time, float previousTime, float weight = 1)
        {
            if (!enabled || targetObject == null || targetObject.Equals(null))
            {
                return;
            }

            if (!HasAnyKey())
            {
                return;
            }

                        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (time == previousTime && HasChanged())
                {
                    if (!Prefs.autoKey)                      //in case of no Auto-Key, store changed params
                    {
                        var    _value         = GetCurrentValue();
                        Action restore        = () => { SetCurrentValue(_value); };
                        Action commit         = () => { TryAutoKey(time); };
                        var    paramCallbacks = new CutsceneUtility.ChangedParameterCallbacks(restore, commit);
                        CutsceneUtility.changedParameterCallbacks[this] = paramCallbacks;
                    }
                    return;                     //auto-key or not, return if the parameter changed
                }
                if (!Prefs.autoKey)
                {
                    CutsceneUtility.changedParameterCallbacks.Remove(this);
                }
            }
                        #endif

            currentEval = GetEvalValue(time);

            if (weight < 1)
            {
                if (animatedType == typeof(int))
                {
                    currentEval = (int)Mathf.Lerp((int)snapshot, (int)currentEval, weight);
                }
                if (animatedType == typeof(float))
                {
                    currentEval = (float)Mathf.Lerp((float)snapshot, (float)currentEval, weight);
                }
                if (animatedType == typeof(Vector2))
                {
                    currentEval = (Vector2)Vector2.Lerp((Vector2)snapshot, (Vector2)currentEval, weight);
                }
                if (animatedType == typeof(Vector3))
                {
                    currentEval = (Vector3)Vector3.Lerp((Vector3)snapshot, (Vector3)currentEval, weight);
                }
                if (animatedType == typeof(Color))
                {
                    currentEval = (Color)Color.Lerp((Color)snapshot, (Color)currentEval, weight);
                }
            }

            SetCurrentValue(currentEval);
        }