private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames) { Array.Sort <UnityEngine.Object>(frames, (UnityEngine.Object a, UnityEngine.Object b) => EditorUtility.NaturalCompare(a.name, b.name)); string message = string.Format("Create a new animation for the game object '{0}':", gameObject.name); string directoryName = Path.GetDirectoryName(AssetDatabase.GetAssetPath(frames[0])); string text = EditorUtility.SaveFilePanelInProject("Create New Animation", "New Animation", "anim", message, directoryName); if (string.IsNullOrEmpty(text)) { return(false); } AnimationClip animationClip = AnimationSelection.AllocateAndSetupClip(true); AssetDatabase.CreateAsset(animationClip, text); AnimationSelection.AddClipToAnimatorComponent(gameObject, animationClip); animationClip.frameRate = 12f; ObjectReferenceKeyframe[] array = new ObjectReferenceKeyframe[frames.Length]; for (int i = 0; i < array.Length; i++) { array[i] = default(ObjectReferenceKeyframe); array[i].value = SpriteUtility.RemapObjectToSprite(frames[i]); array[i].time = (float)i / animationClip.frameRate; } EditorCurveBinding binding = EditorCurveBinding.PPtrCurve(string.Empty, typeof(SpriteRenderer), "m_Sprite"); AnimationUtility.SetObjectReferenceCurve(animationClip, binding, array); return(true); }
public static string GetObjectListHashCode(GameObject[] animatedOptions) { string[] array = new string[animatedOptions.Length]; for (int i = 0; i < array.Length; i++) { array[i] = animatedOptions[i].name; } return(AnimationSelection.GetStringArrayHashCode(array)); }
public void Expand(AnimationHierarchyData data, int level) { this.m_Expanded = true; if (level > 0) { data.expandedFoldouts.Set(AnimationSelection.GetPath(this.obj.transform)); } data.animationWindow.SetDirtyCurves(); }
public void Collapse(AnimationHierarchyData data, int level) { this.m_Expanded = false; this.Hide(data, level); if (level > 0) { data.expandedFoldouts.Remove(AnimationSelection.GetPath(this.obj.transform)); } data.animationWindow.SetDirtyCurves(); }
public AnimationSelection(GameObject[] animatedOptions, SerializedStringTable chosenAnimated, SerializedStringTable chosenClip, AnimationWindow editor) { this.m_AnimationWindow = editor; this.m_AnimatedOptions = animatedOptions; string stringArrayHashCode = AnimationSelection.GetStringArrayHashCode(this.GetAnimatedObjectNames()); if (!chosenAnimated.Contains(stringArrayHashCode)) { chosenAnimated.Set(stringArrayHashCode, animatedOptions.Length - 1); } this.m_AnimatedObjectIndex = chosenAnimated.Get(stringArrayHashCode); this.RefreshChosenClip(chosenClip); }
private AnimationClip CreateNewClip() { bool flag = this.animatedObject.GetComponent <Animator>() != null || this.animatedObject.GetComponent <Animation>() == null; string message = string.Format("Create a new animation for the game object '{0}':", this.animatedObject.name); string text = EditorUtility.SaveFilePanelInProject("Create New Animation", "New Animation", "anim", message, ProjectWindowUtil.GetActiveFolderPath()); if (text == string.Empty) { return(null); } AnimationClip animationClip = AnimationSelection.AllocateAndSetupClip(flag); AssetDatabase.CreateAsset(animationClip, text); this.m_AnimationWindow.EndAnimationMode(); if (flag) { return(AnimationSelection.AddClipToAnimatorComponent(this.animatedObject, animationClip)); } return(this.AddClipToAnimationComponent(animationClip)); }
public static void OnGUISelection(AnimationSelection animSel) { if (animSel == null) { bool enabled = GUI.enabled; GUI.enabled = false; GUILayout.Label(string.Empty, EditorStyles.toolbarPopup, new GUILayoutOption[0]); GUI.enabled = enabled; return; } animSel.m_ClipCanceled = false; bool flag = false; string[] clipMenuContent = animSel.GetClipMenuContent(); int clipIndex = animSel.clipIndex; int num = EditorGUILayout.Popup(clipIndex, clipMenuContent, EditorStyles.toolbarPopup, new GUILayoutOption[0]); if (num != clipIndex) { AnimationClip animationClip = animSel.GetClipAtIndex(num); if (animationClip == null) { animationClip = animSel.CreateNewClip(); } if (animationClip != null) { animSel.ChooseClip(animationClip); flag = true; } } if (flag) { GUI.changed = true; animSel.animationWindow.ReEnterAnimationMode(); animSel.Refresh(); } }
private void RefreshChosenClip(SerializedStringTable chosenClip) { if (this.hasAnimationComponent) { string stringArrayHashCode = AnimationSelection.GetStringArrayHashCode(this.GetClipNames()); if (!chosenClip.Contains(stringArrayHashCode)) { this.m_Clip = null; AnimationClip[] animationClips = AnimationUtility.GetAnimationClips(this.animatedObject); for (int i = 0; i < animationClips.Length; i++) { if (animationClips[i] != null) { this.m_Clip = animationClips[i]; break; } } } else { this.m_Clip = this.GetClipAtIndex(chosenClip.Get(stringArrayHashCode)); } } }
public FoldoutObjectState(GameObject obj, List <FoldoutObjectState> states, SerializedStringTable expandedFoldouts, int level) { this.m_Object = obj; states.Add(this); if (level == 0) { this.m_Expanded = true; } else { if (expandedFoldouts.Contains(AnimationSelection.GetPath(obj.transform))) { this.m_Expanded = true; } } List <int> list = new List <int>(); foreach (Transform transform in obj.transform) { list.Add(states.Count); new FoldoutObjectState(transform.gameObject, states, expandedFoldouts, level + 1); } this.m_Children = list.ToArray(); }
public void EventLineGUI(Rect rect, AnimationSelection selection, AnimationWindowState state, CurveEditor curveEditor) { AnimationClip activeAnimationClip = state.m_ActiveAnimationClip; GameObject rootGameObject = state.m_RootGameObject; 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) { AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(activeAnimationClip); Texture image = EditorGUIUtility.IconContent("Animation.EventMarker").image; Rect[] array = new Rect[animationEvents.Length]; Rect[] array2 = new Rect[animationEvents.Length]; int num = 1; int num2 = 0; for (int i = 0; i < animationEvents.Length; i++) { AnimationEvent animationEvent = animationEvents[i]; if (num2 == 0) { num = 1; while (i + num < animationEvents.Length && animationEvents[i + num].time == animationEvent.time) { num++; } num2 = num; } num2--; float num3 = Mathf.Floor(state.FrameToPixel(animationEvent.time * activeAnimationClip.frameRate, rect)); int num4 = 0; if (num > 1) { float num5 = (float)Mathf.Min((num - 1) * (image.width - 1), (int)(state.FrameDeltaToPixel(rect) - (float)(image.width * 2))); num4 = Mathf.FloorToInt(Mathf.Max(0f, num5 - (float)((image.width - 1) * num2))); } Rect rect3 = new Rect(num3 + (float)num4 - (float)(image.width / 2), (rect.height - 10f) * (float)(num2 - num + 1) / (float)Mathf.Max(1, num - 1), (float)image.width, (float)image.height); array[i] = rect3; array2[i] = rect3; } if (this.m_DirtyTooltip) { if (this.m_HoverEvent >= 0 && this.m_HoverEvent < array.Length) { this.m_InstantTooltipText = AnimationEventPopup.FormatEvent(rootGameObject, animationEvents[this.m_HoverEvent]); this.m_InstantTooltipPoint = new Vector2(array[this.m_HoverEvent].xMin + (float)((int)(array[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; int num6; float num7; float num8; HighLevelEvent highLevelEvent = EditorGUIExt.MultiSelection(rect, array2, new GUIContent(image), array, ref this.m_EventsSelected, null, out num6, out zero, out num7, out num8, GUIStyleX.none); if (highLevelEvent != HighLevelEvent.None) { switch (highLevelEvent) { case HighLevelEvent.DoubleClick: if (num6 != -1) { AnimationEventPopup.Edit(rootGameObject, selection.clip, num6, this.m_Owner); } else { this.EventLineContextMenuAdd(new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, activeAnimationClip, time, -1)); } break; case HighLevelEvent.ContextClick: { GenericMenu genericMenu = new GenericMenu(); AnimationEventTimeLine.EventLineContextMenuObject userData = new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, activeAnimationClip, animationEvents[num6].time, num6); genericMenu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), userData); genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData); genericMenu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData); genericMenu.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 animationEvent2 = this.m_EventsAtMouseDown[k]; animationEvent2.time = this.m_EventTimes[k] + zero.x * state.PixelDeltaToTime(rect); animationEvent2.time = Mathf.Max(0f, animationEvent2.time); animationEvent2.time = (float)Mathf.RoundToInt(animationEvent2.time * activeAnimationClip.frameRate) / activeAnimationClip.frameRate; this.m_EventsAtMouseDown[k] = animationEvent2; } } int[] array3 = new int[this.m_EventsSelected.Length]; for (int l = 0; l < array3.Length; l++) { array3[l] = l; } Array.Sort(this.m_EventsAtMouseDown, array3, new AnimationEventTimeLine.EventComparer()); bool[] array4 = (bool[])this.m_EventsSelected.Clone(); float[] array5 = (float[])this.m_EventTimes.Clone(); for (int m = 0; m < array3.Length; m++) { this.m_EventsSelected[m] = array4[array3[m]]; this.m_EventTimes[m] = array5[array3[m]]; } 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: curveEditor.SelectNone(); if (num6 != -1) { AnimationEventPopup.UpdateSelection(rootGameObject, selection.clip, num6, this.m_Owner); } break; } } this.CheckRectsOnMouseMove(rect, animationEvents, array); } if (Event.current.type == EventType.ContextClick && rect2.Contains(Event.current.mousePosition) && selection.EnsureClipPresence()) { Event.current.Use(); GenericMenu genericMenu2 = new GenericMenu(); genericMenu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, activeAnimationClip, time, -1)); genericMenu2.ShowAsContext(); } GUI.color = color; GUI.EndGroup(); }
private AnimationSelection GetOrAddAnimationSelectionWithObjects(GameObject[] animatedOptions, List<AnimationSelection> animSelected) { AnimationSelection animationSelection = null; string objectListHashCode = AnimationSelection.GetObjectListHashCode(animatedOptions); foreach (AnimationSelection current in animSelected) { if (AnimationSelection.GetObjectListHashCode(current.animatedOptions) == objectListHashCode) { animationSelection = current; break; } } if (animationSelection == null) { animationSelection = new AnimationSelection(animatedOptions, this.m_ChosenAnimated, this.m_ChosenClip, this); animSelected.Add(animationSelection); } return animationSelection; }
private void ChooseClip(AnimationClip newClip, int newClipIndex) { this.m_Clip = newClip; this.m_AnimationWindow.chosenClip.Set(AnimationSelection.GetStringArrayHashCode(this.GetClipNames()), newClipIndex); this.m_AnimationWindow.state.m_ActiveAnimationClip = this.m_Clip; }
public string GetString(Transform tr) { return(AnimationSelection.GetPath(tr) + "/:" + ObjectNames.GetInspectorTitle(this.obj)); }