示例#1
0
 int IComparer.Compare(object xo, object yo)
 {
     AttributeHelper.MonoMenuItem monoMenuItem  = (AttributeHelper.MonoMenuItem)xo;
     AttributeHelper.MonoMenuItem monoMenuItem2 = (AttributeHelper.MonoMenuItem)yo;
     if (monoMenuItem.priority != monoMenuItem2.priority)
     {
         return(monoMenuItem.priority.CompareTo(monoMenuItem2.priority));
     }
     return(monoMenuItem.index.CompareTo(monoMenuItem2.index));
 }
示例#2
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);
        }
        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);
        }
        private static AttributeHelper.MonoMenuItem[] ExtractContextMenu(System.Type klass)
        {
            Dictionary <string, AttributeHelper.MonoMenuItem> dictionary = new Dictionary <string, AttributeHelper.MonoMenuItem>();

            MethodInfo[] methods = klass.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            for (int index = 0; index < methods.GetLength(0); ++index)
            {
                MethodInfo methodInfo = methods[index];
                foreach (ContextMenu customAttribute in methodInfo.GetCustomAttributes(typeof(ContextMenu), false))
                {
                    AttributeHelper.MonoMenuItem monoMenuItem = !dictionary.ContainsKey(customAttribute.menuItem) ? new AttributeHelper.MonoMenuItem() : dictionary[customAttribute.menuItem];
                    monoMenuItem.menuItem = customAttribute.menuItem;
                    monoMenuItem.type     = klass;
                    monoMenuItem.execute  = methodInfo.Name;
                    dictionary[customAttribute.menuItem] = monoMenuItem;
                }
            }
            return(dictionary.Values.ToArray <AttributeHelper.MonoMenuItem>());
        }
        private static AttributeHelper.MonoMenuItem[] ExtractContextMenu(Type type)
        {
            Dictionary <string, AttributeHelper.MonoMenuItem> dictionary = new Dictionary <string, AttributeHelper.MonoMenuItem>();

            MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            for (int i = 0; i < methods.GetLength(0); i++)
            {
                MethodInfo methodInfo       = methods[i];
                object[]   customAttributes = methodInfo.GetCustomAttributes(typeof(ContextMenu), false);
                object[]   array            = customAttributes;
                for (int j = 0; j < array.Length; j++)
                {
                    ContextMenu contextMenu            = (ContextMenu)array[j];
                    AttributeHelper.MonoMenuItem value = (!dictionary.ContainsKey(contextMenu.menuItem)) ? default(AttributeHelper.MonoMenuItem) : dictionary[contextMenu.menuItem];
                    if (!AttributeHelper.ValidateMethodForMenuCommand(methodInfo, true))
                    {
                        break;
                    }
                    value.menuItem = contextMenu.menuItem;
                    if (contextMenu.validate)
                    {
                        value.validateType   = type;
                        value.validateMethod = methodInfo;
                        value.validateName   = methodInfo.Name;
                    }
                    else
                    {
                        value.index         = i;
                        value.priority      = contextMenu.priority;
                        value.executeType   = type;
                        value.executeMethod = methodInfo;
                        value.executeName   = methodInfo.Name;
                    }
                    dictionary[contextMenu.menuItem] = value;
                }
            }
            AttributeHelper.MonoMenuItem[] array2 = dictionary.Values.ToArray <AttributeHelper.MonoMenuItem>();
            Array.Sort(array2, new AttributeHelper.CompareMenuIndex());
            return(array2);
        }
示例#6
0
        private static AttributeHelper.MonoMenuItem[] ExtractContextMenu(Type klass)
        {
            Dictionary <string, AttributeHelper.MonoMenuItem> dictionary = new Dictionary <string, AttributeHelper.MonoMenuItem>();

            MethodInfo[] methods = klass.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            for (int i = 0; i < methods.GetLength(0); i++)
            {
                MethodInfo methodInfo       = methods[i];
                object[]   customAttributes = methodInfo.GetCustomAttributes(typeof(ContextMenu), false);
                object[]   array            = customAttributes;
                for (int j = 0; j < array.Length; j++)
                {
                    ContextMenu contextMenu            = (ContextMenu)array[j];
                    AttributeHelper.MonoMenuItem value = (!dictionary.ContainsKey(contextMenu.menuItem)) ? default(AttributeHelper.MonoMenuItem) : dictionary[contextMenu.menuItem];
                    value.menuItem = contextMenu.menuItem;
                    value.type     = klass;
                    value.execute  = methodInfo.Name;
                    dictionary[contextMenu.menuItem] = value;
                }
            }
            return(dictionary.Values.ToArray <AttributeHelper.MonoMenuItem>());
        }
        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);
        }