예제 #1
0
        private static AttributeHelper.MonoCreateAssetItem[] ExtractCreateAssetMenuItems(Assembly assembly)
        {
            List <AttributeHelper.MonoCreateAssetItem> monoCreateAssetItemList = new List <AttributeHelper.MonoCreateAssetItem>();

            foreach (System.Type type in AssemblyHelper.GetTypesFromAssembly(assembly))
            {
                CreateAssetMenuAttribute customAttribute = (CreateAssetMenuAttribute)Attribute.GetCustomAttribute((MemberInfo)type, typeof(CreateAssetMenuAttribute));
                if (customAttribute != null)
                {
                    if (!type.IsSubclassOf(typeof(ScriptableObject)))
                    {
                        UnityEngine.Debug.LogWarningFormat("CreateAssetMenu attribute on {0} will be ignored as {0} is not derived from ScriptableObject.", (object)type.FullName);
                    }
                    else
                    {
                        string str  = !string.IsNullOrEmpty(customAttribute.menuName) ? customAttribute.menuName : ObjectNames.NicifyVariableName(type.Name);
                        string path = !string.IsNullOrEmpty(customAttribute.fileName) ? customAttribute.fileName : "New " + ObjectNames.NicifyVariableName(type.Name) + ".asset";
                        if (!Path.HasExtension(path))
                        {
                            path += ".asset";
                        }
                        monoCreateAssetItemList.Add(new AttributeHelper.MonoCreateAssetItem()
                        {
                            menuItem = str,
                            fileName = path,
                            order    = customAttribute.order,
                            type     = type
                        });
                    }
                }
            }
            return(monoCreateAssetItemList.ToArray());
        }
