Ejemplo n.º 1
0
            void RegisterAllEngines()
            {
                var types = TypeCache.GetTypesWithAttribute <TAttribute>();
                var instantiatedEngines = types.Select(type => Activator.CreateInstance(type));

                foreach (var instantiatedEngine in instantiatedEngines)
                {
                    if (instantiatedEngine is TEngine typedEngine)
                    {
                        RegisterEngine(typedEngine);
                    }
                    else
                    {
                        Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null,
                                        $"Trying to register a search engine with the attribute {typeof(TAttribute)} but it does not implement the interface {typeof(TEngine)}.");
                    }
                }
            }
Ejemplo n.º 2
0
 static NativeFormatImporterUtility()
 {
     foreach (var type in TypeCache.GetTypesWithAttribute <AssetFileNameExtensionAttribute>())
     {
         var attr = type.GetCustomAttributes(typeof(AssetFileNameExtensionAttribute), false)[0]
                    as AssetFileNameExtensionAttribute;
         try
         {
             RegisterExtensionForType(type, attr.preferredExtension, attr.otherExtensions.ToArray());
         }
         catch (ArgumentException e)
         {
             Debug.LogException(e);
         }
         catch (NotSupportedException e)
         {
             Debug.LogException(e);
         }
     }
 }
Ejemplo n.º 3
0
        static MonoCreateAssetItem[] ExtractCreateAssetMenuItems(Assembly assembly)
        {
            var result = new List <MonoCreateAssetItem>();

            foreach (var type in TypeCache.GetTypesWithAttribute <CreateAssetMenuAttribute>())
            {
                var attr = type.GetCustomAttributes(typeof(CreateAssetMenuAttribute), false).FirstOrDefault() as CreateAssetMenuAttribute;
                if (attr == null)
                {
                    continue;
                }

                if (!type.IsSubclassOf(typeof(ScriptableObject)))
                {
                    Debug.LogWarningFormat("CreateAssetMenu attribute on {0} will be ignored as {0} is not derived from ScriptableObject.", type.FullName);
                    continue;
                }

                string menuItemName = (string.IsNullOrEmpty(attr.menuName)) ? ObjectNames.NicifyVariableName(type.Name) : attr.menuName;
                string fileName     = (string.IsNullOrEmpty(attr.fileName)) ? ("New " + ObjectNames.NicifyVariableName(type.Name) + ".asset") : attr.fileName;
                if (!System.IO.Path.HasExtension(fileName))
                {
                    fileName = fileName + ".asset";
                }

                var item = new MonoCreateAssetItem
                {
                    menuItem = menuItemName,
                    fileName = fileName,
                    order    = attr.order,
                    type     = type
                };
                result.Add(item);
            }

            return(result.ToArray());
        }
Ejemplo n.º 4
0
        internal static void Rebuild()
        {
            kSCustomEditors.Clear();
            kSCustomMultiEditors.Clear();
            var types = TypeCache.GetTypesWithAttribute <CustomEditor>();

            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);
                        }
                    }
                }
            }
        }