GetCurrentValue() public static method

public static GetCurrentValue ( UnityEditorInternal.AnimationWindowState state, AnimationWindowCurve curve ) : object
state UnityEditorInternal.AnimationWindowState
curve AnimationWindowCurve
return object
Example #1
0
        static public void ProcessModifications(IAnimationRecordingState state, UndoPropertyModification[] modifications)
        {
            GameObject root = state.activeRootGameObject;

            // Record modified properties
            for (int i = 0; i < modifications.Length; i++)
            {
                EditorCurveBinding binding = new EditorCurveBinding();

                PropertyModification prop = modifications[i].previousValue;
                Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(prop, root, out binding);
                if (type != null)
                {
                    object currentValue = CurveBindingUtility.GetCurrentValue(root, binding);

                    object previousValue = null;
                    if (!ValueFromPropertyModification(prop, binding, out previousValue))
                    {
                        previousValue = currentValue;
                    }

                    state.AddPropertyModification(binding, prop, modifications[i].keepPrefabOverride);
                    AddKey(state, binding, type, previousValue, currentValue);
                }
            }
        }
Example #2
0
        private static void AddKey(IAnimationRecordingState state, EditorCurveBinding binding, Type type, PropertyModification modification)
        {
            GameObject    activeRootGameObject = state.activeRootGameObject;
            AnimationClip activeAnimationClip  = state.activeAnimationClip;

            if ((activeAnimationClip.hideFlags & HideFlags.NotEditable) == HideFlags.None)
            {
                AnimationWindowCurve animationWindowCurve = new AnimationWindowCurve(activeAnimationClip, binding, type);
                object currentValue = CurveBindingUtility.GetCurrentValue(activeRootGameObject, binding);
                if (animationWindowCurve.length == 0)
                {
                    object value = null;
                    if (!AnimationRecording.ValueFromPropertyModification(modification, binding, out value))
                    {
                        value = currentValue;
                    }
                    if (state.frame != 0)
                    {
                        AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, value, type, AnimationKeyTime.Frame(0, activeAnimationClip.frameRate));
                    }
                }
                AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, currentValue, type, AnimationKeyTime.Frame(state.frame, activeAnimationClip.frameRate));
                state.SaveCurve(animationWindowCurve);
            }
        }
Example #3
0
        static private void ProcessVector3Modification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification, Transform target, string axis, float scale = 1.0f)
        {
            var binding = baseBinding;

            binding.propertyName = binding.propertyName.Remove(binding.propertyName.Length - 1, 1) + axis;

            object currentValue = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, binding);

            var previousModification = modification.previousValue;

            if (previousModification == null)
            {
                // create dummy
                previousModification              = new PropertyModification();
                previousModification.target       = target;
                previousModification.propertyPath = binding.propertyName;
                previousModification.value        = ((float)currentValue).ToString(CultureInfo.InvariantCulture.NumberFormat);
            }

            object previousValue = currentValue;

            ValueFromPropertyModification(previousModification, binding, out previousValue);

            state.AddPropertyModification(binding, previousModification, modification.keepPrefabOverride);

            if (scale != 1.0f)
            {
                previousValue = (object)((float)previousValue / scale);
                currentValue  = (object)((float)currentValue / scale);
            }

            AddKey(state, binding, typeof(float), previousValue, currentValue);
        }
 public static object GetCurrentValue(GameObject rootGameObject, EditorCurveBinding curveBinding)
 {
     if (rootGameObject != null)
     {
         return(AnimationWindowUtility.GetCurrentValue(rootGameObject, curveBinding));
     }
     return(CurveBindingUtility.GetCurrentValue(curveBinding));
 }
        public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowState state, AnimationWindowCurve curve, AnimationKeyTime time)
        {
            object currentValue            = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, curve.binding);
            Type   editorCurveValueType    = CurveBindingUtility.GetEditorCurveValueType(state.activeRootGameObject, curve.binding);
            AnimationWindowKeyframe result = AnimationWindowUtility.AddKeyframeToCurve(curve, currentValue, editorCurveValueType, time);

            state.SaveCurve(curve);
            return(result);
        }