예제 #2
0
 private static void Testing_Invoke(string klass, string method, params object[] prms)
 {
     try
     {
         foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
         {
             if ((assembly.GetName().Name != "UnityEditor") && (assembly.GetName().Name != "UnityEngine"))
             {
                 foreach (System.Type type in AssemblyHelper.GetTypesFromAssembly(assembly))
                 {
                     if (type.Name == klass)
                     {
                         type.InvokeMember(method, BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, null, prms);
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         if ((exception.InnerException != null) && (exception.InnerException.GetType() == typeof(ExitGUIException)))
         {
             throw exception;
         }
         object[] objArray1 = new object[] { exception };
         Testing_Invoke(AssetServer.GetString("s_ExceptionHandlerClass"), AssetServer.GetString("s_ExceptionHandlerFunction"), objArray1);
     }
 }
예제 #3
0
 private void AddCustomSections()
 {
     Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
     for (int i = 0; i < loadedAssemblies.Length; i++)
     {
         Assembly assembly          = loadedAssemblies[i];
         Type[]   typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
         Type[]   array             = typesFromAssembly;
         for (int j = 0; j < array.Length; j++)
         {
             Type         type    = array[j];
             MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
             for (int k = 0; k < methods.Length; k++)
             {
                 MethodInfo     methodInfo     = methods[k];
                 PreferenceItem preferenceItem = Attribute.GetCustomAttribute(methodInfo, typeof(PreferenceItem)) as PreferenceItem;
                 if (preferenceItem != null)
                 {
                     PreferencesWindow.OnGUIDelegate onGUIDelegate = Delegate.CreateDelegate(typeof(PreferencesWindow.OnGUIDelegate), methodInfo) as PreferencesWindow.OnGUIDelegate;
                     if (onGUIDelegate != null)
                     {
                         this.m_Sections.Add(new PreferencesWindow.Section(preferenceItem.name, onGUIDelegate));
                     }
                 }
             }
         }
     }
 }
예제 #4
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());
        }
예제 #5
0
 internal static void Rebuild(Assembly assembly)
 {
     foreach (System.Type type in AssemblyHelper.GetTypesFromAssembly(assembly))
     {
         foreach (CustomEditor customAttribute in type.GetCustomAttributes(typeof(CustomEditor), false))
         {
             CustomEditorAttributes.MonoEditorType monoEditorType = new CustomEditorAttributes.MonoEditorType();
             if (customAttribute.m_InspectedType == null)
             {
                 Debug.Log((object)("Can't load custom inspector " + type.Name + " because the inspected type is null."));
             }
             else if (!type.IsSubclassOf(typeof(Editor)))
             {
                 if (!(type.FullName == "TweakMode") || !type.IsEnum || !(customAttribute.m_InspectedType.FullName == "BloomAndFlares"))
                 {
                     Debug.LogWarning((object)(type.Name + " uses the CustomEditor attribute but does not inherit from Editor.\nYou must inherit from Editor. See the Editor class script documentation."));
                 }
             }
             else
             {
                 monoEditorType.m_InspectedType         = customAttribute.m_InspectedType;
                 monoEditorType.m_InspectorType         = type;
                 monoEditorType.m_EditorForChildClasses = customAttribute.m_EditorForChildClasses;
                 monoEditorType.m_IsFallback            = customAttribute.isFallback;
                 CustomEditorAttributes.kSCustomEditors.Add(monoEditorType);
                 if (type.GetCustomAttributes(typeof(CanEditMultipleObjects), false).Length > 0)
                 {
                     CustomEditorAttributes.kSCustomMultiEditors.Add(monoEditorType);
                 }
             }
         }
     }
 }
        internal static IEnumerable <T> FindImplementors <T>(Assembly assembly) where T : class
        {
            Type interfaze = typeof(T);

            foreach (Type type in AssemblyHelper.GetTypesFromAssembly(assembly))
            {
                if (/*type.IsNotPublic - future! ||*/ type.IsInterface || type.IsAbstract || !interfaze.IsAssignableFrom(type))
                {
                    continue;
                }
                T module = null;

                if (typeof(ScriptableObject).IsAssignableFrom(type))
                {
                    module = ScriptableObject.CreateInstance(type) as T;
                }
                else
                {
                    module = Activator.CreateInstance(type) as T;
                }
                if (module != null)
                {
                    yield return(module);
                }
            }
        }
예제 #7
0
 internal static void Rebuild(Assembly assembly)
 {
     System.Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
     foreach (System.Type type in typesFromAssembly)
     {
         object[] customAttributes = type.GetCustomAttributes(typeof(CustomEditor), false);
         foreach (CustomEditor editor in customAttributes)
         {
             MonoEditorType item = new MonoEditorType();
             if (editor.m_InspectedType == null)
             {
                 Debug.Log("Can't load custom inspector " + type.Name + " because the inspected type is null.");
             }
             else if (!type.IsSubclassOf(typeof(Editor)))
             {
                 if (((type.FullName != "TweakMode") || !type.IsEnum) || (editor.m_InspectedType.FullName != "BloomAndFlares"))
                 {
                     Debug.LogWarning(type.Name + " uses the CustomEditor attribute but does not inherit from Editor.\nYou must inherit from Editor. See the Editor class script documentation.");
                 }
             }
             else
             {
                 item.m_InspectedType         = editor.m_InspectedType;
                 item.m_InspectorType         = type;
                 item.m_EditorForChildClasses = editor.m_EditorForChildClasses;
                 item.m_IsFallback            = editor.isFallback;
                 kSCustomEditors.Add(item);
                 if (type.GetCustomAttributes(typeof(CanEditMultipleObjects), false).Length > 0)
                 {
                     kSCustomMultiEditors.Add(item);
                 }
             }
         }
     }
 }
예제 #8
0
 private static void Testing_Invoke(string klass, string method, params object[] prms)
 {
     try
     {
         AppDomain  currentDomain = AppDomain.CurrentDomain;
         Assembly[] assemblies    = currentDomain.GetAssemblies();
         for (int i = 0; i < assemblies.Length; i++)
         {
             Assembly assembly = assemblies[i];
             if (assembly.GetName().Name != "UnityEditor" && assembly.GetName().Name != "UnityEngine")
             {
                 Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
                 for (int j = 0; j < typesFromAssembly.Length; j++)
                 {
                     Type type = typesFromAssembly[j];
                     if (type.Name == klass)
                     {
                         type.InvokeMember(method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, prms);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null && ex.InnerException.GetType() == typeof(ExitGUIException))
         {
             throw ex;
         }
         ASEditorBackend.Testing_Invoke(AssetServer.GetString("s_ExceptionHandlerClass"), AssetServer.GetString("s_ExceptionHandlerFunction"), new object[]
         {
             ex
         });
     }
 }
예제 #9
0
        private static MonoCreateAssetItem[] ExtractCreateAssetMenuItems(Assembly assembly)
        {
            List <MonoCreateAssetItem> list = new List <MonoCreateAssetItem>();

            System.Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
            foreach (System.Type type in typesFromAssembly)
            {
                CreateAssetMenuAttribute customAttribute = (CreateAssetMenuAttribute)Attribute.GetCustomAttribute(type, typeof(CreateAssetMenuAttribute));
                if (customAttribute != null)
                {
                    if (!type.IsSubclassOf(typeof(ScriptableObject)))
                    {
                        object[] args = new object[] { type.FullName };
                        UnityEngine.Debug.LogWarningFormat("CreateAssetMenu attribute on {0} will be ignored as {0} is not derived from ScriptableObject.", args);
                    }
                    else
                    {
                        string str  = !string.IsNullOrEmpty(customAttribute.menuName) ? customAttribute.menuName : ObjectNames.NicifyVariableName(type.Name);
                        string path = !string.IsNullOrEmpty(customAttribute.fileName) ? customAttribute.fileName : ("New " + ObjectNames.NicifyVariableName(type.Name) + ".asset");
                        if (!Path.HasExtension(path))
                        {
                            path = path + ".asset";
                        }
                        MonoCreateAssetItem item = new MonoCreateAssetItem {
                            menuItem = str,
                            fileName = path,
                            order    = customAttribute.order,
                            type     = type
                        };
                        list.Add(item);
                    }
                }
            }
            return(list.ToArray());
        }
예제 #10
0
        internal static ShaderGUI CreateShaderGUI(string customEditorName)
        {
            string value = "UnityEditor." + customEditorName;

            Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
            for (int i = loadedAssemblies.Length - 1; i >= 0; i--)
            {
                Assembly assembly          = loadedAssemblies[i];
                Type[]   typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
                Type[]   array             = typesFromAssembly;
                int      j = 0;
                while (j < array.Length)
                {
                    Type type = array[j];
                    if (type.FullName.Equals(customEditorName, StringComparison.Ordinal) || type.FullName.Equals(value, StringComparison.Ordinal))
                    {
                        if (typeof(ShaderGUI).IsAssignableFrom(type))
                        {
                            return(Activator.CreateInstance(type) as ShaderGUI);
                        }
                        return(null);
                    }
                    else
                    {
                        j++;
                    }
                }
            }
            return(null);
        }
예제 #11
0
        private static Type ExtractCustomEditorType(string customEditorName)
        {
            Type result;

            if (string.IsNullOrEmpty(customEditorName))
            {
                result = null;
            }
            else
            {
                string     value            = "UnityEditor." + customEditorName;
                Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
                for (int i = loadedAssemblies.Length - 1; i >= 0; i--)
                {
                    Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(loadedAssemblies[i]);
                    for (int j = 0; j < typesFromAssembly.Length; j++)
                    {
                        Type type = typesFromAssembly[j];
                        if (type.FullName.Equals(customEditorName, StringComparison.Ordinal) || type.FullName.Equals(value, StringComparison.Ordinal))
                        {
                            result = ((!typeof(ShaderGUI).IsAssignableFrom(type)) ? null : type);
                            return(result);
                        }
                    }
                }
                result = null;
            }
            return(result);
        }
예제 #12
0
        private static Type ExtractCustomEditorType(string customEditorName)
        {
            if (string.IsNullOrEmpty(customEditorName))
            {
                return(null);
            }

            // To allow users to implement their own ShaderGUI for the Standard shader we iterate in reverse order
            // because the UnityEditor assembly is assumed first in the assembly list.
            // Users can now place a copy of the StandardShaderGUI script in the project and start modifying that copy to make their own version.

            string unityEditorFullName = "UnityEditor." + customEditorName; // for convenience: adding UnityEditor namespace is not needed in the shader

            var editorAssemblies = EditorAssemblies.loadedAssemblies;

            for (int i = editorAssemblies.Length - 1; i >= 0; i--)
            {
                foreach (var type in AssemblyHelper.GetTypesFromAssembly(editorAssemblies[i]))
                {
                    if (type.FullName.Equals(customEditorName, StringComparison.Ordinal) || type.FullName.Equals(unityEditorFullName, StringComparison.Ordinal))
                    {
                        return(typeof(ShaderGUI).IsAssignableFrom(type) ? type : null);
                    }
                }
            }
            return(null);
        }
예제 #13
0
 private static void Testing_Invoke(string klass, string method, params object[] prms)
 {
     try
     {
         foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
         {
             if (assembly.GetName().Name != "UnityEditor" && assembly.GetName().Name != "UnityEngine")
             {
                 foreach (System.Type type in AssemblyHelper.GetTypesFromAssembly(assembly))
                 {
                     if (type.Name == klass)
                     {
                         type.InvokeMember(method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, (Binder)null, (object)null, prms);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null && ex.InnerException.GetType() == typeof(ExitGUIException))
         {
             throw ex;
         }
         ASEditorBackend.Testing_Invoke(AssetServer.GetString("s_ExceptionHandlerClass"), AssetServer.GetString("s_ExceptionHandlerFunction"), (object)ex);
     }
 }
예제 #14
0
        private static AttributeHelper.MonoMenuItem[] ExtractMenuCommands(Assembly assembly)
        {
            bool @bool = EditorPrefs.GetBool("InternalMode", false);
            Dictionary <string, AttributeHelper.MonoMenuItem> dictionary = new Dictionary <string, AttributeHelper.MonoMenuItem>();

            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(MenuItem), false);
                    object[]   array2           = customAttributes;
                    int        k = 0;
                    while (k < array2.Length)
                    {
                        MenuItem menuItem = (MenuItem)array2[k];
                        AttributeHelper.MonoMenuItem value = (!dictionary.ContainsKey(menuItem.menuItem)) ? default(AttributeHelper.MonoMenuItem) : dictionary[menuItem.menuItem];
                        if (!menuItem.menuItem.StartsWith("internal:", StringComparison.Ordinal))
                        {
                            value.menuItem = menuItem.menuItem;
                            goto IL_E9;
                        }
                        if (@bool)
                        {
                            value.menuItem = menuItem.menuItem.Substring(9);
                            goto IL_E9;
                        }
IL_144:
                        k++;
                        continue;
IL_E9:
                        value.type = type;
                        if (menuItem.validate)
                        {
                            value.validate = methodInfo.Name;
                        }
                        else
                        {
                            value.execute  = methodInfo.Name;
                            value.index    = j;
                            value.priority = menuItem.priority;
                        }
                        dictionary[menuItem.menuItem] = value;
                        goto IL_144;
                    }
                }
            }
            AttributeHelper.MonoMenuItem[] array3 = dictionary.Values.ToArray <AttributeHelper.MonoMenuItem>();
            Array.Sort(array3, new AttributeHelper.CompareMenuIndex());
            return(array3);
        }
예제 #15
0
        private static int[] ProcessInitializeOnLoadAttributes()
        {
            List <int> list = null;

            Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
            EditorAssemblies.m_TotalNumRuntimeInitializeMethods = 0;
            EditorAssemblies.m_RuntimeInitializeClassInfoList   = new List <RuntimeInitializeClassInfo>();
            for (int i = 0; i < loadedAssemblies.Length; i++)
            {
                int totalNumRuntimeInitializeMethods = EditorAssemblies.m_TotalNumRuntimeInitializeMethods;
                int count = EditorAssemblies.m_RuntimeInitializeClassInfoList.Count;
                try
                {
                    Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(loadedAssemblies[i]);
                    Type[] array             = typesFromAssembly;
                    for (int j = 0; j < array.Length; j++)
                    {
                        Type type = array[j];
                        if (type.IsDefined(typeof(InitializeOnLoadAttribute), false))
                        {
                            EditorAssemblies.ProcessEditorInitializeOnLoad(type);
                        }
                        EditorAssemblies.ProcessStaticMethodAttributes(type);
                    }
                }
                catch (Exception exception)
                {
                    Debug.LogException(exception);
                    if (list == null)
                    {
                        list = new List <int>();
                    }
                    if (totalNumRuntimeInitializeMethods != EditorAssemblies.m_TotalNumRuntimeInitializeMethods)
                    {
                        EditorAssemblies.m_TotalNumRuntimeInitializeMethods = totalNumRuntimeInitializeMethods;
                    }
                    if (count != EditorAssemblies.m_RuntimeInitializeClassInfoList.Count)
                    {
                        EditorAssemblies.m_RuntimeInitializeClassInfoList.RemoveRange(count, EditorAssemblies.m_RuntimeInitializeClassInfoList.Count - count);
                    }
                    list.Add(i);
                }
            }
            int[] result;
            if (list == null)
            {
                result = null;
            }
            else
            {
                result = list.ToArray();
            }
            return(result);
        }
예제 #16
0
        private static MonoGizmoMethod[] ExtractGizmos(Assembly assembly)
        {
            List <MonoGizmoMethod> list = new List <MonoGizmoMethod>();

            System.Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
            foreach (System.Type type in typesFromAssembly)
            {
                MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
                for (int i = 0; i < methods.GetLength(0); i++)
                {
                    MethodInfo info             = methods[i];
                    object[]   customAttributes = info.GetCustomAttributes(typeof(DrawGizmo), false);
                    foreach (DrawGizmo gizmo in customAttributes)
                    {
                        System.Reflection.ParameterInfo[] parameters = info.GetParameters();
                        if (parameters.Length != 2)
                        {
                            UnityEngine.Debug.LogWarning($"Method {info.DeclaringType.FullName}.{info.Name} is marked with the DrawGizmo attribute but does not take parameters (ComponentType, GizmoType) so will be ignored.");
                        }
                        else
                        {
                            MonoGizmoMethod item = new MonoGizmoMethod();
                            if (gizmo.drawnType == null)
                            {
                                item.drawnType = parameters[0].ParameterType;
                            }
                            else if (parameters[0].ParameterType.IsAssignableFrom(gizmo.drawnType))
                            {
                                item.drawnType = gizmo.drawnType;
                            }
                            else
                            {
                                UnityEngine.Debug.LogWarning($"Method {info.DeclaringType.FullName}.{info.Name} is marked with the DrawGizmo attribute but the component type it applies to could not be determined.");
                                goto Label_0198;
                            }
                            if ((parameters[1].ParameterType != typeof(GizmoType)) && (parameters[1].ParameterType != typeof(int)))
                            {
                                UnityEngine.Debug.LogWarning($"Method {info.DeclaringType.FullName}.{info.Name} is marked with the DrawGizmo attribute but does not take a second parameter of type GizmoType so will be ignored.");
                            }
                            else
                            {
                                item.drawGizmo = info;
                                item.options   = (int)gizmo.drawOptions;
                                list.Add(item);
                            }
                            Label_0198 :;
                        }
                    }
                }
            }
            return(list.ToArray());
        }
예제 #17
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());
        }
예제 #18
0
        private static AttributeHelper.MonoMenuItem[] ExtractMenuCommands(Assembly assembly)
        {
            bool flag = EditorPrefs.GetBool("InternalMode", false);
            Dictionary <string, AttributeHelper.MonoMenuItem> dictionary = new Dictionary <string, AttributeHelper.MonoMenuItem>();

            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 (MenuItem customAttribute in methodInfo.GetCustomAttributes(typeof(MenuItem), false))
                    {
                        AttributeHelper.MonoMenuItem monoMenuItem = !dictionary.ContainsKey(customAttribute.menuItem) ? new AttributeHelper.MonoMenuItem() : dictionary[customAttribute.menuItem];
                        if (customAttribute.menuItem.StartsWith("internal:", StringComparison.Ordinal))
                        {
                            if (flag)
                            {
                                monoMenuItem.menuItem = customAttribute.menuItem.Substring(9);
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            monoMenuItem.menuItem = customAttribute.menuItem;
                        }
                        monoMenuItem.type = type;
                        if (customAttribute.validate)
                        {
                            monoMenuItem.validate = methodInfo.Name;
                        }
                        else
                        {
                            monoMenuItem.execute  = methodInfo.Name;
                            monoMenuItem.index    = index;
                            monoMenuItem.priority = customAttribute.priority;
                        }
                        dictionary[customAttribute.menuItem] = monoMenuItem;
                    }
                }
            }
            AttributeHelper.MonoMenuItem[] array = dictionary.Values.ToArray <AttributeHelper.MonoMenuItem>();
            Array.Sort((Array)array, (IComparer) new AttributeHelper.CompareMenuIndex());
            return(array);
        }
예제 #19
0
        internal static void Rebuild(Assembly assembly)
        {
            Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
            Type[] array             = typesFromAssembly;
            for (int i = 0; i < array.Length; i++)
            {
                Type     type             = array[i];
                object[] customAttributes = type.GetCustomAttributes(typeof(CustomEditor), false);
                object[] array2           = customAttributes;
                int      j = 0;
                while (j < array2.Length)
                {
                    CustomEditor customEditor = (CustomEditor)array2[j];
                    CustomEditorAttributes.MonoEditorType monoEditorType = new CustomEditorAttributes.MonoEditorType();
                    if (customEditor.m_InspectedType == null)
                    {
                        Debug.Log("Can't load custom inspector " + type.Name + " because the inspected type is null.");
                    }
                    else if (!type.IsSubclassOf(typeof(Editor)))
                    {
                        if (!(type.FullName == "TweakMode") || !type.IsEnum || !(customEditor.m_InspectedType.FullName == "BloomAndFlares"))
                        {
                            Debug.LogWarning(type.Name + " uses the CustomEditor attribute but does not inherit from Editor.\nYou must inherit from Editor. See the Editor class script documentation.");
                        }
                    }
                    else
                    {
                        monoEditorType.m_InspectedType         = customEditor.m_InspectedType;
                        monoEditorType.m_InspectorType         = type;
                        monoEditorType.m_EditorForChildClasses = customEditor.m_EditorForChildClasses;
                        monoEditorType.m_IsFallback            = customEditor.isFallback;
                        CustomEditorAttributes.kSCustomEditors.Add(monoEditorType);
                        if (type.GetCustomAttributes(typeof(CanEditMultipleObjects), false).Length > 0)
                        {
                            CustomEditorAttributes.kSCustomMultiEditors.Add(monoEditorType);
                        }
                    }
IL_14D:
                    j++;
                    continue;
                    goto IL_14D;
                }
            }
        }
예제 #20
0
        internal static ShaderGUI CreateShaderGUI(string customEditorName)
        {
            string str = "UnityEditor." + customEditorName;

            Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies;
            for (int index = loadedAssemblies.Length - 1; index >= 0; --index)
            {
                foreach (System.Type type in AssemblyHelper.GetTypesFromAssembly(loadedAssemblies[index]))
                {
                    if (type.FullName.Equals(customEditorName, StringComparison.Ordinal) || type.FullName.Equals(str, StringComparison.Ordinal))
                    {
                        if (typeof(ShaderGUI).IsAssignableFrom(type))
                        {
                            return(Activator.CreateInstance(type) as ShaderGUI);
                        }
                        return((ShaderGUI)null);
                    }
                }
            }
            return((ShaderGUI)null);
        }
예제 #21
0
        private static AttributeHelper.MonoCreateAssetItem[] ExtractCreateAssetMenuItems(Assembly assembly)
        {
            List <AttributeHelper.MonoCreateAssetItem> list = new List <AttributeHelper.MonoCreateAssetItem>();

            Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
            Type[] array             = typesFromAssembly;
            for (int i = 0; i < array.Length; i++)
            {
                Type type = array[i];
                CreateAssetMenuAttribute createAssetMenuAttribute = (CreateAssetMenuAttribute)Attribute.GetCustomAttribute(type, typeof(CreateAssetMenuAttribute));
                if (createAssetMenuAttribute != null)
                {
                    if (!type.IsSubclassOf(typeof(ScriptableObject)))
                    {
                        UnityEngine.Debug.LogWarningFormat("CreateAssetMenu attribute on {0} will be ignored as {0} is not derived from ScriptableObject.", new object[]
                        {
                            type.FullName
                        });
                    }
                    else
                    {
                        string menuItem = (!string.IsNullOrEmpty(createAssetMenuAttribute.menuName)) ? createAssetMenuAttribute.menuName : ObjectNames.NicifyVariableName(type.Name);
                        string text     = (!string.IsNullOrEmpty(createAssetMenuAttribute.fileName)) ? createAssetMenuAttribute.fileName : ("New " + ObjectNames.NicifyVariableName(type.Name) + ".asset");
                        if (!Path.HasExtension(text))
                        {
                            text += ".asset";
                        }
                        list.Add(new AttributeHelper.MonoCreateAssetItem
                        {
                            menuItem = menuItem,
                            fileName = text,
                            order    = createAssetMenuAttribute.order,
                            type     = type
                        });
                    }
                }
            }
            return(list.ToArray());
        }
 private static void BuildDrawerTypeForTypeDictionary()
 {
     ScriptAttributeUtility.s_DrawerTypeForType = new Dictionary <System.Type, ScriptAttributeUtility.DrawerKeySet>();
     System.Type[] array = ((IEnumerable <Assembly>)AppDomain.CurrentDomain.GetAssemblies()).SelectMany <Assembly, System.Type>((Func <Assembly, IEnumerable <System.Type> >)(x => (IEnumerable <System.Type>)AssemblyHelper.GetTypesFromAssembly(x))).ToArray <System.Type>();
     foreach (System.Type type in EditorAssemblies.SubclassesOf(typeof(GUIDrawer)))
     {
         object[] customAttributes = type.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
         // ISSUE: object of a compiler-generated type is created
         // ISSUE: variable of a compiler-generated type
         ScriptAttributeUtility.\u003CBuildDrawerTypeForTypeDictionary\u003Ec__AnonStoreyB0 dictionaryCAnonStoreyB0 = new ScriptAttributeUtility.\u003CBuildDrawerTypeForTypeDictionary\u003Ec__AnonStoreyB0();
         foreach (CustomPropertyDrawer customPropertyDrawer in customAttributes)
         {
             // ISSUE: reference to a compiler-generated field
             dictionaryCAnonStoreyB0.editor = customPropertyDrawer;
             // ISSUE: reference to a compiler-generated field
             // ISSUE: reference to a compiler-generated field
             ScriptAttributeUtility.s_DrawerTypeForType[dictionaryCAnonStoreyB0.editor.m_Type] = new ScriptAttributeUtility.DrawerKeySet()
             {
                 drawer = type,
                 type   = dictionaryCAnonStoreyB0.editor.m_Type
             };
             // ISSUE: reference to a compiler-generated field
             if (dictionaryCAnonStoreyB0.editor.m_UseForChildren)
             {
                 // ISSUE: reference to a compiler-generated method
                 foreach (System.Type key in ((IEnumerable <System.Type>)array).Where <System.Type>(new Func <System.Type, bool>(dictionaryCAnonStoreyB0.\u003C\u003Em__1FB)))
                 {
                     // ISSUE: reference to a compiler-generated field
                     if (!ScriptAttributeUtility.s_DrawerTypeForType.ContainsKey(key) || !dictionaryCAnonStoreyB0.editor.m_Type.IsAssignableFrom(ScriptAttributeUtility.s_DrawerTypeForType[key].type))
                     {
                         // ISSUE: reference to a compiler-generated field
                         ScriptAttributeUtility.s_DrawerTypeForType[key] = new ScriptAttributeUtility.DrawerKeySet()
                         {
                             drawer = type,
                             type   = dictionaryCAnonStoreyB0.editor.m_Type
                         };
                     }
                 }
             }
         }
     }
 }
        // Single argument: enum type name; entry names & values fetched via reflection
        public MaterialEnumDrawer(string enumName)
        {
            var loadedTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => AssemblyHelper.GetTypesFromAssembly(x)).ToArray();

            try
            {
                var enumType = loadedTypes.FirstOrDefault(
                    x => x.IsSubclassOf(typeof(Enum)) && (x.Name == enumName || x.FullName == enumName)
                    );
                var enumNames = Enum.GetNames(enumType);
                this.names = new GUIContent[enumNames.Length];
                for (int i = 0; i < enumNames.Length; ++i)
                {
                    this.names[i] = new GUIContent(enumNames[i]);
                }

                var enumVals = Enum.GetValues(enumType);
                values = new float[enumVals.Length];
                for (var i = 0; i < enumVals.Length; ++i)
                {
                    values[i] = (int)enumVals.GetValue(i);
                }
            }
            catch (Exception)
            {
                Debug.LogWarningFormat("Failed to create MaterialEnum, enum {0} not found", enumName);
                throw;
            }
        }
예제 #24
0
        private static MonoMenuItem[] ExtractMenuCommands(Assembly assembly, bool modifiedSinceLastReload)
        {
            BindingFlags bindingAttr = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;

            if (modifiedSinceLastReload)
            {
                bindingAttr |= BindingFlags.Instance;
            }
            bool @bool = EditorPrefs.GetBool("InternalMode", false);
            Dictionary <string, MonoMenuItem> dictionary = new Dictionary <string, MonoMenuItem>();

            System.Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly);
            foreach (System.Type type in typesFromAssembly)
            {
                MethodInfo[] methods = type.GetMethods(bindingAttr);
                for (int i = 0; i < methods.GetLength(0); i++)
                {
                    MethodInfo mi = methods[i];
                    object[]   customAttributes = mi.GetCustomAttributes(typeof(UnityEditor.MenuItem), false);
                    if ((customAttributes.Length > 0) && type.IsGenericTypeDefinition)
                    {
                        object[] args = new object[] { type.Name, mi.Name };
                        UnityEngine.Debug.LogWarningFormat("Method {0}.{1} cannot be used for menu commands because class {0} is an open generic type.", args);
                    }
                    else
                    {
                        foreach (UnityEditor.MenuItem item in customAttributes)
                        {
                            MonoMenuItem item2 = !dictionary.ContainsKey(item.menuItem) ? new MonoMenuItem() : dictionary[item.menuItem];
                            if (!ValidateMethodForMenuCommand(mi, false))
                            {
                                break;
                            }
                            if (item.menuItem.StartsWith("internal:", StringComparison.Ordinal))
                            {
                                if (!@bool)
                                {
                                    continue;
                                }
                                item2.menuItem = item.menuItem.Substring(9);
                            }
                            else
                            {
                                item2.menuItem = item.menuItem;
                            }
                            if (item.validate)
                            {
                                item2.validateType   = type;
                                item2.validateMethod = mi;
                                item2.validateName   = mi.Name;
                            }
                            else
                            {
                                item2.index         = i;
                                item2.priority      = item.priority;
                                item2.executeType   = type;
                                item2.executeMethod = mi;
                                item2.executeName   = mi.Name;
                            }
                            dictionary[item.menuItem] = item2;
                        }
                    }
                }
            }
            MonoMenuItem[] array = dictionary.Values.ToArray <MonoMenuItem>();
            Array.Sort(array, new CompareMenuIndex());
            return(array);
        }
