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; } }
private void SingleFrameRender(FrameRange viewRange, FrameRange validKeyframeRange) { Rect rect = _eventRect; rect.width = 15; rect.x = SequenceEditor.PixelsPerFrame * Evt.Start; FrameRange range = Evt.FrameRange; range.Start = SequenceEditor.GetFrameForX(rect.x); range.End = range.Start + 1 + _mouseOffsetFrames + SequenceEditor.GetFrameForX(rect.width); Evt.FrameRange = range; switch (Event.current.type) { case EventType.Repaint: { if (!viewRange.Overlaps(Evt.FrameRange)) { break; } _mouseOffsetFrames = 0; GUIStyle evtStyle = _singleFrameStyle; GUI.backgroundColor = Color.white; Rect renderRect = rect; renderRect.x -= 2.5f; evtStyle.Draw(renderRect, _isSelected, _isSelected, false, false); string text = Evt.Text; if (text != null) { GUIStyle style = GetTextStyle(); Vector2 size = style.CalcSize(new GUIContent(text)); rect.size = size; GUI.Label(rect, text, 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) { if (rect.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 && rect.Contains(Event.current.mousePosition)) // right click? { CreateEventContextMenu().ShowAsContext(); Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == GuiId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); SequenceEditor.Repaint(); FinishMovingEventEditors(); } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == GuiId) { int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames; int delta = t - Evt.Start; if (t < viewRange.Start) { t = viewRange.Start; } else if (t > viewRange.End - 1) { t = viewRange.End - 1; } Evt.SingleFrame = t + 1; SequenceEditor.MoveEvents(delta); Event.current.Use(); } break; case EventType.Ignore: if (EditorGUIUtility.hotControl == GuiId) { EditorGUIUtility.hotControl = 0; SequenceEditor.Repaint(); FinishMovingEventEditors(); } break; } }