Exemplo n.º 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());
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
0
        public PCMScriptableObject(Type type)
        {
            this.type = type;
            CreateAssetMenuAttribute attr = type.GetCustomAttributes(typeof(CreateAssetMenuAttribute), false)[0] as CreateAssetMenuAttribute;

            string[] menuPath = attr.menuName.Split('/');
            name = $"{menuPath[menuPath.Length - 2]}/{menuPath[menuPath.Length - 1]}";
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        private static AttributeHelper.MonoCreateAssetItem[] ExtractCreateAssetMenuItems(Assembly assembly)
        {
            List <AttributeHelper.MonoCreateAssetItem> list = new List <AttributeHelper.MonoCreateAssetItem>();

            foreach (Type current in EditorAssemblies.GetAllTypesWithAttribute <CreateAssetMenuAttribute>())
            {
                CreateAssetMenuAttribute createAssetMenuAttribute = current.GetCustomAttributes(typeof(CreateAssetMenuAttribute), false).FirstOrDefault <object>() as CreateAssetMenuAttribute;
                if (createAssetMenuAttribute != null)
                {
                    if (!current.IsSubclassOf(typeof(ScriptableObject)))
                    {
                        UnityEngine.Debug.LogWarningFormat("CreateAssetMenu attribute on {0} will be ignored as {0} is not derived from ScriptableObject.", new object[]
                        {
                            current.FullName
                        });
                    }
                    else
                    {
                        string menuItem = (!string.IsNullOrEmpty(createAssetMenuAttribute.menuName)) ? createAssetMenuAttribute.menuName : ObjectNames.NicifyVariableName(current.Name);
                        string text     = (!string.IsNullOrEmpty(createAssetMenuAttribute.fileName)) ? createAssetMenuAttribute.fileName : ("New " + ObjectNames.NicifyVariableName(current.Name) + ".asset");
                        if (!Path.HasExtension(text))
                        {
                            text += ".asset";
                        }
                        AttributeHelper.MonoCreateAssetItem item = new AttributeHelper.MonoCreateAssetItem
                        {
                            menuItem = menuItem,
                            fileName = text,
                            order    = createAssetMenuAttribute.order,
                            type     = current
                        };
                        list.Add(item);
                    }
                }
            }
            return(list.ToArray());
        }