예제 #25
0
        // 用来搜索Assembly中的,
        // 所有类的[CustomEditor]和[CanEditMultipleObjects]标签,标记情况
        internal static void Rebuild(Assembly assembly)
        {
            // 获取Assembly中全部类型
            Type[] types = AssemblyHelper.GetTypesFromAssembly(assembly);
            foreach (var type in types)
            {
                // 获取CustomEditor标签
                // false参数:不搜索父亲链
                object[] attrs = type.GetCustomAttributes(typeof(CustomEditor), false);

                // Q: 一个类可以有多个CustomEditor?
                // 是可以有的,应该是多个inspectedType,可以拥有相同的界面代码
                foreach (CustomEditor inspectAttr in  attrs)
                {
                    // CustomEditor的数据存储
                    var t = new MonoEditorType();

                    // 检查CustomEditor标签参数
                    if (inspectAttr.m_InspectedType == null)
                    {
                        Debug.Log("Can't load custom inspector " + type.Name + " because the inspected type is null.");
                    }

                    // 检查CustomEditor挂载的类,是Editor
                    else if (!type.IsSubclassOf(typeof(Editor)))
                    {
                        // Q: 特殊处理TweakMode?
                        // Suppress a warning on TweakMode, we did this bad in the default project folder
                        // and it's going to be too hard for customers to figure out how to fix it and also quite pointless.
                        if (type.FullName == "TweakMode" &&
                            type.IsEnum &&
                            inspectAttr.m_InspectedType.FullName == "BloomAndFlares")
                        {
                            continue;
                        }

                        Debug.LogWarning(
                            type.Name +
                            " uses the CustomEditor attribute but does not inherit from Editor.\nYou must inherit from Editor. See the Editor class script documentation.");
                    }
                    else
                    {
                        // 将CustomEditor标记的参数,
                        // 存储到MonoEditorType结构中
                        t.m_InspectedType         = inspectAttr.m_InspectedType;
                        t.m_InspectorType         = type;
                        t.m_EditorForChildClasses = inspectAttr.m_EditorForChildClasses;
                        // Q: CustomEditor.isFallback的含义?
                        t.m_IsFallback = inspectAttr.isFallback;

                        // 特殊存储CustomEditorForRenderPipelineAttribute的参数
                        // Q: CustomEditorForRenderPipelineAttribute,根据RenderPipeline来改变显示的标签
                        var attr = inspectAttr as CustomEditorForRenderPipelineAttribute;
                        if (attr != null)
                        {
                            t.m_RenderPipelineType = attr.renderPipelineType;
                        }

                        List <MonoEditorType> editors;

                        // 确保dic中,有inspectedType的 List<MonoEditorType>
                        if (!kSCustomEditors.TryGetValue(inspectAttr.m_InspectedType, out editors))
                        {
                            editors = new List <MonoEditorType>();
                            kSCustomEditors[inspectAttr.m_InspectedType] = editors;
                        }

                        // 将新的CustomEditor标签数据
                        // 加入到列表中
                        editors.Add(t);

                        // 检查是否有, [CanEditMultipleObjects]标签
                        if (type.GetCustomAttributes(typeof(CanEditMultipleObjects), false).Length > 0)
                        {
                            List <MonoEditorType> multiEditors;

                            // 确保有 List<MonoEditorType>
                            if (!kSCustomMultiEditors.TryGetValue(inspectAttr.m_InspectedType, out multiEditors))
                            {
                                multiEditors = new List <MonoEditorType>();
                                kSCustomMultiEditors[inspectAttr.m_InspectedType] = multiEditors;
                            }

                            // 加入到列表
                            multiEditors.Add(t);
                        }
                    }
                }
            }
        }
        internal static void Rebuild(Assembly assembly)
        {
            Type[] types = AssemblyHelper.GetTypesFromAssembly(assembly);
            foreach (var type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(CustomEditor), false);

                foreach (CustomEditor inspectAttr in  attrs)
                {
                    var t = new MonoEditorType();
                    if (inspectAttr.m_InspectedType == null)
                    {
                        Debug.Log("Can't load custom inspector " + type.Name + " because the inspected type is null.");
                    }
                    else if (!type.IsSubclassOf(typeof(Editor)))
                    {
                        // Suppress a warning on TweakMode, we did this bad in the default project folder
                        // and it's going to be too hard for customers to figure out how to fix it and also quite pointless.
                        if (type.FullName == "TweakMode" && type.IsEnum &&
                            inspectAttr.m_InspectedType.FullName == "BloomAndFlares")
                        {
                            continue;
                        }

                        Debug.LogWarning(
                            type.Name +
                            " uses the CustomEditor attribute but does not inherit from Editor.\nYou must inherit from Editor. See the Editor class script documentation.");
                    }
                    else
                    {
                        t.m_InspectedType         = inspectAttr.m_InspectedType;
                        t.m_InspectorType         = type;
                        t.m_EditorForChildClasses = inspectAttr.m_EditorForChildClasses;
                        t.m_IsFallback            = inspectAttr.isFallback;
                        var attr = inspectAttr as CustomEditorForRenderPipelineAttribute;
                        if (attr != null)
                        {
                            t.m_RenderPipelineType = attr.renderPipelineType;
                        }

                        List <MonoEditorType> editors;
                        if (!kSCustomEditors.TryGetValue(inspectAttr.m_InspectedType, out editors))
                        {
                            editors = new List <MonoEditorType>();
                            kSCustomEditors[inspectAttr.m_InspectedType] = editors;
                        }
                        editors.Add(t);

                        if (type.GetCustomAttributes(typeof(CanEditMultipleObjects), false).Length > 0)
                        {
                            List <MonoEditorType> multiEditors;
                            if (!kSCustomMultiEditors.TryGetValue(inspectAttr.m_InspectedType, out multiEditors))
                            {
                                multiEditors = new List <MonoEditorType>();
                                kSCustomMultiEditors[inspectAttr.m_InspectedType] = multiEditors;
                            }
                            multiEditors.Add(t);
                        }
                    }
                }
            }
        }