Example #6
0
        public static AnimationWindowCurve CreateDefaultCurve(AnimationClip clip, GameObject rootGameObject, EditorCurveBinding binding)
        {
            Type editorCurveValueType  = CurveBindingUtility.GetEditorCurveValueType(rootGameObject, binding);
            AnimationWindowCurve curve = new AnimationWindowCurve(clip, binding, editorCurveValueType);
            object currentValue        = CurveBindingUtility.GetCurrentValue(rootGameObject, binding);

            if (clip.length == 0f)
            {
                AddKeyframeToCurve(curve, currentValue, editorCurveValueType, AnimationKeyTime.Time(0f, clip.frameRate));
                return(curve);
            }
            AddKeyframeToCurve(curve, currentValue, editorCurveValueType, AnimationKeyTime.Time(0f, clip.frameRate));
            AddKeyframeToCurve(curve, currentValue, editorCurveValueType, AnimationKeyTime.Time(clip.length, clip.frameRate));
            return(curve);
        }
Example #7
0
        private static void ProcessVector3Modification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification, Transform target, string axis)
        {
            EditorCurveBinding   editorCurveBinding   = baseBinding;
            PropertyModification propertyModification = modification.previousValue;

            editorCurveBinding.propertyName = editorCurveBinding.propertyName.Remove(editorCurveBinding.propertyName.Length - 1, 1) + axis;
            if (propertyModification == null)
            {
                propertyModification              = new PropertyModification();
                propertyModification.target       = target;
                propertyModification.propertyPath = editorCurveBinding.propertyName;
                object currentValue = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, editorCurveBinding);
                propertyModification.value = ((float)currentValue).ToString();
            }
            state.AddPropertyModification(editorCurveBinding, propertyModification, modification.keepPrefabOverride);
            AnimationRecording.AddKey(state, editorCurveBinding, typeof(float), propertyModification);
        }
        public static AnimationWindowCurve CreateDefaultCurve(AnimationWindowSelectionItem selectionItem, EditorCurveBinding binding)
        {
            AnimationClip        animationClip        = selectionItem.animationClip;
            Type                 editorCurveValueType = selectionItem.GetEditorCurveValueType(binding);
            AnimationWindowCurve animationWindowCurve = new AnimationWindowCurve(animationClip, binding, editorCurveValueType);
            object               currentValue         = CurveBindingUtility.GetCurrentValue(selectionItem.rootGameObject, binding);

            if (animationClip.length == 0f)
            {
                AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, currentValue, editorCurveValueType, AnimationKeyTime.Time(0f, animationClip.frameRate));
            }
            else
            {
                AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, currentValue, editorCurveValueType, AnimationKeyTime.Time(0f, animationClip.frameRate));
                AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, currentValue, editorCurveValueType, AnimationKeyTime.Time(animationClip.length, animationClip.frameRate));
            }
            return(animationWindowCurve);
        }
        public static void AddKeyframes(AnimationWindowState state, AnimationWindowCurve[] curves, AnimationKeyTime time)
        {
            string undoLabel = "Add Key";

            state.SaveKeySelection(undoLabel);
            state.ClearKeySelections();
            foreach (AnimationWindowCurve curve in curves)
            {
                if (curve.animationIsEditable)
                {
                    AnimationKeyTime        time2        = AnimationKeyTime.Time(time.time - curve.timeOffset, time.frameRate);
                    object                  currentValue = CurveBindingUtility.GetCurrentValue(state, curve);
                    AnimationWindowKeyframe keyframe     = AddKeyframeToCurve(curve, currentValue, curve.valueType, time2);
                    state.SaveCurve(curve, undoLabel);
                    state.SelectKey(keyframe);
                }
            }
        }
        private static PropertyModification CreateDummyPropertyModification(GameObject root, PropertyModification baseProperty, EditorCurveBinding binding)
        {
            PropertyModification propertyModification = new PropertyModification();

            propertyModification.target       = baseProperty.target;
            propertyModification.propertyPath = binding.propertyName;
            object currentValue = CurveBindingUtility.GetCurrentValue(root, binding);

            if (binding.isPPtrCurve)
            {
                propertyModification.objectReference = (UnityEngine.Object)currentValue;
            }
            else
            {
                propertyModification.value = ((float)currentValue).ToString();
            }
            return(propertyModification);
        }
