コード例 #1
0
 public static string FormatEvent(GameObject root, AnimationEvent evt)
 {
     if (string.IsNullOrEmpty(evt.functionName))
     {
         return("(No Function Selected)");
     }
     if (!AnimationEventPopup.IsSupportedMethodName(evt.functionName))
     {
         return(evt.functionName + " (Function Not Supported)");
     }
     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 method = type.GetMethod(evt.functionName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                 if (method != null)
                 {
                     IEnumerable <Type> paramTypes = from p in method.GetParameters()
                                                     select p.ParameterType;
                     return(evt.functionName + AnimationEventPopup.FormatEventArguments(paramTypes, evt));
                 }
             }
         }
     }
     return(evt.functionName + " (Function Not Supported)");
 }
コード例 #2
0
 public static string FormatEvent(GameObject root, AnimationEvent evt)
 {
     if (string.IsNullOrEmpty(evt.functionName))
     {
         return("(No Function Selected)");
     }
     if (!AnimationEventPopup.IsSupportedMethodName(evt.functionName))
     {
         return(evt.functionName + " (Function Not Supported)");
     }
     foreach (MonoBehaviour component in root.GetComponents <MonoBehaviour>())
     {
         if (!((UnityEngine.Object)component == (UnityEngine.Object)null))
         {
             System.Type type = component.GetType();
             if (type != typeof(MonoBehaviour) && (type.BaseType == null || !(type.BaseType.Name == "GraphBehaviour")))
             {
                 MethodInfo method = type.GetMethod(evt.functionName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                 if (method != null)
                 {
                     IEnumerable <System.Type> paramTypes = ((IEnumerable <System.Reflection.ParameterInfo>)method.GetParameters()).Select <System.Reflection.ParameterInfo, System.Type>((Func <System.Reflection.ParameterInfo, System.Type>)(p => p.ParameterType));
                     return(evt.functionName + AnimationEventPopup.FormatEventArguments(paramTypes, evt));
                 }
             }
         }
     }
     return(evt.functionName + " (Function Not Supported)");
 }
コード例 #3
0
        private static void CollectSupportedMethods(GameObject root, out List <string> supportedMethods, out List <Type> supportedMethodsParameter)
        {
            supportedMethods          = new List <string>();
            supportedMethodsParameter = new List <Type>();
            MonoBehaviour[]  components = root.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 (AnimationEventPopup.IsSupportedMethodName(name))
                            {
                                ParameterInfo[] parameters = methodInfo.GetParameters();
                                if (parameters.Length <= 1)
                                {
                                    if (parameters.Length == 1)
                                    {
                                        Type 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)
                                        {
                                            goto IL_160;
                                        }
                                        supportedMethodsParameter.Add(parameterType);
                                    }
                                    else
                                    {
                                        supportedMethodsParameter.Add(null);
                                    }
                                    if (supportedMethods.Contains(name))
                                    {
                                        hashSet.Add(name);
                                    }
                                    supportedMethods.Add(name);
                                }
                            }
                            IL_160 :;
                        }
                        type = type.BaseType;
                    }
                }
            }
            foreach (string current in hashSet)
            {
                for (int k = 0; k < supportedMethods.Count; k++)
                {
                    if (supportedMethods[k].Equals(current))
                    {
                        supportedMethods.RemoveAt(k);
                        supportedMethodsParameter.RemoveAt(k);
                        k--;
                    }
                }
            }
        }
コード例 #4
0
        private static void CollectSupportedMethods(GameObject root, out List <string> supportedMethods, out List <System.Type> supportedMethodsParameter)
        {
            supportedMethods          = new List <string>();
            supportedMethodsParameter = new List <System.Type>();
            MonoBehaviour[]  components = root.GetComponents <MonoBehaviour>();
            HashSet <string> stringSet  = new HashSet <string>();

            foreach (MonoBehaviour monoBehaviour in components)
            {
                if (!((UnityEngine.Object)monoBehaviour == (UnityEngine.Object)null))
                {
                    for (System.Type type = monoBehaviour.GetType(); type != typeof(MonoBehaviour) && type != null; type = type.BaseType)
                    {
                        foreach (MethodInfo method in type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            string name = method.Name;
                            if (AnimationEventPopup.IsSupportedMethodName(name))
                            {
                                System.Reflection.ParameterInfo[] parameters = method.GetParameters();
                                if (parameters.Length <= 1)
                                {
                                    if (parameters.Length == 1)
                                    {
                                        System.Type 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))
                                        {
                                            supportedMethodsParameter.Add(parameterType);
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        supportedMethodsParameter.Add((System.Type)null);
                                    }
                                    if (supportedMethods.Contains(name))
                                    {
                                        stringSet.Add(name);
                                    }
                                    supportedMethods.Add(name);
                                }
                            }
                        }
                    }
                }
            }
            using (HashSet <string> .Enumerator enumerator = stringSet.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    for (int index = 0; index < supportedMethods.Count; ++index)
                    {
                        if (supportedMethods[index].Equals(current))
                        {
                            supportedMethods.RemoveAt(index);
                            supportedMethodsParameter.RemoveAt(index);
                            --index;
                        }
                    }
                }
            }
        }