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 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 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 override void OnInspectorGUI() { // EditorGUILayout.PropertyField( _script ); if (_allEventsSameType) { serializedObject.Update(); EditorGUILayout.PropertyField(_triggerOnSkip); } 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("Trigger On Skip", _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() ); float startFrame = _evt.Start; float endFrame = _evt.End; FrameRange validRange = _evt.GetTrack().GetValidRange(_evt); 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()) { 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); } } if (_allEventsSameType) { serializedObject.ApplyModifiedProperties(); base.OnInspectorGUI(); } }
protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange) { int leftHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int evtHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int rightHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); 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, leftHandleId); } if (rightHandleVisible && IsSelected()) { EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, rightHandleId); } switch (Event.current.type) { case EventType.Repaint: if (!viewRange.Overlaps(_evt.FrameRange)) { break; } GUISkin skin = FUtility.GetFluxSkin(); GUIStyle eventStyle = skin.GetStyle("Event"); GUI.color = GetColor(); eventStyle.Draw(_eventRect, _isSelected, _isSelected, false, false); GUI.color = Color.white; break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && IsSelected() && !Event.current.control && !Event.current.shift) { Vector2 mousePos = Event.current.mousePosition; if (rightHandleVisible && rightHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = rightHandleId; // keyframeOnSelect = evt.Start; Event.current.Use(); } else if (leftHandleVisible && leftHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = leftHandleId; // keyframeOnSelect = evt.End; Event.current.Use(); } else if (_eventRect.Contains(mousePos)) { EditorGUIUtility.hotControl = evtHandleId; _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(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == evtHandleId || EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); SequenceEditor.Repaint(); } } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == evtHandleId) { int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames; int delta = t - _evt.Start; SequenceEditor.MoveEvents(delta); Event.current.Use(); } else if (EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId) { int leftLimit = 0; int rightLimit = 0; bool draggingStart = EditorGUIUtility.hotControl == leftHandleId; 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; } }