public void EventLineContextMenuDelete(object obj) { EventLineContextMenuObject eventObj = (EventLineContextMenuObject)obj; AnimationClip clip = eventObj.m_Clip; if (clip == null) { return; } int clickedIndex = eventObj.m_Index; // If a selection already exists, delete selection instead of clicked index if (Array.Exists(eventObj.m_Selected, selected => selected)) { DeleteEvents(clip, eventObj.m_Selected); } // Else, only delete the clicked animation event else if (clickedIndex >= 0) { bool[] deleteIndices = new bool[eventObj.m_Selected.Length]; deleteIndices[clickedIndex] = true; DeleteEvents(clip, deleteIndices); } }
public void EventLineContextMenuEdit(object obj) { EventLineContextMenuObject obj2 = (EventLineContextMenuObject)obj; AnimationEventPopup.Edit(obj2.m_Animated, obj2.m_Clip, obj2.m_Index, this.m_Owner); this.Select(obj2.m_Clip, obj2.m_Index); }
public void EventLineContextMenuEdit(object obj) { EventLineContextMenuObject obj2 = (EventLineContextMenuObject)obj; AnimationWindowEvent evt = AnimationWindowEvent.Edit(obj2.m_Animated, obj2.m_Clip, obj2.m_Index); this.Select(evt); }
public void EventLineContextMenuAdd(object obj) { EventLineContextMenuObject obj2 = (EventLineContextMenuObject)obj; AnimationWindowEvent evt = AnimationWindowEvent.CreateAndEdit(obj2.m_Animated, obj2.m_Clip, obj2.m_Time); this.Select(evt); }
void CreateContextMenu(GameObject animatedGo, AnimationClip clip, float time, int eventIndex, bool[] selectedEvents) { GenericMenu menu = new GenericMenu(); var contextData = new EventLineContextMenuObject(animatedGo, clip, time, eventIndex, selectedEvents); var selectedCount = selectedEvents.Count(selected => selected); menu.AddItem(Styles.textAddEvent, false, EventLineContextMenuAdd, contextData); if (selectedCount > 0 || eventIndex != -1) { menu.AddItem(selectedCount > 1 ? Styles.textDeleteEvents : Styles.textDeleteEvent, false, EventLineContextMenuDelete, contextData); menu.AddItem(Styles.textCopyEvents, false, EventLineContextMenuCopy, contextData); } else { menu.AddDisabledItem(Styles.textDeleteEvents); menu.AddDisabledItem(Styles.textCopyEvents); } if (AnimationWindowEventsClipboard.CanPaste()) { menu.AddItem(Styles.textPasteEvents, false, EventLineContextMenuPaste, contextData); } else { menu.AddDisabledItem(Styles.textPasteEvents); } menu.ShowAsContext(); }
public void EventLineContextMenuAdd(object obj) { EventLineContextMenuObject obj2 = (EventLineContextMenuObject)obj; int index = AnimationEventPopup.Create(obj2.m_Animated, obj2.m_Clip, obj2.m_Time, this.m_Owner); this.Select(obj2.m_Clip, index); this.m_EventsSelected = new bool[AnimationUtility.GetAnimationEvents(obj2.m_Clip).Length]; this.m_EventsSelected[index] = true; }
public void EventLineContextMenuEdit(object obj) { EventLineContextMenuObject eventObj = (EventLineContextMenuObject)obj; if (Array.Exists(eventObj.m_Selected, selected => selected)) { EditEvents(eventObj.m_Animated, eventObj.m_Clip, eventObj.m_Selected); } else if (eventObj.m_Index >= 0) { EditEvent(eventObj.m_Animated, eventObj.m_Clip, eventObj.m_Index); } }
public void EventLineContextMenuDelete(object obj) { EventLineContextMenuObject obj2 = (EventLineContextMenuObject)obj; AnimationClip clip = obj2.m_Clip; if (clip != null) { int index = obj2.m_Index; if (this.m_EventsSelected[index]) { this.DeleteEvents(clip, this.m_EventsSelected); } else { bool[] deleteIndices = new bool[this.m_EventsSelected.Length]; deleteIndices[index] = true; this.DeleteEvents(clip, deleteIndices); } } }
public void EventLineContextMenuAdd(object obj) { EventLineContextMenuObject eventObj = (EventLineContextMenuObject)obj; AddEvent(eventObj.m_Time, eventObj.m_Animated, eventObj.m_Clip); }
public void EventLineGUI(Rect rect, AnimationWindowState state) { // We only display and manipulate animation events from the main // game object in selection. If we ever want to update to handle // a multiple selection, a single timeline might not be sufficient... AnimationClip clip = state.activeAnimationClip; GameObject animated = state.activeRootGameObject; GUI.BeginGroup(rect); Color backupCol = GUI.color; Rect eventLineRect = new Rect(0, 0, rect.width, rect.height); float mousePosTime = Mathf.Max(Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate, 0.0f); // Draw events if (clip != null) { AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip); Texture eventMarker = EditorGUIUtility.IconContent("Animation.EventMarker").image; // Calculate rects Rect[] hitRects = new Rect[events.Length]; Rect[] drawRects = new Rect[events.Length]; int shared = 1; int sharedLeft = 0; for (int i = 0; i < events.Length; i++) { AnimationEvent evt = events[i]; if (sharedLeft == 0) { shared = 1; while (i + shared < events.Length && events[i + shared].time == evt.time) { shared++; } sharedLeft = shared; } sharedLeft--; // Important to take floor of positions of GUI stuff to get pixel correct alignment of // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time. float keypos = Mathf.Floor(state.FrameToPixel(evt.time * clip.frameRate, rect)); int sharedOffset = 0; if (shared > 1) { float spread = Mathf.Min((shared - 1) * (eventMarker.width - 1), (int)(state.FrameDeltaToPixel(rect) - eventMarker.width * 2)); sharedOffset = Mathf.FloorToInt(Mathf.Max(0, spread - (eventMarker.width - 1) * (sharedLeft))); } Rect r = new Rect( keypos + sharedOffset - eventMarker.width / 2, (rect.height - 10) * (float)(sharedLeft - shared + 1) / Mathf.Max(1, shared - 1), eventMarker.width, eventMarker.height); hitRects[i] = r; drawRects[i] = r; } // Store tooptip info if (m_DirtyTooltip) { if (m_HoverEvent >= 0 && m_HoverEvent < hitRects.Length) { m_InstantTooltipText = AnimationWindowEventInspector.FormatEvent(animated, events[m_HoverEvent]); m_InstantTooltipPoint = new Vector2(hitRects[m_HoverEvent].xMin + (int)(hitRects[m_HoverEvent].width / 2) + rect.x - 30, rect.yMax); } m_DirtyTooltip = false; } bool[] selectedEvents = new bool[events.Length]; Object[] selectedObjects = Selection.objects; foreach (Object selectedObject in selectedObjects) { AnimationWindowEvent awe = selectedObject as AnimationWindowEvent; if (awe != null) { if (awe.eventIndex >= 0 && awe.eventIndex < selectedEvents.Length) { selectedEvents[awe.eventIndex] = true; } } } Vector2 offset = Vector2.zero; int clickedIndex; float startSelection, endSelection; // TODO: GUIStyle.none has hopping margins that need to be fixed HighLevelEvent hEvent = EditorGUIExt.MultiSelection( rect, drawRects, new GUIContent(eventMarker), hitRects, ref selectedEvents, null, out clickedIndex, out offset, out startSelection, out endSelection, GUIStyle.none ); if (hEvent != HighLevelEvent.None) { switch (hEvent) { case HighLevelEvent.BeginDrag: m_EventsAtMouseDown = events; m_EventTimes = new float[events.Length]; for (int i = 0; i < events.Length; i++) { m_EventTimes[i] = events[i].time; } break; case HighLevelEvent.SelectionChanged: state.ClearKeySelections(); EditEvents(animated, clip, selectedEvents); break; case HighLevelEvent.Delete: DeleteEvents(clip, selectedEvents); break; case HighLevelEvent.DoubleClick: if (clickedIndex != -1) { EditEvents(animated, clip, selectedEvents); } else { EventLineContextMenuAdd(new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents)); } break; case HighLevelEvent.Drag: for (int i = events.Length - 1; i >= 0; i--) { if (selectedEvents[i]) { AnimationEvent evt = m_EventsAtMouseDown[i]; evt.time = m_EventTimes[i] + offset.x * state.PixelDeltaToTime(rect); evt.time = Mathf.Max(0.0F, evt.time); evt.time = Mathf.RoundToInt(evt.time * clip.frameRate) / clip.frameRate; } } int[] order = new int[selectedEvents.Length]; for (int i = 0; i < order.Length; i++) { order[i] = i; } System.Array.Sort(m_EventsAtMouseDown, order, new EventComparer()); bool[] selectedOld = (bool[])selectedEvents.Clone(); float[] timesOld = (float[])m_EventTimes.Clone(); for (int i = 0; i < order.Length; i++) { selectedEvents[i] = selectedOld[order[i]]; m_EventTimes[i] = timesOld[order[i]]; } // Update selection to reflect new order. EditEvents(animated, clip, selectedEvents); Undo.RegisterCompleteObjectUndo(clip, "Move Event"); AnimationUtility.SetAnimationEvents(clip, m_EventsAtMouseDown); m_DirtyTooltip = true; break; case HighLevelEvent.ContextClick: GenericMenu menu = new GenericMenu(); var contextData = new EventLineContextMenuObject(animated, clip, events[clickedIndex].time, clickedIndex, selectedEvents); int selectedEventsCount = selectedEvents.Count(selected => selected); menu.AddItem( EditorGUIUtility.TrTextContent("Add Animation Event"), false, EventLineContextMenuAdd, contextData); menu.AddItem( new GUIContent(selectedEventsCount > 1 ? "Delete Animation Events" : "Delete Animation Event"), false, EventLineContextMenuDelete, contextData); menu.ShowAsContext(); // Mouse may move while context menu is open - make sure instant tooltip is handled m_InstantTooltipText = null; m_DirtyTooltip = true; state.Repaint(); break; } } CheckRectsOnMouseMove(rect, events, hitRects); // Create context menu on context click if (Event.current.type == EventType.ContextClick && eventLineRect.Contains(Event.current.mousePosition)) { Event.current.Use(); // Create menu GenericMenu menu = new GenericMenu(); var contextData = new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents); int selectedEventsCount = selectedEvents.Count(selected => selected); menu.AddItem( EditorGUIUtility.TrTextContent("Add Animation Event"), false, EventLineContextMenuAdd, contextData); if (selectedEventsCount > 0) { menu.AddItem( new GUIContent(selectedEventsCount > 1 ? "Delete Animation Events" : "Delete Animation Event"), false, EventLineContextMenuDelete, contextData); } menu.ShowAsContext(); } } GUI.color = backupCol; GUI.EndGroup(); }
public void EventLineGUI(Rect rect, AnimationWindowState state) { if (state.selectedItem != null) { AnimationClip animationClip = state.selectedItem.animationClip; GameObject rootGameObject = state.selectedItem.rootGameObject; GUI.BeginGroup(rect); Color color = GUI.color; Rect rect2 = new Rect(0f, 0f, rect.width, rect.height); float time = Mathf.Max((float) (((float) Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate)) / state.frameRate), (float) 0f); if (animationClip != null) { int num8; float num9; float num10; AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(animationClip); Texture image = EditorGUIUtility.IconContent("Animation.EventMarker").image; Rect[] hitPositions = new Rect[animationEvents.Length]; Rect[] positions = new Rect[animationEvents.Length]; int num2 = 1; int num3 = 0; for (int i = 0; i < animationEvents.Length; i++) { AnimationEvent event2 = animationEvents[i]; if (num3 == 0) { num2 = 1; while (((i + num2) < animationEvents.Length) && (animationEvents[i + num2].time == event2.time)) { num2++; } num3 = num2; } num3--; float num5 = Mathf.Floor(state.FrameToPixel(event2.time * animationClip.frameRate, rect)); int num6 = 0; if (num2 > 1) { float num7 = Mathf.Min((int) ((num2 - 1) * (image.width - 1)), (int) (((int) state.FrameDeltaToPixel(rect)) - (image.width * 2))); num6 = Mathf.FloorToInt(Mathf.Max((float) 0f, (float) (num7 - ((image.width - 1) * num3)))); } Rect rect3 = new Rect((num5 + num6) - (image.width / 2), ((rect.height - 10f) * ((num3 - num2) + 1)) / ((float) Mathf.Max(1, num2 - 1)), (float) image.width, (float) image.height); hitPositions[i] = rect3; positions[i] = rect3; } if (this.m_DirtyTooltip) { if ((this.m_HoverEvent >= 0) && (this.m_HoverEvent < hitPositions.Length)) { this.m_InstantTooltipText = AnimationWindowEventInspector.FormatEvent(rootGameObject, animationEvents[this.m_HoverEvent]); this.m_InstantTooltipPoint = new Vector2(((hitPositions[this.m_HoverEvent].xMin + ((int) (hitPositions[this.m_HoverEvent].width / 2f))) + rect.x) - 30f, rect.yMax); } this.m_DirtyTooltip = false; } if ((this.m_EventsSelected == null) || (this.m_EventsSelected.Length != animationEvents.Length)) { this.m_EventsSelected = new bool[animationEvents.Length]; } Vector2 zero = Vector2.zero; switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), hitPositions, ref this.m_EventsSelected, null, out num8, out zero, out num9, out num10, GUIStyle.none)) { case HighLevelEvent.DoubleClick: if (num8 == -1) { this.EventLineContextMenuAdd(new EventLineContextMenuObject(rootGameObject, animationClip, time, -1)); break; } Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8); break; case HighLevelEvent.ContextClick: { GenericMenu menu = new GenericMenu(); EventLineContextMenuObject userData = new EventLineContextMenuObject(rootGameObject, animationClip, animationEvents[num8].time, num8); menu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), userData); menu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData); menu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData); menu.ShowAsContext(); this.m_InstantTooltipText = null; this.m_DirtyTooltip = true; state.Repaint(); break; } case HighLevelEvent.BeginDrag: this.m_EventsAtMouseDown = animationEvents; this.m_EventTimes = new float[animationEvents.Length]; for (int j = 0; j < animationEvents.Length; j++) { this.m_EventTimes[j] = animationEvents[j].time; } break; case HighLevelEvent.Drag: { for (int k = animationEvents.Length - 1; k >= 0; k--) { if (this.m_EventsSelected[k]) { AnimationEvent event6 = this.m_EventsAtMouseDown[k]; event6.time = this.m_EventTimes[k] + (zero.x * state.PixelDeltaToTime(rect)); event6.time = Mathf.Max(0f, event6.time); event6.time = ((float) Mathf.RoundToInt(event6.time * animationClip.frameRate)) / animationClip.frameRate; } } int[] items = new int[this.m_EventsSelected.Length]; for (int m = 0; m < items.Length; m++) { items[m] = m; } Array.Sort(this.m_EventsAtMouseDown, items, new EventComparer()); bool[] flagArray = (bool[]) this.m_EventsSelected.Clone(); float[] numArray2 = (float[]) this.m_EventTimes.Clone(); for (int n = 0; n < items.Length; n++) { this.m_EventsSelected[n] = flagArray[items[n]]; this.m_EventTimes[n] = numArray2[items[n]]; } Undo.RegisterCompleteObjectUndo(animationClip, "Move Event"); AnimationUtility.SetAnimationEvents(animationClip, this.m_EventsAtMouseDown); this.m_DirtyTooltip = true; break; } case HighLevelEvent.Delete: this.DeleteEvents(animationClip, this.m_EventsSelected); break; case HighLevelEvent.SelectionChanged: state.ClearKeySelections(); if (num8 != -1) { Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8); } break; } this.CheckRectsOnMouseMove(rect, animationEvents, hitPositions); } if ((Event.current.type == EventType.ContextClick) && rect2.Contains(Event.current.mousePosition)) { Event.current.Use(); GenericMenu menu2 = new GenericMenu(); menu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new EventLineContextMenuObject(rootGameObject, animationClip, time, -1)); menu2.ShowAsContext(); } GUI.color = color; GUI.EndGroup(); } }
public void EventLineGUI(Rect rect, AnimationWindowState state) { AnimationClip activeAnimationClip = state.activeAnimationClip; GameObject activeRootGameObject = state.activeRootGameObject; GUI.BeginGroup(rect); Color color = GUI.color; Rect rect2 = new Rect(0f, 0f, rect.width, rect.height); float time = ((float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate)) / state.frameRate; if (activeAnimationClip != null) { int num8; float num9; float num10; AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(activeAnimationClip); Texture image = EditorGUIUtility.IconContent("Animation.EventMarker").image; Rect[] hitPositions = new Rect[animationEvents.Length]; Rect[] positions = new Rect[animationEvents.Length]; int num2 = 1; int num3 = 0; for (int i = 0; i < animationEvents.Length; i++) { AnimationEvent event2 = animationEvents[i]; if (num3 == 0) { num2 = 1; while (((i + num2) < animationEvents.Length) && (animationEvents[i + num2].time == event2.time)) { num2++; } num3 = num2; } num3--; float num5 = Mathf.Floor(state.FrameToPixel(event2.time * activeAnimationClip.frameRate, rect)); int num6 = 0; if (num2 > 1) { float num7 = Mathf.Min((int)((num2 - 1) * (image.width - 1)), (int)(((int)state.FrameDeltaToPixel(rect)) - (image.width * 2))); num6 = Mathf.FloorToInt(Mathf.Max((float)0f, (float)(num7 - ((image.width - 1) * num3)))); } Rect rect3 = new Rect((num5 + num6) - (image.width / 2), ((rect.height - 10f) * ((num3 - num2) + 1)) / ((float)Mathf.Max(1, num2 - 1)), (float)image.width, (float)image.height); hitPositions[i] = rect3; positions[i] = rect3; } if (this.m_DirtyTooltip) { if ((this.m_HoverEvent >= 0) && (this.m_HoverEvent < hitPositions.Length)) { this.m_InstantTooltipText = AnimationEventPopup.FormatEvent(activeRootGameObject, animationEvents[this.m_HoverEvent]); this.m_InstantTooltipPoint = new Vector2(((hitPositions[this.m_HoverEvent].xMin + ((int)(hitPositions[this.m_HoverEvent].width / 2f))) + rect.x) - 30f, rect.yMax); } this.m_DirtyTooltip = false; } if ((this.m_EventsSelected == null) || (this.m_EventsSelected.Length != animationEvents.Length)) { this.m_EventsSelected = new bool[animationEvents.Length]; AnimationEventPopup.ClosePopup(); } Vector2 zero = Vector2.zero; switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), hitPositions, ref this.m_EventsSelected, null, out num8, out zero, out num9, out num10, GUIStyle.none)) { case HighLevelEvent.DoubleClick: if (num8 == -1) { this.EventLineContextMenuAdd(new EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1)); break; } AnimationEventPopup.Edit(activeRootGameObject, state.activeAnimationClip, num8, this.m_Owner); break; case HighLevelEvent.ContextClick: { GenericMenu menu = new GenericMenu(); EventLineContextMenuObject userData = new EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, animationEvents[num8].time, num8); menu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), userData); menu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData); menu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData); menu.ShowAsContext(); this.m_InstantTooltipText = null; this.m_DirtyTooltip = true; state.Repaint(); break; } case HighLevelEvent.BeginDrag: this.m_EventsAtMouseDown = animationEvents; this.m_EventTimes = new float[animationEvents.Length]; for (int j = 0; j < animationEvents.Length; j++) { this.m_EventTimes[j] = animationEvents[j].time; } break; case HighLevelEvent.Drag: { for (int k = animationEvents.Length - 1; k >= 0; k--) { if (this.m_EventsSelected[k]) { AnimationEvent event4 = this.m_EventsAtMouseDown[k]; event4.time = this.m_EventTimes[k] + (zero.x * state.PixelDeltaToTime(rect)); event4.time = Mathf.Max(0f, event4.time); event4.time = ((float)Mathf.RoundToInt(event4.time * activeAnimationClip.frameRate)) / activeAnimationClip.frameRate; } } int[] items = new int[this.m_EventsSelected.Length]; for (int m = 0; m < items.Length; m++) { items[m] = m; } Array.Sort(this.m_EventsAtMouseDown, items, new EventComparer()); bool[] flagArray = (bool[])this.m_EventsSelected.Clone(); float[] numArray2 = (float[])this.m_EventTimes.Clone(); for (int n = 0; n < items.Length; n++) { this.m_EventsSelected[n] = flagArray[items[n]]; this.m_EventTimes[n] = numArray2[items[n]]; } Undo.RegisterCompleteObjectUndo(activeAnimationClip, "Move Event"); AnimationUtility.SetAnimationEvents(activeAnimationClip, this.m_EventsAtMouseDown); this.m_DirtyTooltip = true; break; } case HighLevelEvent.Delete: this.DeleteEvents(activeAnimationClip, this.m_EventsSelected); break; case HighLevelEvent.SelectionChanged: state.ClearKeySelections(); if (num8 != -1) { AnimationEventPopup.UpdateSelection(activeRootGameObject, state.activeAnimationClip, num8, this.m_Owner); } break; } this.CheckRectsOnMouseMove(rect, animationEvents, hitPositions); } if ((Event.current.type == EventType.ContextClick) && rect2.Contains(Event.current.mousePosition)) { Event.current.Use(); GenericMenu menu2 = new GenericMenu(); menu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1)); menu2.ShowAsContext(); } GUI.color = color; GUI.EndGroup(); }