Example #11
0
        public static void AddKeyframes(AnimationWindowState state, AnimationWindowCurve[] curves, AnimationKeyTime time)
        {
            string undoLabel = "Add Key";

            state.SaveKeySelection(undoLabel);
            state.ClearKeySelections();
            for (int i = 0; i < curves.Length; i++)
            {
                AnimationWindowCurve animationWindowCurve = curves[i];
                if (animationWindowCurve.animationIsEditable)
                {
                    AnimationKeyTime        time2        = AnimationKeyTime.Time(time.time - animationWindowCurve.timeOffset, time.frameRate);
                    object                  currentValue = CurveBindingUtility.GetCurrentValue(state, animationWindowCurve);
                    AnimationWindowKeyframe keyframe     = AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, currentValue, animationWindowCurve.valueType, time2);
                    state.SaveCurve(animationWindowCurve, undoLabel);
                    state.SelectKey(keyframe);
                }
            }
        }
Example #12
0
        static private void ProcessVector3Modification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification, Transform target, string axis)
        {
            var binding  = baseBinding;
            var property = modification.previousValue;

            binding.propertyName = binding.propertyName.Remove(binding.propertyName.Length - 1, 1) + axis;

            if (property == null)
            {
                // create dummy
                property              = new PropertyModification();
                property.target       = target;
                property.propertyPath = binding.propertyName;
                object currentValue = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, binding);
                property.value = ((float)currentValue).ToString();
            }

            state.AddPropertyModification(binding, property, modification.keepPrefabOverride);
            AddKey(state, binding, typeof(float), property);
        }
        private static void AddKey(AnimationWindowState state, EditorCurveBinding binding, Type type, PropertyModification modification)
        {
            GameObject           activeRootGameObject = state.activeRootGameObject;
            AnimationClip        activeAnimationClip  = state.activeAnimationClip;
            AnimationWindowCurve curve = new AnimationWindowCurve(activeAnimationClip, binding, type);
            object currentValue        = CurveBindingUtility.GetCurrentValue(activeRootGameObject, binding);

            if (curve.length == 0)
            {
                object outObject = null;
                if (!ValueFromPropertyModification(modification, binding, out outObject))
                {
                    outObject = currentValue;
                }
                if (state.frame != 0)
                {
                    AnimationWindowUtility.AddKeyframeToCurve(curve, outObject, type, AnimationKeyTime.Frame(0, activeAnimationClip.frameRate));
                }
            }
            AnimationWindowUtility.AddKeyframeToCurve(curve, currentValue, type, AnimationKeyTime.Frame(state.frame, activeAnimationClip.frameRate));
            state.SaveCurve(curve);
        }
Example #14
0
        static void AddKey(IAnimationRecordingState state, EditorCurveBinding binding, Type type, PropertyModification modification)
        {
            GameObject    root = state.activeRootGameObject;
            AnimationClip clip = state.activeAnimationClip;

            if ((clip.hideFlags & HideFlags.NotEditable) != 0)
            {
                return;
            }

            AnimationWindowCurve curve = new AnimationWindowCurve(clip, binding, type);

            // Add key at current frame
            object currentValue = CurveBindingUtility.GetCurrentValue(root, binding);

            if (state.addZeroFrame)
            {
                // Is it a new curve?
                if (curve.length == 0)
                {
                    object oldValue = null;
                    if (!ValueFromPropertyModification(modification, binding, out oldValue))
                    {
                        oldValue = currentValue;
                    }

                    if (state.currentFrame != 0)
                    {
                        AnimationWindowUtility.AddKeyframeToCurve(curve, oldValue, type, AnimationKeyTime.Frame(0, clip.frameRate));
                    }
                }
            }

            AnimationWindowUtility.AddKeyframeToCurve(curve, currentValue, type, AnimationKeyTime.Frame(state.currentFrame, clip.frameRate));

            state.SaveCurve(curve);
        }
