Created
March 3, 2022 07:28
-
-
Save rittikornt/caf4624e0dbf21e19a4a23f7092947b8 to your computer and use it in GitHub Desktop.
Find all ScriptableObject in the Unity Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T[] LoadAllAssetAtPath<T>(string fullFolderPath, string prefix, string postfix, List<T> list = null) where T : UnityEngine.Object | |
{ | |
string searchPattern = prefix + "*" + postfix; | |
string[] filePaths = Directory.GetFiles(fullFolderPath | |
, searchPattern, SearchOption.AllDirectories); | |
//System.Array.Sort(filePaths); | |
Debug.Log($"Found {filePaths.Length} paths to check for search pattern: \"{searchPattern}\""); | |
if (list == null) | |
{ | |
list = new List<T>(); | |
} | |
foreach (string path in filePaths) | |
{ | |
string assetPath = "Assets" + path.Replace(Application.dataPath, "").Replace('\\', '/'); | |
var asset = (T)AssetDatabase.LoadAssetAtPath(assetPath, typeof(T)); | |
if (asset != null) | |
{ | |
list.Add(asset); | |
} | |
//Debug.Log(assetPath); | |
} | |
return list.ToArray(); | |
} | |
// Example Usage: find | |
// string findPath = Application.dataPath; | |
// CustomScriptableObjectType[] objs = LoadAllAssetAtPath<CustomScriptableObjectType>(findPath, "", ".asset", null); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment