public static void OnEditAnimationEvents(AnimationWindowEvent[] awEvents) { AnimationWindowEventInspector.AnimationWindowEventData data = AnimationWindowEventInspector.GetData(awEvents); if (data.events != null && data.selectedEvents != null && data.selectedEvents.Length != 0) { AnimationEvent firstEvent = data.selectedEvents[0]; bool flag = Array.TrueForAll <AnimationEvent>(data.selectedEvents, (AnimationEvent evt) => evt.functionName == firstEvent.functionName); GUI.changed = false; if (data.root != null) { List <AnimationWindowEventMethod> list = AnimationWindowEventInspector.CollectSupportedMethods(data.root); List <string> list2 = new List <string>(list.Count); for (int i = 0; i < list.Count; i++) { AnimationWindowEventMethod animationWindowEventMethod = list[i]; string str = " ( )"; if (animationWindowEventMethod.parameterType != null) { if (animationWindowEventMethod.parameterType == typeof(float)) { str = " ( float )"; } else if (animationWindowEventMethod.parameterType == typeof(int)) { str = " ( int )"; } else { str = string.Format(" ( {0} )", animationWindowEventMethod.parameterType.Name); } } list2.Add(animationWindowEventMethod.name + str); } int count = list.Count; int num = list.FindIndex((AnimationWindowEventMethod method) => method.name == firstEvent.functionName); if (num == -1) { num = list.Count; list.Add(new AnimationWindowEventMethod { name = firstEvent.functionName, parameterType = null }); if (string.IsNullOrEmpty(firstEvent.functionName)) { list2.Add("(No Function Selected)"); } else { list2.Add(firstEvent.functionName + " (Function Not Supported)"); } } EditorGUIUtility.labelWidth = 130f; EditorGUI.showMixedValue = !flag; int num2 = (!flag) ? -1 : num; num = EditorGUILayout.Popup("Function: ", num, list2.ToArray(), new GUILayoutOption[0]); if (num2 != num && num != -1 && num != count) { AnimationEvent[] selectedEvents = data.selectedEvents; for (int j = 0; j < selectedEvents.Length; j++) { AnimationEvent animationEvent = selectedEvents[j]; animationEvent.functionName = list[num].name; animationEvent.stringParameter = string.Empty; } } EditorGUI.showMixedValue = false; Type parameterType = list[num].parameterType; if (flag && parameterType != null) { EditorGUILayout.Space(); if (parameterType == typeof(AnimationEvent)) { EditorGUILayout.PrefixLabel("Event Data"); } else { EditorGUILayout.PrefixLabel("Parameters"); } AnimationWindowEventInspector.DoEditRegularParameters(data.selectedEvents, parameterType); } } else { EditorGUI.showMixedValue = !flag; string text = (!flag) ? "" : firstEvent.functionName; string text2 = EditorGUILayout.TextField(EditorGUIUtility.TrTextContent("Function", null, null), text, new GUILayoutOption[0]); if (text2 != text) { AnimationEvent[] selectedEvents2 = data.selectedEvents; for (int k = 0; k < selectedEvents2.Length; k++) { AnimationEvent animationEvent2 = selectedEvents2[k]; animationEvent2.functionName = text2; animationEvent2.stringParameter = string.Empty; } } EditorGUI.showMixedValue = false; if (flag) { AnimationWindowEventInspector.DoEditRegularParameters(data.selectedEvents, typeof(AnimationEvent)); } else { using (new EditorGUI.DisabledScope(true)) { AnimationEvent animationEvent3 = new AnimationEvent(); AnimationWindowEventInspector.DoEditRegularParameters(new AnimationEvent[] { animationEvent3 }, typeof(AnimationEvent)); } } } if (GUI.changed) { AnimationWindowEventInspector.SetData(awEvents, data); } } }
public static List <AnimationWindowEventMethod> CollectSupportedMethods(GameObject gameObject) { List <AnimationWindowEventMethod> list = new List <AnimationWindowEventMethod>(); List <AnimationWindowEventMethod> result; if (gameObject == null) { result = list; } else { MonoBehaviour[] components = gameObject.GetComponents <MonoBehaviour>(); HashSet <string> hashSet = new HashSet <string>(); MonoBehaviour[] array = components; for (int i = 0; i < array.Length; i++) { MonoBehaviour monoBehaviour = array[i]; if (!(monoBehaviour == null)) { Type type = monoBehaviour.GetType(); while (type != typeof(MonoBehaviour) && type != null) { MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int j = 0; j < methods.Length; j++) { MethodInfo methodInfo = methods[j]; string name = methodInfo.Name; if (AnimationWindowEventInspector.IsSupportedMethodName(name)) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length <= 1) { Type type2 = null; if (parameters.Length == 1) { type2 = parameters[0].ParameterType; if (type2 != typeof(string) && type2 != typeof(float) && type2 != typeof(int) && type2 != typeof(AnimationEvent) && type2 != typeof(UnityEngine.Object) && !type2.IsSubclassOf(typeof(UnityEngine.Object)) && !type2.IsEnum) { goto IL_1BD; } } AnimationWindowEventMethod item = default(AnimationWindowEventMethod); item.name = methodInfo.Name; item.parameterType = type2; int num = list.FindIndex((AnimationWindowEventMethod m) => m.name == name); if (num != -1) { if (list[num].parameterType != type2) { hashSet.Add(name); } } list.Add(item); } } IL_1BD :; } type = type.BaseType; } } } foreach (string current in hashSet) { for (int k = list.Count - 1; k >= 0; k--) { if (list[k].name.Equals(current)) { list.RemoveAt(k); } } } result = list; } return(result); }
public static void OnEditAnimationEvents(AnimationWindowEvent[] awEvents) { AnimationWindowEventData data = GetData(awEvents); if (data.events == null || data.selectedEvents == null || data.selectedEvents.Length == 0) { return; } AnimationEvent firstEvent = data.selectedEvents[0]; bool singleFunctionName = Array.TrueForAll(data.selectedEvents, evt => evt.functionName == firstEvent.functionName); GUI.changed = false; if (data.root != null) { List <AnimationWindowEventMethod> methods = new List <AnimationWindowEventMethod>(); HashSet <string> overloads = new HashSet <string>(); CollectSupportedMethods(data.root, methods, overloads); var methodsFormatted = new List <string>(methods.Count); for (int i = 0; i < methods.Count; ++i) { AnimationWindowEventMethod method = methods[i]; string postFix = " ( )"; if (method.parameterType != null) { if (method.parameterType == typeof(float)) { postFix = " ( float )"; } else if (method.parameterType == typeof(int)) { postFix = " ( int )"; } else { postFix = string.Format(" ( {0} )", method.parameterType.Name); } } methodsFormatted.Add(method.name + postFix); } int notSupportedIndex = methods.Count; int selected = methods.FindIndex(method => method.name == firstEvent.functionName); if (selected == -1) { selected = methods.Count; AnimationWindowEventMethod newMethod = new AnimationWindowEventMethod(); newMethod.name = firstEvent.functionName; newMethod.parameterType = null; methods.Add(newMethod); if (string.IsNullOrEmpty(firstEvent.functionName)) { methodsFormatted.Add(kNoneSelected); } else { methodsFormatted.Add(firstEvent.functionName + kNotSupportedPostFix); } } EditorGUIUtility.labelWidth = 130; EditorGUI.showMixedValue = !singleFunctionName; int wasSelected = singleFunctionName ? selected : -1; selected = EditorGUILayout.Popup("Function: ", selected, methodsFormatted.ToArray()); if (wasSelected != selected && selected != -1 && selected != notSupportedIndex) { foreach (var evt in data.selectedEvents) { evt.functionName = methods[selected].name; evt.stringParameter = string.Empty; } } EditorGUI.showMixedValue = false; var selectedParameter = methods[selected].parameterType; if (singleFunctionName && selectedParameter != null) { EditorGUILayout.Space(); if (selectedParameter == typeof(AnimationEvent)) { EditorGUILayout.PrefixLabel("Event Data"); } else { EditorGUILayout.PrefixLabel("Parameters"); } DoEditRegularParameters(data.selectedEvents, selectedParameter); } if (overloads.Count > 0) { EditorGUILayout.Space(); EditorGUILayout.HelpBox(s_OverloadWarning.text, MessageType.Warning, true); } } else { EditorGUI.showMixedValue = !singleFunctionName; string oldFunctionName = singleFunctionName ? firstEvent.functionName : ""; string functionName = EditorGUILayout.TextField(EditorGUIUtility.TrTextContent("Function"), oldFunctionName); if (functionName != oldFunctionName) { foreach (var evt in data.selectedEvents) { evt.functionName = functionName; evt.stringParameter = string.Empty; } } EditorGUI.showMixedValue = false; if (singleFunctionName) { DoEditRegularParameters(data.selectedEvents, typeof(AnimationEvent)); } else { using (new EditorGUI.DisabledScope(true)) { AnimationEvent dummyEvent = new AnimationEvent(); DoEditRegularParameters(new AnimationEvent[] { dummyEvent }, typeof(AnimationEvent)); } } } if (GUI.changed) { SetData(awEvents, data); } }
public static void CollectSupportedMethods(GameObject gameObject, List <AnimationWindowEventMethod> supportedMethods, HashSet <string> overloadedMethods) { if (gameObject == null) { return; } MonoBehaviour[] behaviours = gameObject.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour behaviour in behaviours) { if (behaviour == null) { continue; } Type type = behaviour.GetType(); while (type != typeof(MonoBehaviour) && type != null) { MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); for (int i = 0; i < methods.Length; i++) { MethodInfo method = methods[i]; string name = method.Name; if (!IsSupportedMethodName(name)) { continue; } ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length > 1) { continue; } Type parameterType = null; if (parameters.Length == 1) { parameterType = parameters[0].ParameterType; if (!(parameterType == typeof(string) || parameterType == typeof(float) || parameterType == typeof(int) || parameterType == typeof(AnimationEvent) || parameterType == typeof(UnityEngine.Object) || parameterType.IsSubclassOf(typeof(UnityEngine.Object)) || parameterType.IsEnum)) { continue; } } AnimationWindowEventMethod newMethod = new AnimationWindowEventMethod(); newMethod.name = method.Name; newMethod.parameterType = parameterType; // Since AnimationEvents only stores method name, it can't handle functions with multiple overloads. // Only retrieve first found function, but discard overloads. int existingMethodIndex = supportedMethods.FindIndex(m => m.name == name); if (existingMethodIndex != -1) { // The method is only ambiguous if it has a different signature to the one we saw before if (supportedMethods[existingMethodIndex].parameterType != parameterType) { overloadedMethods.Add(name); } } else { supportedMethods.Add(newMethod); } } type = type.BaseType; } } }
public static void OnEditAnimationEvent(AnimationWindowEvent awevt) { AnimationEvent[] array = null; if (awevt.clip != null) { array = AnimationUtility.GetAnimationEvents(awevt.clip); } else if (awevt.clipInfo != null) { array = awevt.clipInfo.GetEvents(); } if (array != null && awevt.eventIndex >= 0 && awevt.eventIndex < array.Length) { AnimationEvent evt = array[awevt.eventIndex]; GUI.changed = false; if (awevt.root != null) { List <AnimationWindowEventMethod> list = AnimationWindowEventInspector.CollectSupportedMethods(awevt); List <string> list2 = new List <string>(list.Count); for (int i = 0; i < list.Count; i++) { AnimationWindowEventMethod animationWindowEventMethod = list[i]; string str = " ( )"; if (animationWindowEventMethod.parameterType != null) { if (animationWindowEventMethod.parameterType == typeof(float)) { str = " ( float )"; } else if (animationWindowEventMethod.parameterType == typeof(int)) { str = " ( int )"; } else { str = string.Format(" ( {0} )", animationWindowEventMethod.parameterType.Name); } } list2.Add(animationWindowEventMethod.name + str); } int count = list.Count; int num = list.FindIndex((AnimationWindowEventMethod method) => method.name == evt.functionName); if (num == -1) { num = list.Count; list.Add(new AnimationWindowEventMethod { name = evt.functionName, parameterType = null }); if (string.IsNullOrEmpty(evt.functionName)) { list2.Add("(No Function Selected)"); } else { list2.Add(evt.functionName + " (Function Not Supported)"); } } EditorGUIUtility.labelWidth = 130f; int num2 = num; num = EditorGUILayout.Popup("Function: ", num, list2.ToArray(), new GUILayoutOption[0]); if (num2 != num && num != -1 && num != count) { evt.functionName = list[num].name; evt.stringParameter = string.Empty; } Type parameterType = list[num].parameterType; if (parameterType != null) { EditorGUILayout.Space(); if (parameterType == typeof(AnimationEvent)) { EditorGUILayout.PrefixLabel("Event Data"); } else { EditorGUILayout.PrefixLabel("Parameters"); } AnimationWindowEventInspector.DoEditRegularParameters(evt, parameterType); } } else { evt.functionName = EditorGUILayout.TextField(new GUIContent("Function"), evt.functionName, new GUILayoutOption[0]); AnimationWindowEventInspector.DoEditRegularParameters(evt, typeof(AnimationEvent)); } if (GUI.changed) { if (awevt.clip != null) { Undo.RegisterCompleteObjectUndo(awevt.clip, "Animation Event Change"); AnimationUtility.SetAnimationEvents(awevt.clip, array); } else if (awevt.clipInfo != null) { awevt.clipInfo.SetEvent(awevt.eventIndex, evt); } } } }
public static List <AnimationWindowEventMethod> CollectSupportedMethods(GameObject gameObject) { List <AnimationWindowEventMethod> supportedMethods = new List <AnimationWindowEventMethod>(); if (gameObject == null) { return(supportedMethods); } MonoBehaviour[] behaviours = gameObject.GetComponents <MonoBehaviour>(); HashSet <string> ambiguousMethods = new HashSet <string>(); foreach (MonoBehaviour behaviour in behaviours) { if (behaviour == null) { continue; } Type type = behaviour.GetType(); while (type != typeof(MonoBehaviour) && type != null) { MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); for (int i = 0; i < methods.Length; i++) { MethodInfo method = methods[i]; string name = method.Name; if (!IsSupportedMethodName(name)) { continue; } ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length > 1) { continue; } Type parameterType = null; if (parameters.Length == 1) { parameterType = parameters[0].ParameterType; if (!(parameterType == typeof(string) || parameterType == typeof(float) || parameterType == typeof(int) || parameterType == typeof(AnimationEvent) || parameterType == typeof(UnityEngine.Object) || parameterType.IsSubclassOf(typeof(UnityEngine.Object)) || parameterType.IsEnum)) { continue; } } AnimationWindowEventMethod newMethod = new AnimationWindowEventMethod(); newMethod.name = method.Name; newMethod.parameterType = parameterType; int existingMethodIndex = supportedMethods.FindIndex(m => m.name == name); if (existingMethodIndex != -1) { // The method is only ambiguous if it has a different signature to the one we saw before if (supportedMethods[existingMethodIndex].parameterType != parameterType) { ambiguousMethods.Add(name); } } supportedMethods.Add(newMethod); } type = type.BaseType; } } // Since AnimationEvents only stores method name, it can't handle functions with multiple overloads // So we remove all the ambiguous methods (overloads) from the list foreach (string ambiguousMethod in ambiguousMethods) { for (int i = supportedMethods.Count - 1; i >= 0; --i) { if (supportedMethods[i].name.Equals(ambiguousMethod)) { supportedMethods.RemoveAt(i); } } } return(supportedMethods); }