예제 #27
0
        // Called on demand
        private static void BuildDrawerTypeForTypeDictionary()
        {
            s_DrawerTypeForType = new Dictionary <Type, DrawerKeySet>();

            var loadedTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => AssemblyHelper.GetTypesFromAssembly(x)).ToArray();

            foreach (var type in EditorAssemblies.SubclassesOf(typeof(GUIDrawer)))
            {
                //Debug.Log("Drawer: " + type);
                object[] attrs = type.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
                foreach (CustomPropertyDrawer editor in attrs)
                {
                    //Debug.Log("Base type: " + editor.type);
                    s_DrawerTypeForType[editor.m_Type] = new DrawerKeySet()
                    {
                        drawer = type,
                        type   = editor.m_Type
                    };

                    if (!editor.m_UseForChildren)
                    {
                        continue;
                    }

                    var candidateTypes = loadedTypes.Where(x => x.IsSubclassOf(editor.m_Type));
                    foreach (var candidateType in candidateTypes)
                    {
                        //Debug.Log("Candidate Type: "+ candidateType);
                        if (s_DrawerTypeForType.ContainsKey(candidateType) &&
                            (editor.m_Type.IsAssignableFrom(s_DrawerTypeForType[candidateType].type)))
                        {
                            //  Debug.Log("skipping");
                            continue;
                        }

                        //Debug.Log("Setting");
                        s_DrawerTypeForType[candidateType] = new DrawerKeySet()
                        {
                            drawer = type,
                            type   = editor.m_Type
                        };
                    }
                }
            }
        }
