using UnityEditor; using UnityEngine; using System.IO; using System.Collections.Generic; using static UnityEditor.ShaderGraph.Internal.KeywordDependentCollection; using UnityEngine.Windows; /// /// Resources Objects other than directories can be accessed. In fact, you can also access objects in the Resources directory. /// public static class GetAsset { //================================================================================= //Single load //================================================================================= /// /// Set the file path (including the extension from Assets) and type, and load the Object. Returns Null if not present /// public static T Load(string path) where T : Object { return AssetDatabase.LoadAssetAtPath(path); } /// /// Set the file path (from Assets, including the extension) and load the Object. Returns Null if not present /// public static Object Load(string path) { return Load(path); } //================================================================================= //multiple loads //================================================================================= /// /// Set the directory path(from Assets) and type, and load the Object.Returns an empty List if it does not exist /// public static List LoadAll(string directoryPath) where T : Object { List assetList = new List(); //Get all files in the specified directory (including child directories) string[] filePathArray = System.IO.Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories); //Add only assets from the acquired files to the list foreach (string filePath in filePathArray) { T asset = Load(filePath); if (asset != null) { assetList.Add(asset); } } return assetList; } /// /// Set the directory path (from Assets) and read the Object. Returns an empty List if it does not exist /// public static List LoadAll(string directoryPath) { return LoadAll(directoryPath); } }