public static IEnumerable <ResourcesAssetEntry> GetPrefabsWithComponent(Type component)
 {
     foreach (var go in Util.GetAssets <GameObject>())
     {
         if (go != null && go.GetComponent(component) != null)
         {
             yield return(ResourcesAssetEntry.Create(go));
         }
     }
 }
 public static IEnumerable <ResourcesAssetEntry> GetScriptableObjectsWithInterface(Type @interface)
 {
     foreach (var so in Util.GetAssets <ScriptableObject>())
     {
         if (so != null && @interface.IsAssignableFrom(so.GetType()))
         {
             yield return(ResourcesAssetEntry.Create(so));
         }
     }
 }
 internal static IEnumerable <ResourcesAssetEntry> GetScenes()
 {
     foreach (var item in Util.GetAssets <SceneAsset>("", RESOURCES_ROOT_FOLDER))
     {
         var path = AssetDatabase.GetAssetPath(item);
         yield return(new ResourcesAssetEntry()
         {
             address = ResourcesAssetEntry.GetAddress(AssetDatabase.GetAssetPath(item)),
             asset = item,
             AssetPath = path
         });
     }
 }
Пример #4
0
        protected static string CreateAsset(Type type, Type linkType, FieldInfo fieldInfo)
        {
            LinkFolderAttribute folderAttr = linkType.GetCustomAttribute <LinkFolderAttribute>();
            string defaultFolder           = folderAttr != null ? ResourcesAssetHelper.RootFolder + "/" + folderAttr.folder : ResourcesAssetHelper.RootFolder;

            if (fieldInfo != null && fieldInfo.GetCustomAttribute <LinkFolderAttribute>() != null)
            {
                defaultFolder = ResourcesAssetHelper.RootFolder + "/" + fieldInfo.GetCustomAttribute <LinkFolderAttribute>().folder;
            }

            string ext = GetExtension(type);

            if (Directory.Exists(defaultFolder) == false)
            {
                Directory.CreateDirectory(defaultFolder);
            }

            string path = EditorUtility.SaveFilePanelInProject("Create new " + type.Name, fieldInfo?.Name.FirstCharToUpper(), ext, "Create new " + type.Name, defaultFolder);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            if (ext == "prefab")
            {
                GameObject go = new GameObject(type.Name);
                go.AddComponent(type);
                PrefabUtility.SaveAsPrefabAsset(go, path);
                Object.DestroyImmediate(go);
            }
            else
            {
                ScriptableObject so = ScriptableObject.CreateInstance(type);
                AssetDatabase.CreateAsset(so, path);
            }

            string address = null;

#if USE_ADDRESSABLES
            AddrHelper.Reload();

            AddressableAssetEntry entry = AddrHelper.CreateOrModifyEntry(AssetDatabase.AssetPathToGUID(path));
            address = entry.address;
#else
            address = ResourcesAssetEntry.GetAddress(path);
#endif
            AssetDatabase.Refresh();

            return(address);
        }
        internal static IEnumerable <ResourcesAssetEntry> GetAssets(Type type)
        {
            Util.EnsureProjectFolderExists(RESOURCES_ROOT_FOLDER);

            if (typeof(Component).IsAssignableFrom(type))
            {
                foreach (var asset in Util.GetAssets(typeof(GameObject), "", RESOURCES_ROOT_FOLDER))
                {
                    var go = asset as GameObject;
                    if (go && go.GetComponent(type))
                    {
                        yield return(ResourcesAssetEntry.Create(asset));
                    }
                }
            }
            else
            {
                foreach (var asset in Util.GetAssets(type, "", RESOURCES_ROOT_FOLDER))
                {
                    yield return(ResourcesAssetEntry.Create(asset));
                }
            }
        }