-
-
Save JonTerp/cedaf913589fe1fb082634d0a2c73b8f to your computer and use it in GitHub Desktop.
Hacky get all assets in folder
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 async Task<List<T>> GetAllAssetsInFolderAsync<T>(string folderPath, Action<List<T>> onComplete) | |
{ | |
IList<IResourceLocation> assetsToLoad = new List<IResourceLocation>(); | |
foreach (var locs in Addressables.ResourceLocators) | |
{ | |
ResourceLocationMap map = (ResourceLocationMap) locs; | |
Dictionary<object, IList<IResourceLocation>> locations = map.Locations; | |
foreach (var loc in locations) | |
{ | |
if (loc.Key.ToString().Contains(folderPath)) | |
{ | |
Debug.Log($"{loc.Key} contains filepath {folderPath}"); | |
assetsToLoad.Add(loc.Value[0]); | |
} | |
} | |
} | |
AsyncOperationHandle<IList<T>> handle = Addressables.LoadAssetsAsync<T>(assetsToLoad, null); | |
await handle.Task; | |
if (handle.Status != AsyncOperationStatus.Succeeded) | |
{ | |
return null; | |
} | |
onComplete?.Invoke((List<T>)handle.Result); | |
return (List<T>)handle.Result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment