Time() public static method

public static Time ( float time, float frameRate ) : AnimationKeyTime
time float
frameRate float
return AnimationKeyTime
Beispiel #1
0
        public override bool PlaybackUpdate()
        {
            if (!playing)
            {
                return(false);
            }

            float deltaTime = Time.realtimeSinceStartup - m_PreviousUpdateTime;

            m_PreviousUpdateTime = Time.realtimeSinceStartup;

            float newTime = time.time + deltaTime;

            // looping
            if (newTime > state.maxTime)
            {
                newTime = state.minTime;
            }

            m_Time = AnimationKeyTime.Time(Mathf.Clamp(newTime, state.minTime, state.maxTime), state.frameRate);

            ResampleAnimation();

            return(true);
        }
        public void SaveSelectedKeys(List <AnimationWindowKeyframe> currentSelectedKeys)
        {
            List <AnimationWindowCurve> list = new List <AnimationWindowCurve>();

            foreach (AnimationWindowKeyframe current in currentSelectedKeys)
            {
                if (!list.Contains(current.curve))
                {
                    list.Add(current.curve);
                }
                List <AnimationWindowKeyframe> list2 = new List <AnimationWindowKeyframe>();
                foreach (AnimationWindowKeyframe current2 in current.curve.m_Keyframes)
                {
                    if (!currentSelectedKeys.Contains(current2) && AnimationKeyTime.Time(current.time, this.frameRate).frame == AnimationKeyTime.Time(current2.time, this.frameRate).frame)
                    {
                        list2.Add(current2);
                    }
                }
                foreach (AnimationWindowKeyframe current3 in list2)
                {
                    current.curve.m_Keyframes.Remove(current3);
                }
            }
            foreach (AnimationWindowCurve current4 in list)
            {
                this.SaveCurve(current4);
            }
        }
 public override void OnSelectionChanged()
 {
     if (this.state != null)
     {
         this.m_Time = AnimationKeyTime.Time(0f, this.state.frameRate);
     }
     this.StopPreview();
     this.StopPlayback();
 }
Beispiel #4
0
 private void SetCurrentTime(float value)
 {
     if (!Mathf.Approximately(value, this.time.time))
     {
         this.m_Time = AnimationKeyTime.Time(value, this.state.frameRate);
         this.StartRecording();
         this.ResampleAnimation();
     }
 }
 private void SetCurrentTime(float value)
 {
     if (!Mathf.Approximately(value, this.time.time))
     {
         this.m_Time = AnimationKeyTime.Time(value, this.state.frameRate);
         this.StartPreview();
         this.ClearCandidates();
         this.ResampleAnimation();
     }
 }
Beispiel #6
0
        public override void OnSelectionChanged()
        {
            // Set back time at beginning and stop recording.
            if (state != null)
            {
                m_Time = AnimationKeyTime.Time(0f, state.frameRate);
            }

            StopPreview();
            StopPlayback();
        }
        public static void AddSelectedKeyframes(AnimationWindowState state, AnimationKeyTime time)
        {
            List <AnimationWindowCurve> list = (state.activeCurves.Count <= 0) ? state.allCurves : state.activeCurves;

            foreach (AnimationWindowCurve current in list)
            {
                if (current.animationIsEditable)
                {
                    AnimationWindowUtility.AddKeyframeToCurve(state, current, AnimationKeyTime.Time(time.time - current.timeOffset, time.frameRate));
                }
            }
        }
Beispiel #8
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);
        }
        public static void RemoveKeyframes(AnimationWindowState state, AnimationWindowCurve[] curves, AnimationKeyTime time)
        {
            string undoLabel = "Remove Key";

            state.SaveKeySelection(undoLabel);
            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);
                    animationWindowCurve.RemoveKeyframe(time2);
                    state.SaveCurve(animationWindowCurve, undoLabel);
                }
            }
        }
        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);
                }
            }
        }
Beispiel #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);
                }
            }
        }
        public override bool PlaybackUpdate()
        {
            bool result;

            if (!this.playing)
            {
                result = false;
            }
            else
            {
                float num = Time.realtimeSinceStartup - this.m_PreviousUpdateTime;
                this.m_PreviousUpdateTime = Time.realtimeSinceStartup;
                float num2 = this.time.time + num;
                if (num2 > this.state.maxTime)
                {
                    num2 = this.state.minTime;
                }
                this.m_Time = AnimationKeyTime.Time(Mathf.Clamp(num2, this.state.minTime, this.state.maxTime), this.state.frameRate);
                this.ResampleAnimation();
                result = true;
            }
            return(result);
        }
        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();
            }
        }
Beispiel #14
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();
            }
        }
Beispiel #15
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();
            }
        }
        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);
        }