public void ResizeEventsRight(int delta) { int howMuchCanResize = int.MaxValue; // making them bigger? if (delta > 0) { for (int i = 0; i != _selectedEvents.Count; ++i) { int evtId = _selectedEvents[i].GetRuntimeObject().GetId(); int howMuchCanEvtResize = _selectedEvents[i]._evt.IsLastEvent() ? _sequence.Length : _selectedEvents[i]._evt.GetTrack().GetEvent(evtId + 1).Start; howMuchCanEvtResize -= _selectedEvents[i]._evt.End; if (howMuchCanResize > howMuchCanEvtResize) { howMuchCanResize = howMuchCanEvtResize; } } delta = Mathf.Clamp(delta, 0, howMuchCanResize); } else // making them smaller { for (int i = 0; i != _selectedEvents.Count; ++i) { int howMuchCanEvtResize = _selectedEvents[i]._evt.Length - _selectedEvents[i]._evt.GetMinLength(); if (howMuchCanResize > howMuchCanEvtResize) { howMuchCanResize = howMuchCanEvtResize; } } delta = Mathf.Clamp(delta, -howMuchCanResize, 0); } for (int i = 0; i != _selectedEvents.Count; ++i) { FrameRange evtRange = _selectedEvents[i]._evt.FrameRange; evtRange.End += delta; FUtility.Resize(_selectedEvents[i]._evt, evtRange); } }
// animation editing public static void ScaleAnimationClip(AnimationClip clip, FrameRange range) { if (clip == null) { return; } float oldLength = clip.length; float newLength = range.Length / clip.frameRate; AnimationClipCurveData[] curves = AnimationUtility.GetAllCurves(clip, true); // when scaling, we need to adjust the tangents otherwise the curves will get completely distorted float tangentMultiplier = oldLength / newLength; for (int i = 0; i != curves.Length; ++i) { AnimationCurve curve = curves[i].curve; if (newLength < oldLength) { for (int j = 0; j < curve.keys.Length; ++j) { Keyframe newKeyframe = new Keyframe((curve.keys[j].time / oldLength) * newLength, curve.keys[j].value, curve.keys[j].inTangent * tangentMultiplier, curve.keys[j].outTangent * tangentMultiplier); newKeyframe.tangentMode = curve.keys[j].tangentMode; curve.MoveKey(j, newKeyframe); } } else { for (int j = curve.keys.Length - 1; j >= 0; --j) { Keyframe newKeyframe = new Keyframe((curve.keys[j].time / oldLength) * newLength, curve.keys[j].value, curve.keys[j].inTangent * tangentMultiplier, curve.keys[j].outTangent * tangentMultiplier); newKeyframe.tangentMode = curve.keys[j].tangentMode; curve.MoveKey(j, newKeyframe); } } AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.PPtrCurve(curves[i].path, curves[i].type, curves[i].propertyName), curve); } clip.EnsureQuaternionContinuity(); EditorApplication.RepaintAnimationWindow(); EditorUtility.SetDirty(clip); }
// pixelsPerFrame can be calculated from rect and viewRange, but being cached on a higher level public void Render(Rect rect, FrameRange viewRange, float pixelsPerFrame, FrameRange validKeyframeRange) { Rect = rect; _eventRect = rect; int eventStartFrame = Mathf.Max(Evt.Start, viewRange.Start); int eventEndFrame = Mathf.Min(Evt.End, viewRange.End); _eventRect.xMin += (eventStartFrame - viewRange.Start) * pixelsPerFrame; // first set the start _eventRect.xMax = _eventRect.xMin + Mathf.Max(4, (eventEndFrame - eventStartFrame) * pixelsPerFrame); // then width if (_eventRect.Contains(Event.current.mousePosition)) { SequenceEditor.SetMouseHover(Event.current.mousePosition.x - rect.x, this); } RenderEvent(viewRange, validKeyframeRange); }
private void StopDragSelecting(Vector2 mousePos) { if (!_isDragSelecting) { return; } _isDragSelecting = false; FrameRange selectedRange = new FrameRange(); bool isSelectingTimelines; Rect selectionRect = GetDragSelectionRect(_dragSelectingStartPos, mousePos, out selectedRange, out isSelectingTimelines); if (!Event.current.shift && !Event.current.control) { SequenceEditor.DeselectAll(); } for (int i = 0; i != Editors.Count; ++i) { Rect trackRect = Editors[i].Rect; if (trackRect.yMin >= selectionRect.yMax) { break; } if (trackRect.yMax <= selectionRect.yMin) { continue; } if (Event.current.control) { Editors[i].DeselectEvents(selectedRange); } else { Editors[i].SelectEvents(selectedRange); } } }
// pixelsPerFrame can be calculated from rect and viewRange, but being cached on a higher level public void Render(Rect rect, FrameRange viewRange, float pixelsPerFrame, FrameRange validKeyframeRange) { Rect = rect; _eventRect = rect; int eventStartFrame = Mathf.Max(Evt.Start, viewRange.Start); int eventEndFrame = Mathf.Min(Evt.End, viewRange.End); _eventRect.xMin = SequenceEditor.GetXForFrame(eventStartFrame); _eventRect.xMax = SequenceEditor.GetXForFrame(eventEndFrame); if (_eventRect.Contains(Event.current.mousePosition)) { SequenceEditor.SetMouseHover(Event.current.mousePosition.x, this); } RenderEvent(viewRange, validKeyframeRange); }
private bool TryCapNode(MapNode chosenNode, List <FrameMaker> fillerFrameMakers) { Edge chosenEntry = chosenNode.UnjoinedEntries.RandomElement(random); FrameRange frameRange = chosenNode.frame.FrameRangeOff(chosenEntry); //frameRange = frameRange.WithOptionalEntriesRemoved(); FrameMaker frameMaker = fillerFrameMakers.RandomElement(random); MapNode newNode = TryAddNodeToMap(frameMaker, frameRange, EntryCountPreference.Min); if (newNode == null) { return(false); } chosenNode.Join(chosenEntry, newNode); //map.AddMapNode(chosenNode); return(true); }
public override void Render(int id, Rect rect, int headerWidth, FrameRange viewRange, float pixelsPerFrame) { base.Render(id, rect, headerWidth, viewRange, pixelsPerFrame); switch (Event.current.type) { case EventType.DragUpdated: if (rect.Contains(Event.current.mousePosition)) { int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(_track.Sequence.FrameRate); int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); DragAndDrop.visualMode = numAnimationsDragged > 0 && _track.CanAddAt(frame) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; Event.current.Use(); } break; case EventType.DragPerform: if (rect.Contains(Event.current.mousePosition)) { AnimationClip animClip = FAnimationEventInspector.GetAnimationClipDragAndDrop(_track.Sequence.FrameRate); if (animClip && Mathf.Approximately(animClip.frameRate, _track.Sequence.FrameRate)) { int frame = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); int maxLength; if (_track.CanAddAt(frame, out maxLength)) { FPlayAnimationEvent animEvt = FEvent.Create <FPlayAnimationEvent>(new FrameRange(frame, frame + Mathf.Min(maxLength, Mathf.RoundToInt(animClip.length * animClip.frameRate)))); _track.Add(animEvt); FAnimationEventInspector.SetAnimationClip(animEvt, animClip); DragAndDrop.AcceptDrag(); } } Event.current.Use(); } break; } }
public void SetViewRange(FrameRange viewRange) { FrameRange sequenceRange = new FrameRange(0, _sequence.Length); viewRange.Start = sequenceRange.Cull(viewRange.Start); viewRange.End = sequenceRange.Cull(viewRange.End); if (viewRange.End <= viewRange.Start) { if (viewRange.Start == _sequence.Length) { viewRange.End = _sequence.Length; viewRange.Start = viewRange.End - 1; } else { viewRange.End = viewRange.Start + 1; } } _viewRange = viewRange; }
public void OnGUI() { FrameRange viewRange = _window.GetSequenceEditor().ViewRange; GUI.backgroundColor = Color.white; GUI.contentColor = FGUI.GetTextColor(); GUIStyle numberFieldStyle = new GUIStyle(EditorStyles.numberField); numberFieldStyle.alignment = TextAnchor.MiddleCenter; 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 static void Resize( FEvent evt, FrameRange newFrameRange ) // { // if( evt.FrameRange == newFrameRange || newFrameRange.Start > newFrameRange.End ) // return; // // if( newFrameRange.Length < evt.GetMinLength() || newFrameRange.Length > evt.GetMaxLength() ) // { // Debug.LogError( string.Format("Trying to resize an Event to [{0},{1}] (length: {2}) which isn't a valid length, should be between [{3},{4}]", newFrameRange.Start, newFrameRange.End, newFrameRange.Length, evt.GetMinLength(), evt.GetMaxLength() ), evt ); // return; // } // // bool changedLength = evt.Length != newFrameRange.Length; // // if( !evt.GetTrack().CanAdd( evt, newFrameRange ) ) // return; // // Undo.RecordObject( evt, changedLength ? "Resize Event" : "Move Event" ); // // evt.Start = newFrameRange.Start; // evt.End = newFrameRange.End; // // if( changedLength ) // { // if( evt is FPlayAnimationEvent ) // { // FPlayAnimationEvent animEvt = (FPlayAnimationEvent)evt; // // if( animEvt.IsAnimationEditable() ) // { // FAnimationEventInspector.ScaleAnimationClip( animEvt._animationClip, animEvt.FrameRange ); // } // } // else if( evt is FTimescaleEvent ) // { // ResizeAnimationCurve( (FTimescaleEvent)evt, newFrameRange ); // } // } // // EditorUtility.SetDirty( evt ); // // if( FSequenceEditorWindow.instance != null ) // FSequenceEditorWindow.instance.Repaint(); // } public static void Rescale(FEvent evt, FrameRange newFrameRange) { if (evt.FrameRange == newFrameRange) { return; } Undo.RecordObject(evt, string.Empty); evt.Start = newFrameRange.Start; evt.End = newFrameRange.End; //if (evt is FPlayAnimationEvent) //{ // FPlayAnimationEvent animEvt = (FPlayAnimationEvent)evt; // if (animEvt._animationClip != null) // { // if (Flux.FUtility.IsAnimationEditable(animEvt._animationClip)) // { // animEvt._animationClip.frameRate = animEvt.Sequence.FrameRate; // EditorUtility.SetDirty(animEvt._animationClip); // } // else if (Mathf.RoundToInt(animEvt._animationClip.frameRate) != animEvt.Sequence.FrameRate) // { // Debug.LogError(string.Format("Removed AnimationClip '{0}' ({1} fps) from Animation Event '{2}'", // animEvt._animationClip.name, // animEvt._animationClip.frameRate, // animEvt.name), animEvt); // animEvt._animationClip = null; // } // } //} EditorUtility.SetDirty(evt); }
public Frame TryMakeFrame(FrameRange frameRangeConstraints, System.Random random = null) { random = random ?? new System.Random(); List <FrameRange> preferredFrameRanges = PreferredFrameRanges; preferredFrameRanges.Shuffle(random); //Debug.Log("Constraints: " + frameRangeConstraints); foreach (FrameRange preferredFrameRange in preferredFrameRanges) { FrameRange possibleFrameRange = frameRangeConstraints.Intersection(preferredFrameRange); //Debug.Log("Possible FR: " + possibleFrameRange); if (!possibleFrameRange.IsEmpty) { Frame chosenFrame = possibleFrameRange.RandomFrame(random); //Debug.Log("Chosen Frame: " + chosenFrame); return(chosenFrame); } } return(null); }
public void OnGUI() { if (_timelineEditors == null) { return; } if (_timelineEditors.Count == 0) { if (_renderingOnEditorWindow) { _renderingOnEditorWindow.ShowNotification(new GUIContent("Drag GameObjects Here")); } } _pixelsPerFrame = (_sequenceRect.width - _timelineHeaderWidth) / _viewRange.Length; if (_timelineEditorIds.Length != _timelineEditors.Count) { _timelineEditorIds = new int[_timelineEditors.Count]; _timelineEditorHeights = new float[_timelineEditors.Count]; } int timelineHeaderResizerId = EditorGUIUtility.GetControlID(FocusType.Passive); float sequenceViewHeight = 0; for (int i = 0; i != _timelineEditors.Count; ++i) { _timelineEditorIds[i] = EditorGUIUtility.GetControlID(FocusType.Passive); _timelineEditorHeights[i] = _timelineEditors[i].GetHeight(); sequenceViewHeight += _timelineEditorHeights[i]; _timelineEditors[i].ReserveTrackGuiIds(); } _scrollPos.y = GUI.VerticalScrollbar(_verticalScrollerRect, _scrollPos.y, Mathf.Min(_sequenceRect.height, sequenceViewHeight), 0, sequenceViewHeight); Rect scrolledViewRect = _viewRect; // scrolledViewRect.yMin -= _scrollPos.y; GUI.BeginGroup(scrolledViewRect); Rect timelineRect = _sequenceRect; timelineRect.y = -_scrollPos.y; timelineRect.height = 0; Rect timelineDraggedRect = new Rect(); // Debug.Log( "sequence: " + _sequenceRect + " scrubber: " + _timeScrubberRect + " width: " + _timelineHeaderWidth ); Handles.color = FGUI.GetLineColor(); for (int i = 0; i != _timelineEditors.Count; ++i) { timelineRect.yMin = timelineRect.yMax; timelineRect.height = _timelineEditors[i].GetHeight(); if (_timelineDragged != null) { if (_timelineDragged == _timelineEditors[i]) { timelineDraggedRect = timelineRect; continue; } else if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()]) { if (i < _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y < timelineRect.yMax) { _timelineEditors[i].SetOffset(new Vector2(0, _timelineDragged.GetHeight())); } else if (i > _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y > timelineRect.yMin) { _timelineEditors[i].SetOffset(new Vector2(0, -_timelineDragged.GetHeight())); } else { _timelineEditors[i].SetOffset(Vector2.zero); } } } _timelineEditors[i].Render(_timelineEditorIds[i], timelineRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame); } if (_timelineDragged != null) { if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()]) { timelineDraggedRect.y = Event.current.mousePosition.y; } // timelineRect.yMin = Event.current.mousePosition.y; // timelineRect.height = _timelineDragged.GetHeight(); _timelineDragged.Render(_timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()], timelineDraggedRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame); } switch (Event.current.type) { case EventType.MouseDown: // bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt); // // if( middleClick ) // middle button if (Event.current.button == 0) { StartDragSelecting(Event.current.mousePosition); Event.current.Use(); } break; case EventType.MouseUp: if (_isDragSelecting) { StopDragSelecting(Event.current.mousePosition); Event.current.Use(); } break; case EventType.Ignore: if (_isDragSelecting) { StopDragSelecting(Event.current.mousePosition); } break; case EventType.Repaint: if (_isDragSelecting) { OnDragSelecting(Event.current.mousePosition); } break; } GUI.EndGroup(); if (_viewRange.End > _sequence.Length) { _viewRange.Start = 0; _viewRange.End = _sequence.Length; } int newT = FGUI.TimeScrubber(_timeScrubberRect, _sequence.GetCurrentFrame(), _sequence.FrameRate, _viewRange); if (newT != _sequence.GetCurrentFrame()) { // _sequence.SetCurrentFrameEditor( newT ); SetCurrentFrame(newT); if (Application.isPlaying) { Play(false); Pause(); } // Repaint(); // SceneView.RepaintAll(); // UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); // FUtility.RepaintGameView(); } _viewRange = FGUI.ViewRangeBar(_viewRangeRect, _viewRange, _sequence.Length); if (_timelineHeaderResizerRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.AddCursorRect(_timelineHeaderResizerRect, MouseCursor.ResizeHorizontal); } switch (Event.current.type) { case EventType.MouseDown: bool leftClick = Event.current.button == 0 && !Event.current.alt; // bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt); if (leftClick) // left button { if (EditorGUIUtility.hotControl == 0 && _timelineHeaderResizerRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.hotControl = timelineHeaderResizerId; Event.current.Use(); } else if (_rect.Contains(Event.current.mousePosition)) { DeselectAll(); Event.current.Use(); } } // else if( middleClick ) // middle button // { // StartDragSelecting( Event.current.mousePosition ); // Event.current.Use(); // } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == timelineHeaderResizerId) { _timelineHeaderWidth = (int)Mathf.Max(MINIMUM_HEADER_WIDTH, _timelineHeaderWidth + Event.current.delta.x); RebuildLayout(_rect); EditorWindow.GetWindow <FSequenceEditorWindow>().Repaint(); Event.current.Use(); } if (_isDragSelecting) { Repaint(); } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == timelineHeaderResizerId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } // if( _isDragSelecting ) // { // StopDragSelecting( Event.current.mousePosition ); // Event.current.Use(); // } break; case EventType.Repaint: Rect dragArea = _timelineHeaderResizerRect; dragArea.xMax -= 10; dragArea.xMin = dragArea.xMax - 16; GUIStyle dragStyle = FUtility.GetFluxSkin().GetStyle("HorizontalPanelSeparatorHandle"); dragStyle.Draw(dragArea, GUIContent.none, 0); // GUI.DrawTexture( dragArea, EditorGUIUtility.whiteTexture ); Handles.color = FGUI.GetLineColor(); // new Color(0.8f, 0.8f, 0.8f, 0.2f); Handles.DrawLine(new Vector3(_viewRect.xMin - 16, _sequenceRect.yMax, 0), new Vector3(_viewRect.xMax - RIGHT_BORDER, _sequenceRect.yMax, 0)); // Handles.color = Color.black; break; case EventType.ScrollWheel: if (_viewRect.Contains(Event.current.mousePosition)) { _scrollPos.y += Event.current.delta.y * SCROLL_WHEEL_SPEED; Event.current.Use(); } break; } #if FLUX_TRIAL GUIStyle watermarkLabel = new GUIStyle(GUI.skin.label); watermarkLabel.fontSize = 24; GUIContent watermark = new GUIContent("..::FLUX TRIAL::.."); Vector2 watermarkSize = watermarkLabel.CalcSize(watermark); Rect watermarkRect = new Rect(_rect.width * 0.5f - watermarkSize.x * 0.5f, _rect.height * 0.5f - watermarkSize.y * 0.5f, watermarkSize.x, watermarkSize.y); GUI.color = new Color(1f, 1f, 1f, 0.4f); GUI.Label(watermarkRect, watermark, watermarkLabel); #endif }
public void OpenSequence(FSequence sequence) { #if FLUX_DEBUG Debug.Log("Opening sequence: " + sequence); #endif if (sequence == null) { Debug.LogError("sequence == null"); if (!object.Equals(sequence, null)) { sequence = (FSequence)EditorUtility.InstanceIDToObject(sequence.GetInstanceID()); } } bool sequenceChanged = _sequence != sequence && (object.Equals(_sequence, null) || object.Equals(sequence, null) || _sequence.GetInstanceID() != sequence.GetInstanceID()); // Debug.Log ("selected sequence! Changed? " + sequenceChanged ); if (sequenceChanged) { if (_sequence != null) { Stop(); } _editorCache.Clear(); _selectedEvents.Clear(); _selectedTracks.Clear(); } else { _editorCache.Refresh(); } if (sequence != null) { // _sequenceInstanceID = sequence.GetInstanceID(); if (_viewRange.Length == 0) { _viewRange = new FrameRange(0, sequence.Length); } if (!EditorApplication.isPlaying) { sequence.Rebuild(); } List <FTimeline> timelines = sequence.GetTimelines(); _timelineEditors.Clear(); for (int i = 0; i < timelines.Count; ++i) { FTimeline timeline = timelines[i]; FTimelineEditor timelineEditor = GetEditor <FTimelineEditor>(timeline); timelineEditor.Init(timeline, this); _timelineEditors.Add(timelineEditor); } if (_viewRange.Length == 0) { _viewRange = new FrameRange(0, sequence.Length); } } else { // _sequenceInstanceID = int.MinValue; } _sequence = sequence; Repaint(); }
public override void OnInspectorGUI() { bool rebuildTrack = false; base.OnInspectorGUI(); serializedObject.Update(); if (_animationClip.objectReferenceValue == null) { EditorGUILayout.HelpBox("There's no Animation Clip", MessageType.Warning); Rect helpBoxRect = GUILayoutUtility.GetLastRect(); float yCenter = helpBoxRect.center.y; helpBoxRect.xMax -= 3; helpBoxRect.xMin = helpBoxRect.xMax - 50; helpBoxRect.yMin = yCenter - 12.5f; helpBoxRect.height = 25f; FAnimationTrack animTrack = (FAnimationTrack)_animEvent.Track; if (animTrack.AnimatorController == null || animTrack.LayerId == -1) { GUI.enabled = false; } if (GUI.Button(helpBoxRect, "Create")) { CreateAnimationClip(_animEvent); } GUI.enabled = true; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_animationClip); Rect animationClipRect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.DragUpdated && animationClipRect.Contains(Event.current.mousePosition)) { int numAnimations = NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate); if (numAnimations > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } else if (Event.current.type == EventType.DragPerform && animationClipRect.Contains(Event.current.mousePosition)) { if (NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate) > 0) { DragAndDrop.AcceptDrag(); AnimationClip clip = GetAnimationClipDragAndDrop(_animEvent.Sequence.FrameRate); if (clip != null) { _animationClip.objectReferenceValue = clip; } } } if (EditorGUI.EndChangeCheck()) { AnimationClip clip = (AnimationClip)_animationClip.objectReferenceValue; if (clip) { if (clip.frameRate != _animEvent.Track.Timeline.Sequence.FrameRate) { Debug.LogError(string.Format("Can't add animation, it has a different frame rate from the sequence ({0} vs {1})", clip.frameRate, _animEvent.Track.Timeline.Sequence.FrameRate)); _animationClip.objectReferenceValue = null; } else { SerializedProperty frameRangeEnd = _frameRange.FindPropertyRelative("_end"); FrameRange maxFrameRange = _animEvent.GetMaxFrameRange(); frameRangeEnd.intValue = Mathf.Min(_animEvent.FrameRange.Start + Mathf.RoundToInt(clip.length * clip.frameRate), maxFrameRange.End); } rebuildTrack = true; } else { CheckDeleteAnimation(_animEvent); } } bool isAnimationEditable = Flux.FUtility.IsAnimationEditable(_animEvent._animationClip); if (isAnimationEditable) { EditorGUILayout.PropertyField(_controlsAnimation); } else { if (_controlsAnimation.boolValue) { _controlsAnimation.boolValue = false; } } if (!_controlsAnimation.boolValue) { if (_animEvent.IsBlending()) { float offset = _startOffset.intValue / _animEvent._animationClip.frameRate; float blendFinish = offset + (_blendLength.intValue / _animEvent._animationClip.frameRate); EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(EditorGUIUtility.labelWidth - 5)); // hack to get around some layout issue with imgui _showBlendAndOffsetContent = EditorGUILayout.Foldout(_showBlendAndOffsetContent, new GUIContent("Offset+Blend")); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(ref offset, ref blendFinish, 0, _animEvent.GetMaxStartOffset() / _animEvent._animationClip.frameRate + _animEvent.LengthTime); if (EditorGUI.EndChangeCheck()) { _startOffset.intValue = Mathf.Clamp(Mathf.RoundToInt(offset * _animEvent.Sequence.FrameRate), 0, _animEvent.GetMaxStartOffset()); _blendLength.intValue = Mathf.Clamp(Mathf.RoundToInt((blendFinish - offset) * _animEvent.Sequence.FrameRate), 0, _animEvent.Length); rebuildTrack = true; } EditorGUILayout.EndHorizontal(); if (_showBlendAndOffsetContent) { EditorGUI.BeginChangeCheck(); ++EditorGUI.indentLevel; if (!isAnimationEditable) { EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset()); } // if( _animEvent.IsBlending() ) { EditorGUILayout.IntSlider(_blendLength, 0, _animEvent.Length); } --EditorGUI.indentLevel; if (EditorGUI.EndChangeCheck()) { rebuildTrack = true; } } } else { EditorGUI.BeginChangeCheck(); EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset()); if (EditorGUI.EndChangeCheck()) { rebuildTrack = true; } } } serializedObject.ApplyModifiedProperties(); if (rebuildTrack) { FAnimationTrackInspector.RebuildStateMachine((FAnimationTrack)_animEvent.Track); } }
// 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); } } }
protected override void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange) { if (_animEvtSO == null) { _animEvtSO = new SerializedObject(AnimEvt); _blendLength = _animEvtSO.FindProperty("_blendLength"); _startOffset = _animEvtSO.FindProperty("_startOffset"); } UpdateEventFromController(); _animEvtSO.Update(); FAnimationTrackEditor animTrackEditor = (FAnimationTrackEditor)TrackEditor; Rect transitionOffsetRect = _eventRect; int startOffsetHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int transitionHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); bool isBlending = AnimEvt.IsBlending(); bool isAnimEditable = Flux.FUtility.IsAnimationEditable(AnimEvt._animationClip); if (isBlending) { transitionOffsetRect.xMin = Rect.xMin + SequenceEditor.GetXForFrame(AnimEvt.Start + AnimEvt._blendLength) - 3; transitionOffsetRect.width = 6; transitionOffsetRect.yMin = transitionOffsetRect.yMax - 8; } switch (Event.current.type) { case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && Event.current.alt && !isAnimEditable) { if (isBlending && transitionOffsetRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.hotControl = transitionHandleId; AnimatorWindowProxy.OpenAnimatorWindowWithAnimatorController((AnimatorController)AnimTrack.AnimatorController); if (Selection.activeObject != _transitionToState) { Selection.activeObject = _transitionToState; } Event.current.Use(); } else if (_eventRect.Contains(Event.current.mousePosition)) { _mouseDown = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - AnimEvt.Start; EditorGUIUtility.hotControl = startOffsetHandleId; Event.current.Use(); } } break; case EventType.Ignore: case EventType.MouseUp: if (EditorGUIUtility.hotControl == transitionHandleId || EditorGUIUtility.hotControl == startOffsetHandleId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == transitionHandleId) { int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length); if (_blendLength.intValue != mouseDragPos) { _blendLength.intValue = mouseDragPos; FPlayAnimationEvent prevAnimEvt = (FPlayAnimationEvent)animTrackEditor.Track.GetEvent(AnimEvt.GetId() - 1); if (_transitionDuration != null) { _transitionDuration.floatValue = (_blendLength.intValue / prevAnimEvt._animationClip.frameRate) / prevAnimEvt._animationClip.length; } Undo.RecordObject(this, "Animation Blending"); } Event.current.Use(); } else if (EditorGUIUtility.hotControl == startOffsetHandleId) { int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length); int delta = _mouseDown - mouseDragPos; _mouseDown = mouseDragPos; _startOffset.intValue = Mathf.Clamp(_startOffset.intValue + delta, 0, AnimEvt._animationClip.isLooping ? AnimEvt.Length : Mathf.RoundToInt(AnimEvt._animationClip.length * AnimEvt._animationClip.frameRate) - AnimEvt.Length); if (_transitionOffset != null) { _transitionOffset.floatValue = (_startOffset.intValue / AnimEvt._animationClip.frameRate) / AnimEvt._animationClip.length; } Undo.RecordObject(this, "Animation Offset"); Event.current.Use(); } break; } _animEvtSO.ApplyModifiedProperties(); if (_transitionSO != null) { _transitionSO.ApplyModifiedProperties(); } switch (Event.current.type) { case EventType.DragUpdated: if (_eventRect.Contains(Event.current.mousePosition)) { int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Evt.Sequence.FrameRate); DragAndDrop.visualMode = numAnimationsDragged > 0 ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; Event.current.Use(); } break; case EventType.DragPerform: if (_eventRect.Contains(Event.current.mousePosition)) { AnimationClip animationClipDragged = FAnimationEventInspector.GetAnimationClipDragAndDrop(Evt.Sequence.FrameRate); if (animationClipDragged) { int animFrameLength = Mathf.RoundToInt(animationClipDragged.length * animationClipDragged.frameRate); FAnimationEventInspector.SetAnimationClip(AnimEvt, animationClipDragged); FrameRange maxRange = AnimEvt.GetMaxFrameRange(); SequenceEditor.MoveEvent(AnimEvt, new FrameRange(AnimEvt.Start, Mathf.Min(AnimEvt.Start + animFrameLength, maxRange.End))); DragAndDrop.AcceptDrag(); Event.current.Use(); } else { Event.current.Use(); } } break; } // FrameRange currentRange = Evt.FrameRange; base.RenderEvent(viewRange, validKeyframeRange); // if( isAnimEditable && currentRange.Length != Evt.FrameRange.Length ) // { // FAnimationEventInspector.ScaleAnimationClip( AnimEvt._animationClip, Evt.FrameRange ); // } if (Event.current.type == EventType.Repaint) { if (isBlending && !isAnimEditable && viewRange.Contains(AnimEvt.Start + AnimEvt._blendLength)) { GUISkin skin = FUtility.GetFluxSkin(); GUIStyle transitionOffsetStyle = skin.GetStyle("BlendOffset"); Texture2D t = FUtility.GetFluxTexture("EventBlend.png"); Rect r = new Rect(_eventRect.xMin, _eventRect.yMin + 1, transitionOffsetRect.center.x - _eventRect.xMin, _eventRect.height - 2); Color guiColor = GUI.color; Color c = new Color(1f, 1f, 1f, 0.3f); c.a *= guiColor.a; GUI.color = c; GUI.DrawTexture(r, t); if (Event.current.alt) { GUI.color = Color.white; } transitionOffsetStyle.Draw(transitionOffsetRect, false, false, false, false); GUI.color = guiColor; // Debug.Log ( transitionOffsetRect ); } // GUI.color = Color.red; if (EditorGUIUtility.hotControl == transitionHandleId) { Rect transitionOffsetTextRect = transitionOffsetRect; transitionOffsetTextRect.y -= 16; transitionOffsetTextRect.height = 20; transitionOffsetTextRect.width += 50; GUI.Label(transitionOffsetTextRect, AnimEvt._blendLength.ToString(), EditorStyles.label); } if (EditorGUIUtility.hotControl == startOffsetHandleId) { Rect startOffsetTextRect = _eventRect; GUI.Label(startOffsetTextRect, AnimEvt._startOffset.ToString(), EditorStyles.label); } } }
public virtual void Render(int id, Rect rect, int headerWidth, FrameRange viewRange, float pixelsPerFrame) { rect.y += _offsetAnim.value.y; _rect = rect; Rect viewRect = rect; viewRect.y += _offsetAnim.value.y; viewRect.xMax = headerWidth; viewRect.xMin = viewRect.xMax - 16; viewRect.height = 16; if (_track.CanTogglePreview()) { if (Event.current.type == EventType.MouseDown) { if (viewRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) // left click? { _track.IsPreviewing = !_track.IsPreviewing; FUtility.RepaintGameView(); Event.current.Use(); } } } } Rect trackHeaderRect = rect; trackHeaderRect.xMax = headerWidth; bool selected = _isSelected; if (selected) { Color c = FGUI.GetSelectionColor(); GUI.color = c; GUI.DrawTexture(trackHeaderRect, EditorGUIUtility.whiteTexture); GUI.color = FGUI.GetTextColor(); // Debug.Log( GUI.color ); } Rect trackLabelRect = trackHeaderRect; trackLabelRect.xMin += 10; GUI.Label(trackLabelRect, new GUIContent(_track.name), FGUI.GetTrackHeaderStyle()); rect.xMin = trackHeaderRect.xMax; FrameRange validKeyframeRange = new FrameRange(0, SequenceEditor.GetSequence().Length); for (int i = 0; i != _eventEditors.Count; ++i) { if (i == 0) { validKeyframeRange.Start = 0; } else { validKeyframeRange.Start = _eventEditors[i - 1]._evt.End; } if (i == _eventEditors.Count - 1) { validKeyframeRange.End = SequenceEditor.GetSequence().Length; } else { validKeyframeRange.End = _eventEditors[i + 1]._evt.Start; } _eventEditors[i].Render(rect, viewRange, pixelsPerFrame, validKeyframeRange); } switch (Event.current.type) { case EventType.ContextClick: if (trackHeaderRect.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Duplicate Track"), false, DuplicateTrack); menu.AddItem(new GUIContent("Delete Track"), false, DeleteTrack); menu.ShowAsContext(); Event.current.Use(); } break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && trackHeaderRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) // selecting { if (Event.current.control) { if (IsSelected()) { SequenceEditor.Deselect(this); } else { SequenceEditor.Select(this); } } else if (Event.current.shift) { SequenceEditor.Select(this); } else { SequenceEditor.SelectExclusive(this); _timelineEditor.StartTrackDrag(this); _offsetAnim.value = _offsetAnim.target = new Vector2(0, rect.yMin) - Event.current.mousePosition; EditorGUIUtility.hotControl = id; } Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == id) { EditorGUIUtility.hotControl = 0; _offsetAnim.value = _offsetAnim.target = Vector2.zero; _timelineEditor.StopTrackDrag(); SequenceEditor.Repaint(); Event.current.Use(); } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == id) { SequenceEditor.Repaint(); Event.current.Use(); } break; } if (_track.CanTogglePreview()) { GUI.color = FGUI.GetTextColor(); if (!_track.IsPreviewing) { Color c = GUI.color; c.a = 0.3f; GUI.color = c; } GUI.DrawTexture(viewRect, _previewIcon); GUI.color = Color.white; } #if UNITY_4_5 if (_offsetAnim.isAnimating) { SequenceEditor.Repaint(); } #endif }
public virtual void OnEventFinishedMoving(FrameRange oldFrameRange) { }
public override void OnInspectorGUI() { // EditorGUILayout.PropertyField( _script ); if (_allEventsSameType) { serializedObject.Update(); EditorGUILayout.PropertyField(_triggerOnSkip, new GUIContent("跳过触发器")); } else { bool triggerOnSkipMatch = true; for (int i = 0; i != targets.Length; ++i) { if (((FEvent)targets[i]).TriggerOnSkip != _evt.TriggerOnSkip) { triggerOnSkipMatch = false; break; } } EditorGUI.BeginChangeCheck(); bool triggerOnSkip = EditorGUILayout.Toggle("跳过触发器", _evt.TriggerOnSkip, triggerOnSkipMatch ? EditorStyles.toggle : "ToggleMixed"); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(targets, " Inspector"); for (int i = 0; i != targets.Length; ++i) { FEvent evt = (FEvent)targets[i]; evt.TriggerOnSkip = triggerOnSkip; } } } // EditorGUILayout.IntField( "Instance ID", _evt.GetInstanceID() ); FrameRange validRange = _evt.Track != null?_evt.Track.GetValidRange(_evt) : new FrameRange(_evt.Start, _evt.End); if (!_isSingleFrame) { float startFrame = _evt.Start; float endFrame = _evt.End; EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("范围"); GUILayout.Label("开始:", EditorStyles.label); GUI.SetNextControlName(FRAMERANGE_START_FIELD_ID); startFrame = EditorGUILayout.IntField(_evt.Start); GUILayout.Label("结束:", EditorStyles.label); endFrame = EditorGUILayout.IntField(_evt.End); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { bool changedStart = GUI.GetNameOfFocusedControl() == FRAMERANGE_START_FIELD_ID; for (int i = 0; i != targets.Length; ++i) { FEvent evt = (FEvent)targets[i]; FrameRange newFrameRange = evt.FrameRange; if (changedStart) { if (startFrame <= newFrameRange.End) { newFrameRange.Start = (int)startFrame; } } else if (endFrame >= newFrameRange.Start) { newFrameRange.End = (int)endFrame; } if (newFrameRange.Length >= evt.GetMinLength() && newFrameRange.Length <= evt.GetMaxLength()) { FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent(evt, newFrameRange); FEventEditor.FinishMovingEventEditors(); // FUtility.Resize( evt, newFrameRange ); } } } if (targets.Length == 1) { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(EditorGUIUtility.labelWidth); float sliderStartFrame = startFrame; float sliderEndFrame = endFrame; EditorGUILayout.MinMaxSlider(ref sliderStartFrame, ref sliderEndFrame, validRange.Start, validRange.End); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { FrameRange newFrameRange = new FrameRange((int)sliderStartFrame, (int)sliderEndFrame); if (newFrameRange.Length < _evt.GetMinLength()) { if (sliderStartFrame != startFrame) // changed start { newFrameRange.Start = newFrameRange.End - _evt.GetMinLength(); } else { newFrameRange.Length = _evt.GetMinLength(); } } // FUtility.Resize( _evt, newFrameRange ); FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent(_evt, newFrameRange); FEventEditor.FinishMovingEventEditors(); } } } else { EditorGUI.BeginChangeCheck(); EditorGUILayout.IntSlider(_singleFrame, validRange.Start + 1, validRange.End, _singleFrameUI); if (EditorGUI.EndChangeCheck()) { _evt.SingleFrame = _singleFrame.intValue; FrameRange newFrameRange = _evt.FrameRange; newFrameRange.Start = _evt.SingleFrame - 1; newFrameRange.End = _evt.SingleFrame; FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent(_evt, newFrameRange); FEventEditor.FinishMovingEventEditors(); } } if (_allEventsSameType) { serializedObject.ApplyModifiedProperties(); base.OnInspectorGUI(); serializedObject.Update(); foreach (var field in _fields) { if (field.AddFindBtn) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(field.Property, field.DisplayName); if (GUILayout.Button("F", GUILayout.Width(30))) { UnityEngine.Object obj = Selection.activeObject; string path = AssetDatabase.GetAssetPath(obj); if (obj != null && string.IsNullOrEmpty(path)) { path = GetSceneNodePath((obj as GameObject).transform); field.Property.stringValue = path; } else if (!string.IsNullOrEmpty(path)) { field.Property.stringValue = path; } } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.PropertyField(field.Property, field.DisplayName); } } serializedObject.ApplyModifiedProperties(); } }
public static FrameRange ViewRangeBar(Rect rect, FrameRange viewRange, int totalFrames) { GUISkin previousGUI = GUI.skin; GUI.skin = null; int leftArrowId = EditorGUIUtility.GetControlID(FocusType.Passive); int rightArrowId = EditorGUIUtility.GetControlID(FocusType.Passive); int leftHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int rightHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int midHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); GUIStyle leftArrowStyle = GUI.skin.GetStyle("horizontalscrollbarleftbutton"); GUIStyle rightArrowStyle = GUI.skin.GetStyle("horizontalscrollbarrightbutton"); GUIStyle timelineScrubberStyle = GUI.skin.GetStyle("HorizontalMinMaxScrollbarThumb"); Rect leftArrowRect = rect; leftArrowRect.width = leftArrowStyle.fixedWidth; Rect rightArrowRect = rect; rightArrowRect.xMin = rightArrowRect.xMax - rightArrowStyle.fixedWidth; Rect scrubberRect = rect; scrubberRect.xMin += leftArrowRect.width; scrubberRect.xMax -= rightArrowRect.width; float scrubberLeftEdge = scrubberRect.xMin; float minWidth = 50; float maxWith = scrubberRect.width - minWidth; scrubberRect.xMin += ((float)viewRange.Start / totalFrames) * maxWith; scrubberRect.width = ((float)viewRange.Length / totalFrames) * maxWith + minWidth; Rect leftHandleRect = scrubberRect; leftHandleRect.width = timelineScrubberStyle.border.left; Rect rightHandRect = scrubberRect; rightHandRect.xMin = rightHandRect.xMax - timelineScrubberStyle.border.right; switch (Event.current.type) { case EventType.MouseDown: if (Event.current.clickCount > 1) { viewRange.Start = 0; viewRange.End = totalFrames; } else if (EditorGUIUtility.hotControl == 0) { Vector3 mousePos = Event.current.mousePosition; if (leftArrowRect.Contains(mousePos)) { EditorGUIUtility.hotControl = leftArrowId; } else if (rightArrowRect.Contains(mousePos)) { EditorGUIUtility.hotControl = rightArrowId; } else if (leftHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = leftHandleId; } else if (rightHandRect.Contains(mousePos)) { EditorGUIUtility.hotControl = rightHandleId; } else if (scrubberRect.Contains(mousePos)) { EditorGUIUtility.hotControl = midHandleId; _offset = Event.current.mousePosition - new Vector2(scrubberRect.xMin, scrubberRect.yMin); } if (EditorGUIUtility.hotControl != 0) { // cachedMousePos = Input.mousePosition; Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == leftArrowId || EditorGUIUtility.hotControl == rightArrowId || EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId || EditorGUIUtility.hotControl == midHandleId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } break; case EventType.MouseDrag: int delta = 0; if (EditorGUIUtility.hotControl == leftHandleId) { delta = Mathf.RoundToInt(((Event.current.mousePosition.x - scrubberLeftEdge) / maxWith) * totalFrames); viewRange.Start = Mathf.Clamp(delta, 0, viewRange.End - 1); GUI.changed = true; Event.current.Use(); } else if (EditorGUIUtility.hotControl == rightHandleId) { delta = Mathf.RoundToInt(((Event.current.mousePosition.x - (scrubberLeftEdge + minWidth)) / maxWith) * totalFrames); viewRange.End = Mathf.Clamp(delta, viewRange.Start + 1, totalFrames); GUI.changed = true; Event.current.Use(); } else if (EditorGUIUtility.hotControl == midHandleId) { // int startX = Mathf.RoundToInt(((cachedMousePos.x-scrubberLeftEdge)/maxWith)*totalFrames); delta = Mathf.RoundToInt(((Event.current.mousePosition.x - _offset.x - scrubberLeftEdge) / maxWith) * totalFrames); int x = delta - viewRange.Start; viewRange.Start = delta; viewRange.End += x; if (viewRange.Start < 0) { int diff = -viewRange.Start; viewRange.Start += diff; viewRange.End += diff; } if (viewRange.End > totalFrames) { int diff = viewRange.End - totalFrames; viewRange.Start -= diff; viewRange.End -= diff; } GUI.changed = true; Event.current.Use(); } break; case EventType.Repaint: GUIStyle bar = GUI.skin.GetStyle("horizontalscrollbar"); bar.Draw(rect, false, false, false, false); leftArrowStyle.Draw(leftArrowRect, true, EditorGUIUtility.hotControl == leftArrowId, false, false); rightArrowStyle.Draw(rightArrowRect, true, EditorGUIUtility.hotControl == rightArrowId, false, false); timelineScrubberStyle.Draw(scrubberRect, false, false, false, false); GUIStyle label = new GUIStyle(EditorStyles.boldLabel); string viewRangeStartStr = viewRange.Start.ToString(); string viewRangeEndStr = viewRange.End.ToString(); string viewRangeLengthStr = viewRange.Length.ToString(); scrubberRect.xMin += 20; scrubberRect.xMax -= 20; Vector2 sizeAllLabels = label.CalcSize(new GUIContent(viewRangeStartStr + viewRangeEndStr + viewRangeLengthStr)); if (scrubberRect.width > sizeAllLabels.x + 40) { label.Draw(scrubberRect, new GUIContent(viewRangeStartStr), 0); label.alignment = TextAnchor.MiddleRight; label.Draw(scrubberRect, new GUIContent(viewRangeEndStr), 0); } label.alignment = TextAnchor.MiddleCenter; label.Draw(scrubberRect, new GUIContent(viewRangeLengthStr), 0); // GUI.HorizontalScrollbar( rect, 0, 100, 0, 100); break; } GUI.skin = previousGUI; return(viewRange); }
public virtual void OnEventMoved(FrameRange oldFrameRange) { AddEventEditorBeingMoved(this, oldFrameRange); }
void OnGUI() { if (curEvt == null) { return; } //if (SkillWindow.Inst == null) //{ // this.Close(); // return; //} mScrollPos = EditorGUILayout.BeginScrollView(mScrollPos); EditorGUILayout.BeginVertical(); drawRoot(curEvt.root.lStyle); GEventStyle style = curEvt.mStyle; GUILayout.Label(style.Attr.name + " id:" + curEvt.id); FrameRange rang = style.range; FrameRange validRange = curEvt.GetMaxFrameRange(); if (!(style is GTimelineStyle)) { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Range "); GUILayout.Label("S:", EditorStyles.label); GUI.SetNextControlName(FRAMERANGE_START_FIELD_ID); rang.Start = EditorGUILayout.IntField(style.Start); GUILayout.Label("E:", EditorStyles.label); rang.End = EditorGUILayout.IntField(style.End); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("t:" + curEvt.LengthTime + "s", GUILayout.Width(30f)); GUILayout.Space(20f);//EditorGUIUtility.labelWidth GUILayout.Label(validRange.Start.ToString(), GUILayout.Width(30f)); float sliderStartFrame = rang.Start; float sliderEndFrame = rang.End; EditorGUILayout.MinMaxSlider(ref sliderStartFrame, ref sliderEndFrame, validRange.Start, validRange.End); GUILayout.Label(validRange.End.ToString(), GUILayout.Width(30f)); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { rang.Start = (int)sliderStartFrame; rang.End = (int)sliderEndFrame; } rang = FrameRange.Resize(rang, validRange); } else { } if (rang != style.range) { rootNode.isChange = true; } style.range = rang; RanderEvent(style); curEvt.OnStyleChange(); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); }
protected override void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange) { int startOffsetHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); switch (Event.current.type) { case EventType.MouseDown: if (Event.current.alt && EditorGUIUtility.hotControl == 0 && _eventRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.hotControl = startOffsetHandleId; _frameMouseDown = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _playAudioEvt.Start; Event.current.Use(); } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == startOffsetHandleId) { int mouseCurrentFrame = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _playAudioEvt.Start, 0, _playAudioEvt.Length); int mouseDelta = _frameMouseDown - mouseCurrentFrame; if (mouseDelta != 0) { _frameMouseDown = mouseCurrentFrame; _startOffset.serializedObject.Update(); _startOffset.intValue = Mathf.Clamp(_startOffset.intValue + mouseDelta, 0, _playAudioEvt.GetMaxStartOffset()); _startOffset.serializedObject.ApplyModifiedProperties(); } Event.current.Use(); } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == startOffsetHandleId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } break; } int frameRangeLength = _playAudioEvt.Length; base.RenderEvent(viewRange, validKeyframeRange); if (frameRangeLength != _playAudioEvt.Length) { _startOffset.serializedObject.Update(); _startOffset.intValue = Mathf.Clamp(_startOffset.intValue, 0, _playAudioEvt.GetMaxStartOffset()); _startOffset.serializedObject.ApplyModifiedProperties(); } if (_currentClip != _playAudioEvt.AudioClip) { _waveformTexture = FUtility.GetAudioClipTexture(_playAudioEvt.AudioClip, _rect.width, 64); _currentClip = _playAudioEvt.AudioClip; } if (Event.current.type == EventType.Repaint && _waveformTexture != null) { float border = 2; Rect waveformRect = _eventRect; waveformRect.xMin += border; waveformRect.xMax -= border; FrameRange visibleEvtRange = _playAudioEvt.FrameRange; float startOffset = _playAudioEvt.StartOffset; if (viewRange.Start > visibleEvtRange.Start) { startOffset += viewRange.Start - visibleEvtRange.Start; visibleEvtRange.Start = viewRange.Start; } if (viewRange.End < visibleEvtRange.End) { visibleEvtRange.End = viewRange.End; } float uvLength = (visibleEvtRange.Length * _playAudioEvt.Sequence.InverseFrameRate) / _playAudioEvt.AudioClip.length; Rect waveformUVRect = new Rect((startOffset / _playAudioEvt.FrameRange.Length) * ((_playAudioEvt.FrameRange.Length * _playAudioEvt.Sequence.InverseFrameRate) / _playAudioEvt.AudioClip.length), 0, uvLength, 1f); float uvPerPixel = uvLength / waveformRect.width; float borderUVs = border * uvPerPixel; waveformUVRect.xMin += borderUVs; waveformUVRect.xMax -= borderUVs; if (_currentClip.channels == 1) { waveformUVRect.yMin = 0.3f; waveformUVRect.yMax = 0.7f; } GUI.DrawTextureWithTexCoords(waveformRect, _waveformTexture, waveformUVRect); } }
public override void Render(Rect rect, float headerWidth) { Rect = rect; _headerWidth = headerWidth; Rect headerRect = rect; headerRect.width = headerWidth; Rect viewRect = rect; viewRect.xMax = rect.xMin + headerWidth; viewRect.xMin = viewRect.xMax - 16; viewRect.height = 16; if (Track.CanTogglePreview) { if (Event.current.type == EventType.MouseDown) { if (viewRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) // left click? { if (Event.current.shift) // turn all? { SequenceEditor.TurnOnAllPreviews(!Track.CanPreview); } else { OnTogglePreview(!Track.CanPreview); } FUtility.RepaintGameView(); Event.current.Use(); } } } } Rect trackHeaderRect = rect; trackHeaderRect.xMax = viewRect.xMax; //headerWidth; Color guiColor = GUI.color; bool selected = _isSelected; if (selected) { Color c = FGUI.GetSelectionColor(); c.a = GUI.color.a; GUI.color = c; GUI.DrawTexture(trackHeaderRect, EditorGUIUtility.whiteTexture); GUI.color = guiColor; } if (!Track.enabled) { Color c = guiColor; c.a = 0.5f; GUI.color = c; } Rect trackLabelRect = trackHeaderRect; trackLabelRect.xMin += 8; GUI.Label(trackLabelRect, new GUIContent(Track.name), FGUI.GetTrackHeaderStyle()); rect.xMin = trackHeaderRect.xMax; if (rect.Contains(Event.current.mousePosition)) { SequenceEditor.SetMouseHover(Event.current.mousePosition.x - rect.xMin, this); } FrameRange validKeyframeRange = new FrameRange(0, SequenceEditor.Sequence.Length); for (int i = 0; i != _eventEditors.Count; ++i) { if (i == 0) { validKeyframeRange.Start = 0; } else { validKeyframeRange.Start = _eventEditors[i - 1].Evt.End; } if (i == _eventEditors.Count - 1) { validKeyframeRange.End = SequenceEditor.Sequence.Length; } else { validKeyframeRange.End = _eventEditors[i + 1].Evt.Start; } _eventEditors[i].Render(rect, SequenceEditor.ViewRange, SequenceEditor.PixelsPerFrame, validKeyframeRange); } switch (Event.current.type) { case EventType.ContextClick: if (trackHeaderRect.Contains(Event.current.mousePosition)) { OnHeaderContextClick(); } else if (Rect.Contains(Event.current.mousePosition)) { OnBodyContextClick(); } break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && trackHeaderRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) // selecting { if (Event.current.control) { if (IsSelected) { SequenceEditor.Deselect(this); } else { SequenceEditor.Select(this); } } else if (Event.current.shift) { SequenceEditor.Select(this); } else { SequenceEditor.SelectExclusive(this); } Event.current.Use(); } } break; case EventType.MouseUp: // if( EditorGUIUtility.hotControl == GuiId ) // { // EditorGUIUtility.hotControl = 0; // _offsetAnim.value = _offsetAnim.target = Vector2.zero; // //// if( TimelineEditor ) TimelineEditor.StopTrackDrag(); // // SequenceEditor.Repaint(); // Event.current.Use(); // } break; case EventType.MouseDrag: // if( EditorGUIUtility.hotControl == GuiId ) // { // SequenceEditor.Repaint(); // Event.current.Use(); // } break; } if (Track.CanTogglePreview) { GUI.color = GetPreviewIconColor(); //FGUI.GetTextColor(); if (!Track.CanPreview) { Color c = GUI.color; c.a = 0.3f; GUI.color = c; } GUI.DrawTexture(viewRect, _previewIcon); GUI.color = Color.white; } Handles.color = FGUI.GetLineColor(); Handles.DrawLine(Rect.min, Rect.min + new Vector2(Rect.width, 0)); Handles.DrawLine(Rect.max, Rect.max - new Vector2(Rect.width, 0)); GUI.color = guiColor; }
private Rect GetDragSelectionRect(Vector2 rawStartPos, Vector2 rawEndPos, out FrameRange selectedRange, out bool isSelectingTimelines) { int startFrame = GetFrameForX(rawStartPos.x); int endFrame = GetFrameForX(rawEndPos.x); if (startFrame > endFrame) { int temp = startFrame; startFrame = endFrame; endFrame = temp; } selectedRange = new FrameRange(startFrame, endFrame); Rect rect = new Rect(); Vector2 startPos = new Vector2(GetXForFrame(startFrame), rawStartPos.y); Vector2 endPos = new Vector2(GetXForFrame(endFrame), rawEndPos.y); bool isStartOnHeader; bool isEndOnHeader; FTimelineEditor startTimeline = GetTimeline(startPos, out isStartOnHeader); isSelectingTimelines = isStartOnHeader; if (startTimeline != null) { FTrackEditor startTrack = GetTrack(startPos); FTrackEditor endTrack; FTimelineEditor endTimeline = GetTimeline(endPos, out isEndOnHeader); if (endTimeline == null) { endTimeline = startTimeline; isEndOnHeader = isStartOnHeader; endTrack = startTrack; } else { endTrack = GetTrack(endPos); } float xStart = Mathf.Min(startPos.x, endPos.x); float width = Mathf.Abs(startPos.x - endPos.x); float yStart; float height; if (startPos.y <= endPos.y) { yStart = isStartOnHeader ? startTimeline.GetRect().yMin : startTrack.GetRect().yMin; height = (isStartOnHeader ? endTimeline.GetRect().yMax : (isEndOnHeader ? endTimeline.GetRect().yMin + FTimelineEditor.HEADER_HEIGHT : endTrack.GetRect().yMax)) - yStart; // yStart = isStartOnHeader ? startTimeline.GetRect().yMin : startTrack.GetRect().yMin; // height = (isEndOnHeader ? endTimeline._trackEditors[endTimeline._trackEditors.Count-1].GetRect().yMax : endTrack.GetRect().yMax) - yStart; } else { yStart = isStartOnHeader || isEndOnHeader?endTimeline.GetRect().yMin : endTrack.GetRect().yMin; height = (isStartOnHeader ? startTimeline.GetRect().yMax : startTrack.GetRect().yMax) - yStart; // yStart = isEndOnHeader ? endTimeline.GetRect().yMin : endTrack.GetRect().yMin; // height = Mathf.Max( (isStartOnHeader ? startTimeline._trackEditors[startTimeline._trackEditors.Count-1].GetRect().yMax : startTrack.GetRect().yMax), // (isEndOnHeader ? endTimeline._trackEditors[endTimeline._trackEditors.Count-1].GetRect().yMax : endTrack.GetRect().yMax) ) - yStart; } rect.x = xStart; rect.y = yStart; rect.width = width; rect.height = height; } return(rect); }
protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange) { bool leftHandleVisible = viewRange.Contains(Evt.Start); bool rightHandleVisible = viewRange.Contains(Evt.End); Rect leftHandleRect = _eventRect; leftHandleRect.width = 4; Rect rightHandleRect = _eventRect; rightHandleRect.xMin = rightHandleRect.xMax - 4; if (leftHandleVisible && IsSelected) { EditorGUIUtility.AddCursorRect(leftHandleRect, MouseCursor.ResizeHorizontal, _leftHandleGuiId); } if (rightHandleVisible && IsSelected) { EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, _rightHandleGuiId); } switch (Event.current.type) { case EventType.Repaint: if (!viewRange.Overlaps(Evt.FrameRange)) { break; } GUIStyle evtStyle = GetEventStyle(); GUI.backgroundColor = GetColor(); evtStyle.Draw(_eventRect, _isSelected, _isSelected, false, false); string text = Evt.Text; if (text != null) { var style = GetTextStyle(); //style.alignment = TextAnchor.MiddleCenter; GUI.Label(_eventRect, text, style); } /* * var leftRect = _eventRect; * leftRect.xMax = leftRect.xMin + 16; * GUI.Label(leftRect, Evt.Start.ToString(), GetTextStyle()); * var rightRect = _eventRect; * rightRect.xMin = rightRect.xMax - 16; * GUI.Label(rightRect, Evt.End.ToString(), GetTextStyle()); */ break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift) { Vector2 mousePos = Event.current.mousePosition; if (Event.current.button == 0) // left click? { if (rightHandleVisible && rightHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = _rightHandleGuiId; // keyframeOnSelect = evt.Start; Event.current.Use(); } else if (leftHandleVisible && leftHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = _leftHandleGuiId; // keyframeOnSelect = evt.End; Event.current.Use(); } else if (_eventRect.Contains(mousePos)) { EditorGUIUtility.hotControl = GuiId; _mouseOffsetFrames = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start; if (IsSelected) { if (Event.current.control) { SequenceEditor.Deselect(this); } } else { if (Event.current.shift) { SequenceEditor.Select(this); } else if (!Event.current.control) { SequenceEditor.SelectExclusive(this); } } Event.current.Use(); } } else if (Event.current.button == 1 && _eventRect.Contains(Event.current.mousePosition)) // right click? { CreateEventContextMenu().ShowAsContext(); Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == GuiId || EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); SequenceEditor.Repaint(); FinishMovingEventEditors(); } } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == GuiId) { int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames; int delta = t - Evt.Start; SequenceEditor.MoveEvents(delta); Event.current.Use(); } else if (EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId) { int leftLimit = 0; int rightLimit = 0; bool draggingStart = EditorGUIUtility.hotControl == _leftHandleGuiId; if (draggingStart) { leftLimit = validKeyframeRange.Start; rightLimit = Evt.End - 1; } else { leftLimit = Evt.Start + 1; rightLimit = validKeyframeRange.End; } int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); t = Mathf.Clamp(t, leftLimit, rightLimit); int delta = t - (draggingStart ? Evt.Start : Evt.End); if (draggingStart) { int newLength = Evt.Length - delta; if (newLength < Evt.GetMinLength()) { delta += newLength - Evt.GetMinLength(); } if (newLength > Evt.GetMaxLength()) { delta += newLength - Evt.GetMaxLength(); } } else { int newLength = Evt.Length + delta; if (newLength < Evt.GetMinLength()) { delta -= newLength - Evt.GetMinLength(); } if (newLength > Evt.GetMaxLength()) { delta -= newLength - Evt.GetMaxLength(); } } if (delta != 0) { if (draggingStart) { SequenceEditor.ResizeEventsLeft(delta); } else { SequenceEditor.ResizeEventsRight(delta); } } Event.current.Use(); } } break; case EventType.Ignore: if (EditorGUIUtility.hotControl == GuiId || EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId) { EditorGUIUtility.hotControl = 0; SequenceEditor.Repaint(); FinishMovingEventEditors(); } break; } }
public override void OnInspectorGUI() { float startFrame = _evt.Start; float endFrame = _evt.End; FrameRange validRange = _evt.Track != null?_evt.Track.GetValidRange(_evt) : new FrameRange(_evt.Start, _evt.End); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Range"); GUILayout.Label("S:", EditorStyles.label); GUI.SetNextControlName(FRAMERANGE_START_FIELD_ID); startFrame = EditorGUILayout.IntField(_evt.Start); GUILayout.Label("E:", EditorStyles.label); endFrame = EditorGUILayout.IntField(_evt.End); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { bool changedStart = GUI.GetNameOfFocusedControl() == FRAMERANGE_START_FIELD_ID; for (int i = 0; i != targets.Length; ++i) { FEvent evt = (FEvent)targets[i]; FrameRange newFrameRange = evt.FrameRange; if (changedStart) { if (startFrame <= newFrameRange.End) { newFrameRange.Start = (int)startFrame; } } else if (endFrame >= newFrameRange.Start) { newFrameRange.End = (int)endFrame; } if (newFrameRange.Length >= evt.GetMinLength() && newFrameRange.Length <= evt.GetMaxLength()) { FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent(evt, newFrameRange); FEventEditor.FinishMovingEventEditors(); } } } if (targets.Length == 1) { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(EditorGUIUtility.labelWidth); float sliderStartFrame = startFrame; float sliderEndFrame = endFrame; EditorGUILayout.MinMaxSlider(ref sliderStartFrame, ref sliderEndFrame, validRange.Start, validRange.End); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { FrameRange newFrameRange = new FrameRange((int)sliderStartFrame, (int)sliderEndFrame); if (newFrameRange.Length < _evt.GetMinLength()) { if (sliderStartFrame != startFrame) // changed start { newFrameRange.Start = newFrameRange.End - _evt.GetMinLength(); } else { newFrameRange.Length = _evt.GetMinLength(); } } FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent(_evt, newFrameRange); FEventEditor.FinishMovingEventEditors(); } } if (_allEventsSameType) { serializedObject.ApplyModifiedProperties(); base.OnInspectorGUI(); } }
public static int TimeScrubber(Rect rect, int t, int frameRate, FrameRange range) { // Rect actualRect = rect; // actualRect.xMax -= 20; // buffer on the right Rect clickRect = rect; clickRect.yMin = clickRect.yMax - TIMELINE_SCRUBBER_HEIGHT; int length = range.Length; int controlId = EditorGUIUtility.GetControlID(FocusType.Passive); switch (Event.current.type) { case EventType.Repaint: int frames = range.Start; float width = rect.width; int maxFramesBetweenSteps = Mathf.Max(1, Mathf.FloorToInt(width / MIN_PIXELS_BETWEEN_FRAMES)); int numFramesPerStep = Mathf.Max(1, length / maxFramesBetweenSteps); // multiple of 60 fps? if (numFramesPerStep < 30) { if (numFramesPerStep <= 12) { if (numFramesPerStep != 5) { if (12 % numFramesPerStep != 0) { numFramesPerStep = 12; } } } else { numFramesPerStep = 30; } } else if (numFramesPerStep < 60) { numFramesPerStep = 60; } else { int multiplesOf60 = numFramesPerStep / 60; numFramesPerStep = (multiplesOf60 + 1) * 60; } int numFramesIter = numFramesPerStep < 30 ? 1 : numFramesPerStep / 10; Vector3 pt = new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0); Rect backgroundRect = clickRect; backgroundRect.xMin = 0; backgroundRect.xMax += FSequenceEditor.RIGHT_BORDER; // GUI.color = new Color( 0.15f, 0.15f, 0.15f, 1f );//FGUI.GetTimelineColor(); // GUI.DrawTexture( backgroundRect, EditorGUIUtility.whiteTexture ); // GUI.color = Color.white; GUI.color = GetTextColor(); // a little darker than it is originally to stand out GUI.Label(backgroundRect, GUIContent.none, FGUI.GetTimeScrubberStyle()); Handles.color = GetLineColor(); // int framesBetweenSteps = maxFramesBetweenSteps / (maxFramesBetweenSteps * 10 / MIN_PIXELS_BETWEEN_FRAMES); // float pixelsBetweenSteps = minPixelsBetweenSteps / framesBetweenSteps; // // Debug.Log ( maxFramesBetweenSteps + " " + minPixelsBetweenSteps + " vs " + framesBetweenSteps + " " + pixelsBetweenSteps ); GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel); labelStyle.normal.textColor = Color.white; labelStyle.alignment = TextAnchor.UpperCenter; GUI.contentColor = FGUI.GetLineColor(); frames = (frames / numFramesIter) * numFramesIter; while (frames <= range.End) { pt.x = rect.x + (width * ((float)(frames - range.Start) / length)); if (pt.x >= rect.x) { if (frames % numFramesPerStep == 0) { Handles.DrawLine(pt, pt - new Vector3(0, rect.height - TIMELINE_SCRUBBER_TEXT_HEIGHT, 0)); GUI.Label(new Rect(pt.x - 30, pt.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(frames, frameRate), labelStyle); } else { Vector3 smallTickPt = pt; smallTickPt.y -= TIMELINE_SCRUBBER_TICK_HEIGHT; Handles.DrawLine(smallTickPt, smallTickPt - new Vector3(0, TIMELINE_SCRUBBER_TICK_HEIGHT, 0)); } } frames += numFramesIter; } if (t >= 0 && range.Contains(t)) { Vector3 tStart = new Vector3(rect.x + (width * ((float)(t - range.Start) / length)), rect.yMin, 0); Vector3 tEnd = tStart; tEnd.y = rect.yMax - TIMELINE_SCRUBBER_TEXT_HEIGHT; Handles.color = Color.red; Handles.DrawLine(tStart, tEnd); GUI.contentColor = Color.red; GUI.Label(new Rect(tEnd.x - 30, tEnd.y, 60, TIMELINE_SCRUBBER_TEXT_HEIGHT), FUtility.GetTime(t, frameRate), labelStyle); GUI.contentColor = FGUI.GetTextColor(); } GUI.color = Color.white; GUI.contentColor = Color.white; Handles.color = GetLineColor(); Handles.DrawLine(new Vector3(rect.x, rect.yMin, 0), new Vector3(rect.x, rect.yMax - TIMELINE_SCRUBBER_HEIGHT, 0)); break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && clickRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.hotControl = controlId; } goto case EventType.MouseDrag; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == controlId) { Rect touchRect = rect; touchRect.yMin = touchRect.yMax - TIMELINE_SCRUBBER_HEIGHT; // if( touchRect.Contains( Event.current.mousePosition ) ) { // Debug.Log( (Event.current.mousePosition.x - touchRect.xMin / t = Mathf.Clamp(range.Start + Mathf.RoundToInt(((Event.current.mousePosition.x - touchRect.xMin) / touchRect.width) * range.Length), range.Start, range.End); Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == controlId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } break; } rect.height = TIMELINE_SCRUBBER_HEIGHT; return(t); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); if (_animationClip.objectReferenceValue == null) { EditorGUILayout.HelpBox("There's no Animation Clip", MessageType.Warning); Rect helpBoxRect = GUILayoutUtility.GetLastRect(); float yCenter = helpBoxRect.center.y; helpBoxRect.xMax -= 3; helpBoxRect.xMin = helpBoxRect.xMax - 50; helpBoxRect.yMin = yCenter - 12.5f; helpBoxRect.height = 25f; if (GUI.Button(helpBoxRect, "Create")) { CreateAnimationClip(_animEvent); } } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_animationClip); Rect animationClipRect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.DragUpdated && animationClipRect.Contains(Event.current.mousePosition)) { int numAnimations = NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate); if (numAnimations > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } else if (Event.current.type == EventType.DragPerform && animationClipRect.Contains(Event.current.mousePosition)) { if (NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate) > 0) { DragAndDrop.AcceptDrag(); AnimationClip clip = GetAnimationClipDragAndDrop(_animEvent.Sequence.FrameRate); if (clip != null) { _animationClip.objectReferenceValue = clip; } } } if (EditorGUI.EndChangeCheck()) { AnimationClip clip = (AnimationClip)_animationClip.objectReferenceValue; if (clip) { if (clip.frameRate != _animEvent.GetTrack().GetTimeline().Sequence.FrameRate) { Debug.LogError(string.Format("Can't add animation, it has a different frame rate from the sequence ({0} vs {1})", clip.frameRate, _animEvent.GetTrack().GetTimeline().Sequence.FrameRate)); _animationClip.objectReferenceValue = null; } else { SerializedProperty frameRangeEnd = _frameRange.FindPropertyRelative("_end"); FrameRange maxFrameRange = _animEvent.GetMaxFrameRange(); frameRangeEnd.intValue = Mathf.Min(_animEvent.FrameRange.Start + Mathf.RoundToInt(clip.length * clip.frameRate), maxFrameRange.End); } } } if (!_animEvent.IsAnimationEditable()) { EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset()); } serializedObject.ApplyModifiedProperties(); }
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); } } }