Пример #1
0
        private static AttributeHelper.MonoGizmoMethod[] ExtractGizmos(Assembly assembly)
        {
            List <AttributeHelper.MonoGizmoMethod> list = new List <AttributeHelper.MonoGizmoMethod>();

            Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
            Type[] array             = typesFromAssembly;
            for (int i = 0; i < array.Length; i++)
            {
                Type         type    = array[i];
                MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                for (int j = 0; j < methods.GetLength(0); j++)
                {
                    MethodInfo methodInfo       = methods[j];
                    object[]   customAttributes = methodInfo.GetCustomAttributes(typeof(DrawGizmo), false);
                    object[]   array2           = customAttributes;
                    for (int k = 0; k < array2.Length; k++)
                    {
                        DrawGizmo       drawGizmo  = (DrawGizmo)array2[k];
                        ParameterInfo[] parameters = methodInfo.GetParameters();
                        if (parameters.Length != 2)
                        {
                            UnityEngine.Debug.LogWarning(string.Format("Method {0}.{1} is marked with the DrawGizmo attribute but does not take parameters (ComponentType, GizmoType) so will be ignored.", methodInfo.DeclaringType.FullName, methodInfo.Name));
                        }
                        else if (methodInfo.DeclaringType != null && methodInfo.DeclaringType.IsGenericTypeDefinition)
                        {
                            UnityEngine.Debug.LogWarning(string.Format("Method {0}.{1} is marked with the DrawGizmo attribute but is defined on a generic type definition, so will be ignored.", methodInfo.DeclaringType.FullName, methodInfo.Name));
                        }
                        else
                        {
                            AttributeHelper.MonoGizmoMethod item = default(AttributeHelper.MonoGizmoMethod);
                            if (drawGizmo.drawnType == null)
                            {
                                item.drawnType = parameters[0].ParameterType;
                            }
                            else
                            {
                                if (!parameters[0].ParameterType.IsAssignableFrom(drawGizmo.drawnType))
                                {
                                    UnityEngine.Debug.LogWarning(string.Format("Method {0}.{1} is marked with the DrawGizmo attribute but the component type it applies to could not be determined.", methodInfo.DeclaringType.FullName, methodInfo.Name));
                                    goto IL_1DD;
                                }
                                item.drawnType = drawGizmo.drawnType;
                            }
                            if (parameters[1].ParameterType != typeof(GizmoType) && parameters[1].ParameterType != typeof(int))
                            {
                                UnityEngine.Debug.LogWarning(string.Format("Method {0}.{1} is marked with the DrawGizmo attribute but does not take a second parameter of type GizmoType so will be ignored.", methodInfo.DeclaringType.FullName, methodInfo.Name));
                            }
                            else
                            {
                                item.drawGizmo = methodInfo;
                                item.options   = (int)drawGizmo.drawOptions;
                                list.Add(item);
                            }
                        }
                        IL_1DD :;
                    }
                }
            }
            return(list.ToArray());
        }
