private void DestroyElements(List <ISelectableElement> elements) { Undo.IncrementCurrentGroup(); Undo.RecordObject(this, "Selected Elements"); for (int i = elements.Count - 1; i >= 0; --i) { if (elements[i] is FEvent) { FEvent evt = (FEvent)elements[i]; Undo.RecordObject(evt.GetTrack(), string.Empty); Undo.RecordObject(evt, string.Empty); evt.GetTrack().Remove(evt); Undo.DestroyObjectImmediate(evt.gameObject); } else if (elements[i] is FTrack) { FTrack track = (FTrack)elements[i]; Undo.RecordObject(track.GetTimeline(), string.Empty); Undo.RecordObject(track, string.Empty); track.GetTimeline().RemoveTrack(track); Undo.DestroyObjectImmediate(track.gameObject); } } Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); Refresh(); }
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() { // 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(); } }