Exemple #1
0
        public static string FormatEvent(GameObject root, AnimationEvent evt)
        {
            string result;

            if (string.IsNullOrEmpty(evt.functionName))
            {
                result = "(No Function Selected)";
            }
            else if (!AnimationWindowEventInspector.IsSupportedMethodName(evt.functionName))
            {
                result = evt.functionName + " (Function Not Supported)";
            }
            else if (root == null)
            {
                result = evt.functionName + " (Function Not Supported)";
            }
            else
            {
                MonoBehaviour[] components = root.GetComponents <MonoBehaviour>();
                for (int i = 0; i < components.Length; i++)
                {
                    MonoBehaviour monoBehaviour = components[i];
                    if (!(monoBehaviour == null))
                    {
                        Type type = monoBehaviour.GetType();
                        if (type != typeof(MonoBehaviour) && (type.BaseType == null || !(type.BaseType.Name == "GraphBehaviour")))
                        {
                            MethodInfo methodInfo = null;
                            try
                            {
                                methodInfo = type.GetMethod(evt.functionName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                            }
                            catch (AmbiguousMatchException)
                            {
                            }
                            if (methodInfo != null)
                            {
                                IEnumerable <Type> paramTypes = from p in methodInfo.GetParameters()
                                                                select p.ParameterType;
                                result = evt.functionName + AnimationWindowEventInspector.FormatEventArguments(paramTypes, evt);
                                return(result);
                            }
                        }
                    }
                }
                result = evt.functionName + " (Function Not Supported)";
            }
            return(result);
        }
Exemple #2
0
        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);
        }