예제 #28
0
        private static AttributeHelper.MonoMenuItem[] ExtractMenuCommands(Assembly assembly, bool modifiedSinceLastReload)
        {
            BindingFlags bindingFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

            if (modifiedSinceLastReload)
            {
                bindingFlags |= BindingFlags.Instance;
            }
            bool @bool = EditorPrefs.GetBool("InternalMode", false);
            Dictionary <string, AttributeHelper.MonoMenuItem> dictionary = new Dictionary <string, AttributeHelper.MonoMenuItem>();

            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);
                for (int j = 0; j < methods.GetLength(0); j++)
                {
                    MethodInfo methodInfo       = methods[j];
                    object[]   customAttributes = methodInfo.GetCustomAttributes(typeof(MenuItem), false);
                    if (customAttributes.Length > 0 && type.IsGenericTypeDefinition)
                    {
                        UnityEngine.Debug.LogWarningFormat("Method {0}.{1} cannot be used for menu commands because class {0} is an open generic type.", new object[]
                        {
                            type.Name,
                            methodInfo.Name
                        });
                    }
                    else
                    {
                        object[] array2 = customAttributes;
                        int      k      = 0;
                        while (k < array2.Length)
                        {
                            MenuItem menuItem = (MenuItem)array2[k];
                            AttributeHelper.MonoMenuItem value = (!dictionary.ContainsKey(menuItem.menuItem)) ? default(AttributeHelper.MonoMenuItem) : dictionary[menuItem.menuItem];
                            if (!AttributeHelper.ValidateMethodForMenuCommand(methodInfo, false))
                            {
                                break;
                            }
                            if (!menuItem.menuItem.StartsWith("internal:", StringComparison.Ordinal))
                            {
                                value.menuItem = menuItem.menuItem;
                                goto IL_154;
                            }
                            if (@bool)
                            {
                                value.menuItem = menuItem.menuItem.Substring(9);
                                goto IL_154;
                            }
IL_1D0:
                            k++;
                            continue;
IL_154:
                            if (menuItem.validate)
                            {
                                value.validateType   = type;
                                value.validateMethod = methodInfo;
                                value.validateName   = methodInfo.Name;
                            }
                            else
                            {
                                value.index         = j;
                                value.priority      = menuItem.priority;
                                value.executeType   = type;
                                value.executeMethod = methodInfo;
                                value.executeName   = methodInfo.Name;
                            }
                            dictionary[menuItem.menuItem] = value;
                            goto IL_1D0;
                        }
                    }
                }
            }
            AttributeHelper.MonoMenuItem[] array3 = dictionary.Values.ToArray <AttributeHelper.MonoMenuItem>();
            Array.Sort(array3, new AttributeHelper.CompareMenuIndex());
            return(array3);
        }
