public void SetCurrentTime(float value) { if (!Mathf.Approximately(value, time.time)) { m_Time = AnimationKeyTime.Time(value, state.frameRate); StartPreview(); ClearCandidates(); ResampleAnimation(); } }
public void OnSelectionChanged() { // Set back time at beginning and stop recording. if (state != null) { m_Time = AnimationKeyTime.Time(0f, state.frameRate); } StopPreview(); StopPlayback(); }
public bool playFromBeginning = false; // TO DO public bool PlaybackUpdate() { if (!playing) { return(false); } float deltaTime = Time.realtimeSinceStartup - m_PreviousUpdateTime; m_PreviousUpdateTime = Time.realtimeSinceStartup; deltaTime *= playbackSpeed; float newTime = time.time + deltaTime; if (loop) { if (newTime > state.maxTime) { newTime = state.minTime; } else if (newTime < state.minTime) { newTime = state.maxTime; } } else { if (newTime > state.maxTime) { newTime = state.maxTime; StopPlayback(); } else if (newTime < state.minTime) { newTime = state.minTime; StopPlayback(); } } m_Time = AnimationKeyTime.Time(Mathf.Clamp(newTime, state.minTime, state.maxTime), state.frameRate); ResampleAnimation(); return(true); }
public bool StartPlayback() { if (!canPlay) { return(false); } if (!playing) { AnimationMode.StartAnimationPlaybackMode(); m_PreviousUpdateTime = Time.realtimeSinceStartup; // Auto-Preview when start playing StartPreview(); ClearCandidates(); } if (playFromBeginning) { if (playbackSpeed > 0) { m_Time = AnimationKeyTime.Time(state.minTime, state.frameRate); } else { m_Time = AnimationKeyTime.Time(state.maxTime, state.frameRate); } } else { if (!loop) { if (time.time >= state.maxTime && playbackSpeed > 0) { m_Time = AnimationKeyTime.Time(state.minTime, state.frameRate); } else if (time.time <= state.minTime && playbackSpeed < 0) { m_Time = AnimationKeyTime.Time(state.maxTime, state.frameRate); } } } return(true); }
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(); } }