Example #15
0
        private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
        {
            bool flag = false;

            if (node is AnimationWindowHierarchyPropertyNode)
            {
                AnimationWindowCurve[] curves = node.curves;
                if (curves == null || curves.Length == 0)
                {
                    return;
                }
                AnimationWindowCurve animationWindowCurve = curves[0];
                object currentValue = CurveBindingUtility.GetCurrentValue(this.state, animationWindowCurve);
                if (currentValue is float)
                {
                    float num         = (float)currentValue;
                    Rect  dragHotZone = new Rect(rect.xMax - 75f - 15f, rect.y, 15f, rect.height);
                    Rect  position    = new Rect(rect.xMax - 75f, rect.y, 50f, rect.height);
                    if (Event.current.type == EventType.MouseMove && position.Contains(Event.current.mousePosition))
                    {
                        AnimationWindowHierarchyGUI.s_WasInsideValueRectFrame = Time.frameCount;
                    }
                    EditorGUI.BeginChangeCheck();
                    if (animationWindowCurve.valueType == typeof(bool))
                    {
                        num = (float)((!GUI.Toggle(position, this.m_HierarchyItemValueControlIDs[row], num != 0f, GUIContent.none, EditorStyles.toggle)) ? 0 : 1);
                    }
                    else
                    {
                        int  num2  = this.m_HierarchyItemValueControlIDs[row];
                        bool flag2 = GUIUtility.keyboardControl == num2 && EditorGUIUtility.editingTextField && Event.current.type == EventType.KeyDown && (Event.current.character == '\n' || Event.current.character == '\u0003');
                        if (EditorGUI.s_RecycledEditor.controlID == num2 && Event.current.type == EventType.MouseDown && position.Contains(Event.current.mousePosition))
                        {
                            GUIUtility.keyboardControl = num2;
                        }
                        num = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, position, dragHotZone, num2, num, EditorGUI.kFloatFieldFormatString, this.m_AnimationSelectionTextField, true);
                        if (flag2)
                        {
                            GUI.changed = true;
                            Event.current.Use();
                        }
                    }
                    if (float.IsInfinity(num) || float.IsNaN(num))
                    {
                        num = 0f;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        string                  undoLabel = "Edit Key";
                        AnimationKeyTime        time      = AnimationKeyTime.Time(this.state.currentTime, animationWindowCurve.clip.frameRate);
                        AnimationWindowKeyframe animationWindowKeyframe = null;
                        foreach (AnimationWindowKeyframe current in animationWindowCurve.m_Keyframes)
                        {
                            if (Mathf.Approximately(current.time, this.state.currentTime))
                            {
                                animationWindowKeyframe = current;
                            }
                        }
                        if (animationWindowKeyframe == null)
                        {
                            AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, num, animationWindowCurve.valueType, time);
                        }
                        else
                        {
                            animationWindowKeyframe.value = num;
                        }
                        this.state.SaveCurve(animationWindowCurve, undoLabel);
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                this.state.ResampleAnimation();
            }
        }
        private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
        {
            bool curvesChanged = false;

            if (node is AnimationWindowHierarchyPropertyNode)
            {
                AnimationWindowCurve[] curves = node.curves;
                if (curves == null || curves.Length == 0)
                {
                    return;
                }

                // We do valuefields for dopelines that only have single curve
                AnimationWindowCurve curve = curves[0];
                object objectValue         = CurveBindingUtility.GetCurrentValue(state, curve);

                if (objectValue is float)
                {
                    float value = (float)objectValue;

                    Rect valueFieldDragRect = new Rect(rect.xMax - k_ValueFieldOffsetFromRightSide - k_ValueFieldDragWidth, rect.y, k_ValueFieldDragWidth, rect.height);
                    Rect valueFieldRect     = new Rect(rect.xMax - k_ValueFieldOffsetFromRightSide, rect.y, k_ValueFieldWidth, rect.height);

                    if (Event.current.type == EventType.MouseMove && valueFieldRect.Contains(Event.current.mousePosition))
                    {
                        s_WasInsideValueRectFrame = Time.frameCount;
                    }

                    EditorGUI.BeginChangeCheck();

                    if (curve.valueType == typeof(bool))
                    {
                        value = GUI.Toggle(valueFieldRect, m_HierarchyItemValueControlIDs[row], value != 0, GUIContent.none, EditorStyles.toggle) ? 1 : 0;
                    }
                    else
                    {
                        int  id = m_HierarchyItemValueControlIDs[row];
                        bool enterInTextField = (EditorGUIUtility.keyboardControl == id &&
                                                 EditorGUIUtility.editingTextField &&
                                                 Event.current.type == EventType.KeyDown &&
                                                 (Event.current.character == '\n' || (int)Event.current.character == 3));

                        //  Force back keyboard focus to float field editor when editing it.
                        //  TreeView forces keyboard focus on itself at mouse down and we lose focus here.
                        if (EditorGUI.s_RecycledEditor.controlID == id && Event.current.type == EventType.MouseDown && valueFieldRect.Contains(Event.current.mousePosition))
                        {
                            GUIUtility.keyboardControl = id;
                        }

                        value = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor,
                                                       valueFieldRect,
                                                       valueFieldDragRect,
                                                       id,
                                                       value,
                                                       "g5",
                                                       m_AnimationSelectionTextField,
                                                       true);
                        if (enterInTextField)
                        {
                            GUI.changed = true;
                            Event.current.Use();
                        }
                    }

                    if (float.IsInfinity(value) || float.IsNaN(value))
                    {
                        value = 0;
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        string undoLabel = "Edit Key";

                        AnimationKeyTime newAnimationKeyTime = AnimationKeyTime.Time(state.currentTime, curve.clip.frameRate);

                        AnimationWindowKeyframe existingKeyframe = null;
                        foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
                        {
                            if (Mathf.Approximately(keyframe.time, state.currentTime))
                            {
                                existingKeyframe = keyframe;
                            }
                        }

                        if (existingKeyframe == null)
                        {
                            AnimationWindowUtility.AddKeyframeToCurve(curve, value, curve.valueType, newAnimationKeyTime);
                        }
                        else
                        {
                            existingKeyframe.value = value;
                        }

                        state.SaveCurve(curve.clip, curve, undoLabel);
                        curvesChanged = true;
                    }
                }
            }

            if (curvesChanged)
            {
                state.ResampleAnimation();
            }
        }
