public static void AddKeyframes(AnimationWindowState state, AnimationWindowCurve[] curves, AnimationKeyTime time) { string undoLabel = "Add Key"; state.SaveKeySelection(undoLabel); state.ClearKeySelections(); foreach (AnimationWindowCurve curve in curves) { if (curve.animationIsEditable) { AnimationKeyTime time2 = AnimationKeyTime.Time(time.time - curve.timeOffset, time.frameRate); object currentValue = CurveBindingUtility.GetCurrentValue(state, curve); AnimationWindowKeyframe keyframe = AddKeyframeToCurve(curve, currentValue, curve.valueType, time2); state.SaveCurve(curve, undoLabel); state.SelectKey(keyframe); } } }
public static void AddKeyframes(AnimationWindowState state, AnimationWindowCurve[] curves, AnimationKeyTime time) { string undoLabel = "Add Key"; state.SaveKeySelection(undoLabel); state.ClearKeySelections(); for (int i = 0; i < curves.Length; i++) { AnimationWindowCurve animationWindowCurve = curves[i]; if (animationWindowCurve.animationIsEditable) { AnimationKeyTime time2 = AnimationKeyTime.Time(time.time - animationWindowCurve.timeOffset, time.frameRate); object currentValue = CurveBindingUtility.GetCurrentValue(state, animationWindowCurve); AnimationWindowKeyframe keyframe = AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, currentValue, animationWindowCurve.valueType, time2); state.SaveCurve(animationWindowCurve, undoLabel); state.SelectKey(keyframe); } } }
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(); } }