예제 #29
0
 private static void BuildDrawerTypeForTypeDictionary()
 {
     ScriptAttributeUtility.s_DrawerTypeForType = new Dictionary <Type, ScriptAttributeUtility.DrawerKeySet>();
     Type[] source = AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly x) => AssemblyHelper.GetTypesFromAssembly(x)).ToArray <Type>();
     foreach (Type current in EditorAssemblies.SubclassesOf(typeof(GUIDrawer)))
     {
         object[] customAttributes = current.GetCustomAttributes(typeof(CustomPropertyDrawer), true);
         object[] array            = customAttributes;
         for (int i = 0; i < array.Length; i++)
         {
             CustomPropertyDrawer editor = (CustomPropertyDrawer)array[i];
             ScriptAttributeUtility.s_DrawerTypeForType[editor.m_Type] = new ScriptAttributeUtility.DrawerKeySet
             {
                 drawer = current,
                 type   = editor.m_Type
             };
             if (editor.m_UseForChildren)
             {
                 IEnumerable <Type> enumerable = from x in source
                                                 where x.IsSubclassOf(editor.m_Type)
                                                 select x;
                 foreach (Type current2 in enumerable)
                 {
                     if (!ScriptAttributeUtility.s_DrawerTypeForType.ContainsKey(current2) || !editor.m_Type.IsAssignableFrom(ScriptAttributeUtility.s_DrawerTypeForType[current2].type))
                     {
                         ScriptAttributeUtility.s_DrawerTypeForType[current2] = new ScriptAttributeUtility.DrawerKeySet
                         {
                             drawer = current,
                             type   = editor.m_Type
                         };
                     }
                 }
             }
         }
     }
 }
예제 #30
0
 public MaterialEnumDrawer(string enumName)
 {
     Type[] source = AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly x) => AssemblyHelper.GetTypesFromAssembly(x)).ToArray <Type>();
     try
     {
         Type     enumType = source.FirstOrDefault((Type x) => x.IsSubclassOf(typeof(Enum)) && (x.Name == enumName || x.FullName == enumName));
         string[] array    = Enum.GetNames(enumType);
         this.names = new GUIContent[array.Length];
         for (int i = 0; i < array.Length; i++)
         {
             this.names[i] = new GUIContent(array[i]);
         }
         Array array2 = Enum.GetValues(enumType);
         this.values = new int[array2.Length];
         for (int j = 0; j < array2.Length; j++)
         {
             this.values[j] = (int)array2.GetValue(j);
         }
     }
     catch (Exception)
     {
         Debug.LogWarningFormat("Failed to create MaterialEnum, enum {0} not found", new object[]
         {
             enumName
         });
         throw;
     }
 }