Example #17
0
        private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
        {
            bool flag = false;

            if (!AnimationMode.InAnimationMode())
            {
                return;
            }
            if (node is AnimationWindowHierarchyPropertyNode)
            {
                AnimationWindowCurve[] curves = node.curves;
                if (curves == null || curves.Length == 0)
                {
                    return;
                }
                AnimationWindowCurve animationWindowCurve = curves[0];
                object currentValue         = CurveBindingUtility.GetCurrentValue(this.state.activeRootGameObject, animationWindowCurve.binding);
                Type   editorCurveValueType = CurveBindingUtility.GetEditorCurveValueType(this.state.activeRootGameObject, animationWindowCurve.binding);
                if (currentValue is float)
                {
                    float num      = (float)currentValue;
                    Rect  position = new Rect(rect.xMax - 75f, rect.y, 50f, rect.height);
                    if (Event.current.type == EventType.MouseMove && position.Contains(Event.current.mousePosition))
                    {
                        AnimationWindowHierarchyGUI.s_WasInsideValueRectFrame = Time.frameCount;
                    }
                    EditorGUI.BeginChangeCheck();
                    if (editorCurveValueType == typeof(bool))
                    {
                        num = (float)((!EditorGUI.Toggle(position, num != 0f)) ? 0 : 1);
                    }
                    else
                    {
                        int  controlID = GUIUtility.GetControlID(123456544, FocusType.Keyboard, position);
                        bool flag2     = GUIUtility.keyboardControl == controlID && EditorGUIUtility.editingTextField && Event.current.type == EventType.KeyDown && (Event.current.character == '\n' || Event.current.character == '\u0003');
                        if (EditorGUI.s_RecycledEditor.controlID == controlID && Event.current.type == EventType.MouseDown && position.Contains(Event.current.mousePosition))
                        {
                            GUIUtility.keyboardControl = controlID;
                        }
                        num = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, position, new Rect(0f, 0f, 0f, 0f), controlID, num, EditorGUI.kFloatFieldFormatString, this.m_AnimationSelectionTextField, false);
                        if (flag2)
                        {
                            GUI.changed = true;
                            Event.current.Use();
                        }
                    }
                    if (float.IsInfinity(num) || float.IsNaN(num))
                    {
                        num = 0f;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        AnimationWindowKeyframe animationWindowKeyframe = null;
                        foreach (AnimationWindowKeyframe current in animationWindowCurve.m_Keyframes)
                        {
                            if (Mathf.Approximately(current.time, this.state.time.time))
                            {
                                animationWindowKeyframe = current;
                            }
                        }
                        if (animationWindowKeyframe == null)
                        {
                            AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, num, editorCurveValueType, this.state.time);
                        }
                        else
                        {
                            animationWindowKeyframe.value = num;
                        }
                        this.state.SaveCurve(animationWindowCurve);
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                this.state.ResampleAnimation();
            }
        }
        private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
        {
            bool flag = false;

            if (AnimationMode.InAnimationMode())
            {
                EditorGUI.BeginDisabledGroup(this.state.animationIsReadOnly);
                if (node is AnimationWindowHierarchyPropertyNode)
                {
                    List <AnimationWindowCurve> curves = this.state.GetCurves(node, false);
                    if ((curves == null) || (curves.Count == 0))
                    {
                        return;
                    }
                    AnimationWindowCurve curve  = curves[0];
                    object currentValue         = CurveBindingUtility.GetCurrentValue(this.state.activeRootGameObject, curve.binding);
                    Type   editorCurveValueType = CurveBindingUtility.GetEditorCurveValueType(this.state.activeRootGameObject, curve.binding);
                    if (currentValue is float)
                    {
                        float num      = (float)currentValue;
                        Rect  position = new Rect(rect.xMax - 75f, rect.y, 50f, rect.height);
                        if ((Event.current.type == EventType.MouseMove) && position.Contains(Event.current.mousePosition))
                        {
                            s_WasInsideValueRectFrame = Time.frameCount;
                        }
                        EditorGUI.BeginChangeCheck();
                        if (editorCurveValueType == typeof(bool))
                        {
                            num = !EditorGUI.Toggle(position, num != 0f) ? ((float)0) : ((float)1);
                        }
                        else
                        {
                            int  id    = GUIUtility.GetControlID(0x75bcc20, FocusType.Keyboard, position);
                            bool flag2 = (((GUIUtility.keyboardControl == id) && EditorGUIUtility.editingTextField) && (Event.current.type == EventType.KeyDown)) && ((Event.current.character == '\n') || (Event.current.character == '\x0003'));
                            num = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, position, new Rect(0f, 0f, 0f, 0f), id, num, EditorGUI.kFloatFieldFormatString, this.m_AnimationSelectionTextField, false);
                            if (flag2)
                            {
                                GUI.changed = true;
                                Event.current.Use();
                            }
                        }
                        if (float.IsInfinity(num) || float.IsNaN(num))
                        {
                            num = 0f;
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            AnimationWindowKeyframe keyframe = null;
                            foreach (AnimationWindowKeyframe keyframe2 in curve.m_Keyframes)
                            {
                                if (Mathf.Approximately(keyframe2.time, this.state.time.time))
                                {
                                    keyframe = keyframe2;
                                }
                            }
                            if (keyframe == null)
                            {
                                AnimationWindowUtility.AddKeyframeToCurve(curve, num, editorCurveValueType, this.state.time);
                            }
                            else
                            {
                                keyframe.value = num;
                            }
                            this.state.SaveCurve(curve);
                            flag = true;
                        }
                    }
                }
                EditorGUI.EndDisabledGroup();
                if (flag)
                {
                    this.state.ResampleAnimation();
                }
            }
        }
 public static object GetCurrentValue(GameObject rootGameObject, EditorCurveBinding curveBinding)
 {
   if ((UnityEngine.Object) rootGameObject != (UnityEngine.Object) null)
     return AnimationWindowUtility.GetCurrentValue(rootGameObject, curveBinding);
   return CurveBindingUtility.GetCurrentValue(curveBinding);
 }
