Пример #1
0
        private static IEnumerable <SettingsProvider> FetchPreferenceItems()
        {
#pragma warning disable CS0618
            var methods = AttributeHelper.GetMethodsWithAttribute <PreferenceItem>(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
#pragma warning restore CS0618
            return(methods.methodsWithAttributes.Select(method =>
            {
                var callback = Delegate.CreateDelegate(typeof(Action), method.info) as Action;
                if (callback != null)
                {
#pragma warning disable CS0618
                    var attributeName = (method.attribute as PreferenceItem).name;
#pragma warning restore CS0618
                    try
                    {
                        return new SettingsProvider("Preferences/" + attributeName, SettingsScope.User)
                        {
                            guiHandler = searchContext => callback()
                        };
                    }
                    catch (Exception)
                    {
                        Debug.LogError("Cannot create preference wrapper for: " + attributeName);
                    }
                }

                return null;
            }));
        }
        internal static string[] GetShaderIncludePaths()
        {
            if (s_ShaderIncludePaths == null)
            {
                List <string> results = new List <string>();
                // ShaderIncludePathAttribute has been obsoleted with warning but we keep it working for
                // a transition period (2018.x)
                // Therefore we need suppress the warning here to make the build succeed.
#pragma warning disable 618
                var methods = AttributeHelper.GetMethodsWithAttribute <ShaderIncludePathAttribute>(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
#pragma warning restore 618
                foreach (var method in methods.methodsWithAttributes)
                {
                    if (method.info.ReturnType == typeof(string[]) && method.info.GetParameters().Length == 0)
                    {
                        var result = method.info.Invoke(null, new object[] {}) as string[];
                        if (result != null)
                        {
                            results.AddRange(result);
                        }
                    }
                }
                // The paths appear in the list in random order. We sort the list here so that the same paths will always
                // result into the exact same list. Otherwise the shader importer will think the paths have changed.
                results.Sort();
                s_ShaderIncludePaths = results.ToArray();
            }
            return(s_ShaderIncludePaths);
        }
Пример #3
0
        private static IEnumerable <Command> ScanAttributes()
        {
            var commands          = new List <Command>();
            var commandAttributes = AttributeHelper.GetMethodsWithAttribute <CommandHandlerAttribute>();

            foreach (var method in commandAttributes.methodsWithAttributes)
            {
                var callback = Delegate.CreateDelegate(typeof(CommandHandler), method.info) as CommandHandler;
                if (callback == null)
                {
                    continue;
                }
                var attr = (CommandHandlerAttribute)method.attribute;

                if (commands.Any(c => c.id == attr.id))
                {
                    Debug.LogWarning($"There is already a command with the ID {attr.id}. " +
                                     "Commands need to have a unique ID, i.e. \"Unity/Category/Command_42\".");
                    continue;
                }

                commands.Add(new Command {
                    id = attr.id, label = attr.label ?? attr.id, hint = attr.hint, handler = callback, managed = true
                });
            }

            return(commands);
        }
Пример #4
0
        private static IEnumerable <SettingsProvider> FetchSettingProvidersFromAttribute()
        {
            var methods = AttributeHelper.GetMethodsWithAttribute <SettingsProviderGroupAttribute>();

            return(methods.methodsWithAttributes.SelectMany(method =>
            {
                var callback = Delegate.CreateDelegate(typeof(Func <SettingsProvider[]>), method.info) as Func <SettingsProvider[]>;
                return callback?.Invoke();
            }));
        }
Пример #5
0
 internal static void Rebuild()
 {
     kSRootEditor.Clear();
     var rootEditorMethods = AttributeHelper.GetMethodsWithAttribute<RootEditorAttribute>(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
     foreach (var method in rootEditorMethods.methodsWithAttributes)
     {
         var callback = Delegate.CreateDelegate(typeof(RootEditorAttribute.RootEditorHandler), method.info) as RootEditorAttribute.RootEditorHandler;
         if (callback != null)
         {
             var attr = method.attribute as RootEditorAttribute;
             kSRootEditor.Add(new RootEditorDesc() { needsRootEditor = callback, supportsAddComponent = attr.supportsAddComponent });
         }
     }
 }
Пример #6
0
        private static WindowAction[] FetchWindowActionFromAttribute()
        {
            var methods = AttributeHelper.GetMethodsWithAttribute <WindowActionAttribute>();

            return(methods.methodsWithAttributes.Select(method =>
            {
                try
                {
                    var callback = Delegate.CreateDelegate(typeof(Func <WindowAction>), method.info) as Func <WindowAction>;
                    return callback?.Invoke();
                }
                catch (Exception)
                {
                    Debug.LogError("Cannot create Window Action for: " + method.info.Name);
                }
                return null;
            }).OrderBy(a => a.priority).ToArray());
        }
Пример #7
0
        private static IEnumerable <SettingsProvider> FetchSettingProviderFromAttribute()
        {
            var methods = AttributeHelper.GetMethodsWithAttribute <SettingsProviderAttribute>();

            return(methods.methodsWithAttributes.Select(method =>
            {
                try
                {
                    var callback = Delegate.CreateDelegate(typeof(Func <SettingsProvider>), method.info) as Func <SettingsProvider>;
                    return callback?.Invoke();
                }
                catch (Exception)
                {
                    Debug.LogError("Cannot create Settings Provider for: " + method.info.Name);
                }
                return null;
            }));
        }
Пример #8
0
        private static IEnumerable <SettingsProvider> FetchDeprecatedPreferenceItems()
        {
            var methods = AttributeHelper.GetMethodsWithAttribute <PreferenceItem>(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);

            return(methods.methodsWithAttributes.Select(method =>
            {
                var callback = Delegate.CreateDelegate(typeof(Action), method.info) as Action;
                if (callback != null)
                {
                    var attributeName = (method.attribute as PreferenceItem).name;
                    return new SettingsProvider("Preferences/" + attributeName)
                    {
                        guiHandler = searchContext => callback(), scopes = SettingsScopes.User
                    };
                }

                return null;
            }));
        }
 internal static string[] GetShaderIncludePaths()
 {
     if (ShaderImporterInspector.s_ShaderIncludePaths == null)
     {
         List <string> list = new List <string>();
         AttributeHelper.MethodInfoSorter methodsWithAttribute = AttributeHelper.GetMethodsWithAttribute <ShaderIncludePathAttribute>(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
         foreach (AttributeHelper.MethodWithAttribute current in methodsWithAttribute.methodsWithAttributes)
         {
             if (current.info.ReturnType == typeof(string[]) && current.info.GetParameters().Length == 0)
             {
                 string[] array = current.info.Invoke(null, new object[0]) as string[];
                 if (array != null)
                 {
                     list.AddRange(array);
                 }
             }
         }
         ShaderImporterInspector.s_ShaderIncludePaths = list.ToArray();
     }
     return(ShaderImporterInspector.s_ShaderIncludePaths);
 }
        internal static Rect DrawEditorHeaderItems(Rect rectangle, Object[] targetObjs)
        {
            if (targetObjs.Length == 0 || (targetObjs.Length == 1 && targetObjs[0].GetType() == typeof(System.Object)))
            {
                return(rectangle);
            }

            if (s_EditorHeaderItemsMethods == null)
            {
                List <Type> targetObjTypes = new List <Type>();
                var         type           = targetObjs[0].GetType();
                while (type.BaseType != null)
                {
                    targetObjTypes.Add(type);
                    type = type.BaseType;
                }

                AttributeHelper.MethodInfoSorter       methods = AttributeHelper.GetMethodsWithAttribute <EditorHeaderItemAttribute>(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
                Func <EditorHeaderItemAttribute, bool> filter  = (a) => targetObjTypes.Any(c => a.TargetType == c);
                var methodInfos = methods.FilterAndSortOnAttribute(filter, (a) => a.callbackOrder);
                s_EditorHeaderItemsMethods = new List <HeaderItemDelegate>();
                foreach (MethodInfo methodInfo in methodInfos)
                {
                    s_EditorHeaderItemsMethods.Add((HeaderItemDelegate)Delegate.CreateDelegate(typeof(HeaderItemDelegate), methodInfo));
                }
            }

            for (var index = 0; index < s_EditorHeaderItemsMethods.Count; index++)
            {
                HeaderItemDelegate dele = s_EditorHeaderItemsMethods[index];
                if (dele(rectangle, targetObjs))
                {
                    rectangle.x -= rectangle.width;
                }
            }

            return(rectangle);
        }
Пример #11
0
        private static IEnumerable <SettingsProvider> FetchSettingProvidersFromAttribute()
        {
            var methods = AttributeHelper.GetMethodsWithAttribute <SettingsProviderGroupAttribute>();

            return(methods.methodsWithAttributes.SelectMany(method =>
            {
                try
                {
                    var callback = Delegate.CreateDelegate(typeof(Func <SettingsProvider[]>), method.info) as Func <SettingsProvider[]>;
                    var providers = callback?.Invoke();
                    if (providers != null)
                    {
                        return providers;
                    }
                }
                catch (Exception)
                {
                    Debug.LogError("Cannot create Settings Providers for: " + method.info.Name);
                }

                return new SettingsProvider[0];
            }));
        }
 internal static string[] GetShaderIncludePaths()
 {
     if (s_ShaderIncludePaths == null)
     {
         List <string> results = new List <string>();
         var           methods = AttributeHelper.GetMethodsWithAttribute <ShaderIncludePathAttribute>(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
         foreach (var method in methods.methodsWithAttributes)
         {
             if (method.info.ReturnType == typeof(string[]) && method.info.GetParameters().Length == 0)
             {
                 var result = method.info.Invoke(null, new object[] {}) as string[];
                 if (result != null)
                 {
                     results.AddRange(result);
                 }
             }
         }
         // The paths appear in the list in random order. We sort the list here so that the same paths will always
         // result into the exact same list. Otherwise the shader importer will think the paths have changed.
         results.Sort();
         s_ShaderIncludePaths = results.ToArray();
     }
     return(s_ShaderIncludePaths);
 }