// private float _speed = 1f; // // public float Speed // { // set // { // _speed = value; // // _speedIndex = 0; //// float distance = float.MaxValue; // for( int i = 1; i != _speedValues.Length; ++i ) // { // if( Mathf.Approximately( _speed, _speedValues[i] ) ) // { // _speedIndex = i; // break; // } //// if( Mathf.Abs( speed - _speedValues[i] ) < distance ) //// { //// distance = Mathf.Abs( speed - _speedValues[i] ); //// _speedIndex = i; //// } // } // // if( _speedIndex > 0 ) // _window.GetSequenceEditor().GetSequence().Speed = _speedValues[_speedIndex] * (_window.GetSequenceEditor().IsPlayingForward ? 1f : -1f); // else // _speedValueStrs[0].text = _speed.ToString("0.00")+'x'; // } // } public void OnGUI() { FSequence sequence = _window.GetSequenceEditor().Sequence; FrameRange viewRange = _window.GetSequenceEditor().ViewRange; GUI.backgroundColor = Color.white; GUI.contentColor = FGUI.GetTextColor(); bool goToFirst = false; bool goToPrevious = false; bool goToNext = false; bool goToLast = false; if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.Comma) { goToFirst = Event.current.shift; goToPrevious = !goToFirst; Event.current.Use(); _window.Repaint(); } if (Event.current.keyCode == KeyCode.Period) { goToLast = Event.current.shift; goToNext = !goToLast; Event.current.Use(); _window.Repaint(); } } if (GUI.Button(_firstFrameButtonRect, _firstFrame, EditorStyles.miniButtonLeft) || goToFirst) { GoToFrame(viewRange.Start); } if (GUI.Button(_previousFrameButtonRect, _previousFrame, EditorStyles.miniButtonMid) || goToPrevious) { GoToFrame(viewRange.Cull(sequence.CurrentFrame - 1)); } GUIStyle numberFieldStyle = new GUIStyle(EditorStyles.numberField); numberFieldStyle.alignment = TextAnchor.MiddleCenter; // Debug.Log("hot control: " + EditorGUIUtility.hotControl + " keyboard control: " + EditorGUIUtility.keyboardControl ); if (sequence != null) { if (sequence.CurrentFrame < 0) { EditorGUI.BeginChangeCheck(); string frameStr = EditorGUI.TextField(_currentFrameFieldRect, string.Empty, numberFieldStyle); if (EditorGUI.EndChangeCheck()) { int newCurrentFrame = 0; int.TryParse(frameStr, out newCurrentFrame); newCurrentFrame = Mathf.Clamp(newCurrentFrame, 0, sequence.Length); _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame); } } else { EditorGUI.BeginChangeCheck(); int newCurrentFrame = Mathf.Clamp(EditorGUI.IntField(_currentFrameFieldRect, sequence.CurrentFrame, numberFieldStyle), 0, sequence.Length); if (EditorGUI.EndChangeCheck()) { _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame); } } } if (GUI.Button(_nextFrameButtonRect, _nextFrame, EditorStyles.miniButtonMid) || goToNext) { GoToFrame(viewRange.Cull(sequence.CurrentFrame + 1)); } if (GUI.Button(_lastFrameButtonRect, _lastFrame, EditorStyles.miniButtonRight) || goToLast) { GoToFrame(viewRange.End); } // if( GUI.Button( _playBackwardButtonRect, isPlaying ? _pause : _playBackward, EditorStyles.miniButtonLeft ) ) // { // if( isPlaying ) // Pause(); // else // PlayBackwards(); // } if (GUI.Button(_stopButtonRect, _stop, EditorStyles.miniButtonLeft)) { Stop(); } if (Event.current.type == EventType.MouseUp && _playForwardButtonRect.Contains(Event.current.mousePosition)) { _window.GetSequenceEditor().IsPlayingForward = Event.current.button == 0; } bool isPlaying = Application.isPlaying ? _window.GetSequenceEditor().Sequence.IsPlaying : _window.GetSequenceEditor().IsPlaying; bool isPlayingForward = _window.GetSequenceEditor().IsPlayingForward; if (GUI.Button(_playForwardButtonRect, isPlaying ? _pause : (isPlayingForward ? _playForward : _playBackward), EditorStyles.miniButtonRight)) { if (isPlaying) { Pause(); } else if (isPlayingForward) { Play(); } else { PlayBackwards(); } } if (_showSpeedSlider) { GUI.Label(_speedLabelRect, _speedLabel); float currentSpeed = Mathf.Abs(_window.GetSequenceEditor().Sequence.Speed); EditorGUI.BeginChangeCheck(); float speed = GUI.HorizontalSlider(_speedSliderRect, currentSpeed, _speedValues[0], _speedValues[_speedValues.Length - 1]); if (EditorGUI.EndChangeCheck()) { int speedIndex = 0; float distance = float.MaxValue; for (int i = 0; i != _speedValues.Length; ++i) { if (Mathf.Abs(speed - _speedValues[i]) < distance) { distance = Mathf.Abs(speed - _speedValues[i]); speedIndex = i; } } // Speed = _speedValues[_speedIndex]; _window.GetSequenceEditor().Sequence.Speed = _speedValues[speedIndex] * (isPlayingForward ? 1f : -1f); } // if( !Mathf.Approximately(speed, currentSpeed) ) // { // _speedIndex = 0; // float distance = float.MaxValue; // for( int i = 0; i != _speedValues.Length; ++i ) // { // if( Mathf.Abs( speed - _speedValues[i] ) < distance ) // { // distance = Mathf.Abs( speed - _speedValues[i] ); // _speedIndex = i; // } // } // _window.GetSequenceEditor().GetSequence().Speed = _speedValues[_speedIndex] * (isPlayingForward ? 1f : -1f); // } // GUI.Label( _speedValueRect, _speedValueStrs[_speedIndex] ); EditorGUI.BeginChangeCheck(); speed = Mathf.Abs(EditorGUI.FloatField(_speedValueRect, currentSpeed)); if (EditorGUI.EndChangeCheck()) { _window.GetSequenceEditor().Sequence.Speed = speed * (isPlayingForward ? 1f : -1f); } } if (_showViewRange) { EditorGUI.PrefixLabel(_viewRangeLabelRect, _viewRangeLabel); EditorGUI.BeginChangeCheck(); viewRange.Start = EditorGUI.IntField(_viewRangeStartRect, viewRange.Start, numberFieldStyle); EditorGUI.PrefixLabel(_viewRangeDashRect, _viewRangeDash); viewRange.End = EditorGUI.IntField(_viewRangeEndRect, viewRange.End, numberFieldStyle); if (EditorGUI.EndChangeCheck()) { _window.GetSequenceEditor().SetViewRange(viewRange); } } }
public void OnGUI() { FSequence sequence = _window.GetSequenceEditor().GetSequence(); FrameRange viewRange = _window.GetSequenceEditor().GetViewRange(); GUI.contentColor = FGUI.GetTextColor(); bool goToFirst = false; bool goToPrevious = false; bool goToNext = false; bool goToLast = false; if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.Comma) { goToFirst = Event.current.shift; goToPrevious = !goToFirst; Event.current.Use(); _window.Repaint(); } if (Event.current.keyCode == KeyCode.Period) { goToLast = Event.current.shift; goToNext = !goToLast; Event.current.Use(); _window.Repaint(); } } if (GUI.Button(_firstFrameButtonRect, _firstFrame, EditorStyles.miniButtonLeft) || goToFirst) { GoToFrame(viewRange.Start); } if (GUI.Button(_previousFrameButtonRect, _previousFrame, EditorStyles.miniButtonMid) || goToPrevious) { GoToFrame(viewRange.Cull(sequence.GetCurrentFrame() - 1)); } GUIStyle numberFieldStyle = new GUIStyle(EditorStyles.numberField); numberFieldStyle.alignment = TextAnchor.MiddleCenter; // Debug.Log("hot control: " + EditorGUIUtility.hotControl + " keyboard control: " + EditorGUIUtility.keyboardControl ); if (sequence != null) { if (sequence.GetCurrentFrame() < 0) { EditorGUI.BeginChangeCheck(); string frameStr = EditorGUI.TextField(_currentFrameFieldRect, string.Empty, numberFieldStyle); if (EditorGUI.EndChangeCheck()) { int newCurrentFrame = 0; int.TryParse(frameStr, out newCurrentFrame); newCurrentFrame = Mathf.Clamp(newCurrentFrame, 0, sequence.Length); _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame); } } else { EditorGUI.BeginChangeCheck(); int newCurrentFrame = Mathf.Clamp(EditorGUI.IntField(_currentFrameFieldRect, sequence.GetCurrentFrame(), numberFieldStyle), 0, sequence.Length); if (EditorGUI.EndChangeCheck()) { _window.GetSequenceEditor().SetCurrentFrame(newCurrentFrame); } } } if (GUI.Button(_nextFrameButtonRect, _nextFrame, EditorStyles.miniButtonMid) || goToNext) { GoToFrame(viewRange.Cull(sequence.GetCurrentFrame() + 1)); } if (GUI.Button(_lastFrameButtonRect, _lastFrame, EditorStyles.miniButtonRight) || goToLast) { GoToFrame(viewRange.End); } // if( GUI.Button( _playBackwardButtonRect, _window.IsPlaying ? "[] Stop" : "< Play", EditorStyles.miniButtonLeft) ) // { // if( _window.IsPlaying ) // { // _window.Stop(); // } // else // { // _window.Play(); // } // } if (GUI.Button(_stopButtonRect, _stop, EditorStyles.miniButtonLeft)) { Stop(); } if (GUI.Button(_playForwardButtonRect, _window.IsPlaying ? _pause : _playForward, EditorStyles.miniButtonRight)) { if (_window.IsPlaying) { Pause(); } else { Play(); } } if (_showViewRange) { EditorGUI.PrefixLabel(_viewRangeLabelRect, _viewRangeLabel); EditorGUI.BeginChangeCheck(); viewRange.Start = EditorGUI.IntField(_viewRangeStartRect, viewRange.Start, numberFieldStyle); EditorGUI.PrefixLabel(_viewRangeDashRect, _viewRangeDash); viewRange.End = EditorGUI.IntField(_viewRangeEndRect, viewRange.End, numberFieldStyle); if (EditorGUI.EndChangeCheck()) { _window.GetSequenceEditor().SetViewRange(viewRange); } } }