Пример #2
0
        private static AttributeHelper.MonoGizmoMethod[] ExtractGizmos(Assembly assembly)
        {
            List <AttributeHelper.MonoGizmoMethod> monoGizmoMethodList = new List <AttributeHelper.MonoGizmoMethod>();

            foreach (System.Type type in AssemblyHelper.GetTypesFromAssembly(assembly))
            {
                MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                for (int index = 0; index < methods.GetLength(0); ++index)
                {
                    MethodInfo methodInfo = methods[index];
                    foreach (DrawGizmo customAttribute in methodInfo.GetCustomAttributes(typeof(DrawGizmo), false))
                    {
                        System.Reflection.ParameterInfo[] parameters = methodInfo.GetParameters();
                        if (parameters.Length != 2)
                        {
                            UnityEngine.Debug.LogWarning((object)string.Format("Method {0}.{1} is marked with the DrawGizmo attribute but does not take parameters (ComponentType, GizmoType) so will be ignored.", (object)methodInfo.DeclaringType.FullName, (object)methodInfo.Name));
                        }
                        else
                        {
                            AttributeHelper.MonoGizmoMethod monoGizmoMethod = new AttributeHelper.MonoGizmoMethod();
                            if (customAttribute.drawnType == null)
                            {
                                monoGizmoMethod.drawnType = parameters[0].ParameterType;
                            }
                            else if (parameters[0].ParameterType.IsAssignableFrom(customAttribute.drawnType))
                            {
                                monoGizmoMethod.drawnType = customAttribute.drawnType;
                            }
                            else
                            {
                                UnityEngine.Debug.LogWarning((object)string.Format("Method {0}.{1} is marked with the DrawGizmo attribute but the component type it applies to could not be determined.", (object)methodInfo.DeclaringType.FullName, (object)methodInfo.Name));
                                continue;
                            }
                            if (parameters[1].ParameterType != typeof(GizmoType) && parameters[1].ParameterType != typeof(int))
                            {
                                UnityEngine.Debug.LogWarning((object)string.Format("Method {0}.{1} is marked with the DrawGizmo attribute but does not take a second parameter of type GizmoType so will be ignored.", (object)methodInfo.DeclaringType.FullName, (object)methodInfo.Name));
                            }
                            else
                            {
                                monoGizmoMethod.drawGizmo = methodInfo;
                                monoGizmoMethod.options   = (int)customAttribute.drawOptions;
                                monoGizmoMethodList.Add(monoGizmoMethod);
                            }
                        }
                    }
                }
            }
            return(monoGizmoMethodList.ToArray());
        }
Пример #3
0
        private static AttributeHelper.MonoGizmoMethod[] ExtractGizmos(Assembly assembly)
        {
            List <AttributeHelper.MonoGizmoMethod> list = new List <AttributeHelper.MonoGizmoMethod>();

            foreach (MethodInfo current in from m in EditorAssemblies.GetAllMethodsWithAttribute <DrawGizmo>(BindingFlags.Static)
                     where m.DeclaringType.Assembly == assembly
                     select m)
            {
                IEnumerable <DrawGizmo> enumerable = current.GetCustomAttributes(typeof(DrawGizmo), false).Cast <DrawGizmo>();
                foreach (DrawGizmo current2 in enumerable)
                {
                    ParameterInfo[] parameters = current.GetParameters();
                    if (parameters.Length != 2)
                    {
                        UnityEngine.Debug.LogWarningFormat("Method {0}.{1} is marked with the DrawGizmo attribute but does not take parameters (ComponentType, GizmoType) so will be ignored.", new object[]
                        {
                            current.DeclaringType.FullName,
                            current.Name
                        });
                    }
                    else if (current.DeclaringType != null && current.DeclaringType.IsGenericTypeDefinition)
                    {
                        UnityEngine.Debug.LogWarningFormat("Method {0}.{1} is marked with the DrawGizmo attribute but is defined on a generic type definition, so will be ignored.", new object[]
                        {
                            current.DeclaringType.FullName,
                            current.Name
                        });
                    }
                    else
                    {
                        AttributeHelper.MonoGizmoMethod item = default(AttributeHelper.MonoGizmoMethod);
                        if (current2.drawnType == null)
                        {
                            item.drawnType = parameters[0].ParameterType;
                        }
                        else
                        {
                            if (!parameters[0].ParameterType.IsAssignableFrom(current2.drawnType))
                            {
                                UnityEngine.Debug.LogWarningFormat("Method {0}.{1} is marked with the DrawGizmo attribute but the component type it applies to could not be determined.", new object[]
                                {
                                    current.DeclaringType.FullName,
                                    current.Name
                                });
                                continue;
                            }
                            item.drawnType = current2.drawnType;
                        }
                        if (parameters[1].ParameterType != typeof(GizmoType) && parameters[1].ParameterType != typeof(int))
                        {
                            UnityEngine.Debug.LogWarningFormat("Method {0}.{1} is marked with the DrawGizmo attribute but does not take a second parameter of type GizmoType so will be ignored.", new object[]
                            {
                                current.DeclaringType.FullName,
                                current.Name
                            });
                        }
                        else
                        {
                            item.drawGizmo = current;
                            item.options   = (int)current2.drawOptions;
                            list.Add(item);
                        }
                    }
                }
            }
            return(list.ToArray());
        }