Example #20
0
        private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
        {
            bool flag1 = false;

            if (!AnimationMode.InAnimationMode())
            {
                return;
            }
            EditorGUI.BeginDisabledGroup(this.state.animationIsReadOnly);
            if (node is AnimationWindowHierarchyPropertyNode)
            {
                List <AnimationWindowCurve> curves = this.state.GetCurves(node, false);
                if (curves == null || curves.Count == 0)
                {
                    return;
                }
                AnimationWindowCurve curve       = curves[0];
                object      currentValue         = CurveBindingUtility.GetCurrentValue(this.state.activeRootGameObject, curve.binding);
                System.Type editorCurveValueType = CurveBindingUtility.GetEditorCurveValueType(this.state.activeRootGameObject, curve.binding);
                if (currentValue is float)
                {
                    float num      = (float)currentValue;
                    Rect  position = new Rect(rect.xMax - 75f, rect.y, 50f, rect.height);
                    if (Event.current.type == EventType.MouseMove && position.Contains(Event.current.mousePosition))
                    {
                        AnimationWindowHierarchyGUI.s_WasInsideValueRectFrame = Time.frameCount;
                    }
                    EditorGUI.BeginChangeCheck();
                    float f;
                    if (editorCurveValueType == typeof(bool))
                    {
                        f = !EditorGUI.Toggle(position, (double)num != 0.0) ? 0.0f : 1f;
                    }
                    else
                    {
                        int  controlId = GUIUtility.GetControlID(123456544, FocusType.Keyboard, position);
                        bool flag2     = GUIUtility.keyboardControl == controlId && EditorGUIUtility.editingTextField && Event.current.type == EventType.KeyDown && ((int)Event.current.character == 10 || (int)Event.current.character == 3);
                        f = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, position, new Rect(0.0f, 0.0f, 0.0f, 0.0f), controlId, num, EditorGUI.kFloatFieldFormatString, this.m_AnimationSelectionTextField, false);
                        if (flag2)
                        {
                            GUI.changed = true;
                            Event.current.Use();
                        }
                    }
                    if (float.IsInfinity(f) || float.IsNaN(f))
                    {
                        f = 0.0f;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        AnimationWindowKeyframe animationWindowKeyframe = (AnimationWindowKeyframe)null;
                        using (List <AnimationWindowKeyframe> .Enumerator enumerator = curve.m_Keyframes.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                AnimationWindowKeyframe current = enumerator.Current;
                                if (Mathf.Approximately(current.time, this.state.time.time))
                                {
                                    animationWindowKeyframe = current;
                                }
                            }
                        }
                        if (animationWindowKeyframe == null)
                        {
                            AnimationWindowUtility.AddKeyframeToCurve(curve, (object)f, editorCurveValueType, this.state.time);
                        }
                        else
                        {
                            animationWindowKeyframe.value = (object)f;
                        }
                        this.state.SaveCurve(curve);
                        flag1 = true;
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
            if (!flag1)
            {
                return;
            }
            this.state.ResampleAnimation();
        }
Example #21
0
        private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
        {
            bool curvesChanged = false;

            if (node is AnimationWindowHierarchyPropertyNode)
            {
                AnimationWindowCurve[] curves = node.curves;
                if (curves == null || curves.Length == 0)
                {
                    return;
                }

                // We do valuefields for dopelines that only have single curve
                AnimationWindowCurve curve = curves[0];
                object value = CurveBindingUtility.GetCurrentValue(state, curve);

                if (!curve.isPPtrCurve)
                {
                    Rect valueFieldDragRect = new Rect(rect.xMax - k_ValueFieldOffsetFromRightSide - k_ValueFieldDragWidth, rect.y, k_ValueFieldDragWidth, rect.height);
                    Rect valueFieldRect     = new Rect(rect.xMax - k_ValueFieldOffsetFromRightSide, rect.y, k_ValueFieldWidth, rect.height);

                    if (Event.current.type == EventType.MouseMove && valueFieldRect.Contains(Event.current.mousePosition))
                    {
                        s_WasInsideValueRectFrame = Time.frameCount;
                    }

                    EditorGUI.BeginChangeCheck();

                    if (curve.valueType == typeof(bool))
                    {
                        value = GUI.Toggle(valueFieldRect, m_HierarchyItemValueControlIDs[row], (float)value != 0, GUIContent.none, EditorStyles.toggle) ? 1f : 0f;
                    }
                    else
                    {
                        int  id = m_HierarchyItemValueControlIDs[row];
                        bool enterInTextField = (EditorGUIUtility.keyboardControl == id &&
                                                 EditorGUIUtility.editingTextField &&
                                                 Event.current.type == EventType.KeyDown &&
                                                 (Event.current.character == '\n' || (int)Event.current.character == 3));

                        //  Force back keyboard focus to float field editor when editing it.
                        //  TreeView forces keyboard focus on itself at mouse down and we lose focus here.
                        if (EditorGUI.s_RecycledEditor.controlID == id && Event.current.type == EventType.MouseDown && valueFieldRect.Contains(Event.current.mousePosition))
                        {
                            GUIUtility.keyboardControl = id;
                        }

                        if (curve.isDiscreteCurve)
                        {
                            value = EditorGUI.DoIntField(EditorGUI.s_RecycledEditor,
                                                         valueFieldRect,
                                                         valueFieldDragRect,
                                                         id,
                                                         (int)value,
                                                         EditorGUI.kIntFieldFormatString,
                                                         m_AnimationSelectionTextField,
                                                         true,
                                                         0);
                            if (enterInTextField)
                            {
                                GUI.changed = true;
                                Event.current.Use();
                            }
                        }
                        else
                        {
                            value = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor,
                                                           valueFieldRect,
                                                           valueFieldDragRect,
                                                           id,
                                                           (float)value,
                                                           "g5",
                                                           m_AnimationSelectionTextField,
                                                           true);
                            if (enterInTextField)
                            {
                                GUI.changed = true;
                                Event.current.Use();
                            }

                            if (float.IsInfinity((float)value) || float.IsNaN((float)value))
                            {
                                value = 0f;
                            }
                        }
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        string undoLabel = "Edit Key";

                        AnimationKeyTime newAnimationKeyTime = AnimationKeyTime.Time(state.currentTime, curve.clip.frameRate);
                        AnimationWindowUtility.AddKeyframeToCurve(curve, value, curve.valueType, newAnimationKeyTime);

                        state.SaveCurve(curve.clip, curve, undoLabel);
                        curvesChanged = true;
                    }
                }
            }

            if (curvesChanged)
            {
                //Fix for case 1382193: Stop recording any candidates if a property value field is modified
                if (AnimationMode.IsRecordingCandidates())
                {
                    state.ClearCandidates();
                }

                state.ResampleAnimation();
            }
        }