From 103c32f38667290e8eedd2d727718ca312c6dc6b Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sat, 29 Mar 2025 17:56:50 -0400 Subject: [PATCH] finish AddressablesLoader.cs --- .../Utilities/Assets/AddressablesLoader.cs | 75 ++++++++++++++----- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/MiraAPI/Utilities/Assets/AddressablesLoader.cs b/MiraAPI/Utilities/Assets/AddressablesLoader.cs index 2c9bdef..ab75377 100644 --- a/MiraAPI/Utilities/Assets/AddressablesLoader.cs +++ b/MiraAPI/Utilities/Assets/AddressablesLoader.cs @@ -14,6 +14,8 @@ namespace MiraAPI.Utilities.Assets; /// public static class AddressablesLoader { + private static bool _isInitialized; + private static readonly List<(string Location, string ProviderSuffix)> CatalogLocations = []; private static readonly List LoadedLocations = []; @@ -29,49 +31,86 @@ public static class AddressablesLoader /// The suffix of the provider for an addressables package. public static void RegisterCatalog(string location, string providerSuffix = "") { + if (_isInitialized) + { + Logger.Error("AddressablesLoader has already been initialized, cannot register more catalogs."); + return; + } + CatalogLocations.Add((location, providerSuffix)); } /// /// Registers a specific addressables key as only containing 's to load. /// - /// The key/label/group for a List . - public static void RegisterHats(string addressables_key) + /// The key/label/group for a List . + public static void RegisterHats(string addressablesKey) { - RegisteredHatKeys.Add(addressables_key); + if (_isInitialized) + { + Logger.Error("AddressablesLoader has already been initialized, cannot register more keys for hats."); + return; + } + + RegisteredHatKeys.Add(addressablesKey); } /// /// Registers a specific addressables key as only containing 's to load. /// - /// The key/label/group for a List . - public static void RegisterSkins(string addressables_key) + /// The key/label/group for a List . + public static void RegisterSkins(string addressablesKey) { - RegisteredSkinKeys.Add(addressables_key); + if (_isInitialized) + { + Logger.Error("AddressablesLoader has already been initialized, cannot register more keys for skins."); + return; + } + + RegisteredSkinKeys.Add(addressablesKey); } /// /// Registers a specific addressables key as only containing 's to load. /// - /// The key/label/group for a List . - /// /// The title of the group for visors. - public static void RegisterNameplates(string addressables_key, string group_title) + /// The key/label/group for a List . + /// /// The title of the group for visors. + public static void RegisterNameplates(string addressablesKey, string groupTitle) { - RegisteredNameplateKeys.Add((addressables_key, group_title)); + if (_isInitialized) + { + Logger.Error("AddressablesLoader has already been initialized, cannot register more keys for nameplates."); + return; + } + + RegisteredNameplateKeys.Add((addressablesKey, groupTitle)); } /// /// Registers a specific addressables key as only containing 's to load. /// - /// The key/label/group for a List . - /// The title of the group for visors. - public static void RegisterVisors(string addressables_key, string group_title) + /// The key/label/group for a List . + /// The title of the group for visors. + public static void RegisterVisors(string addressablesKey, string groupTitle) { - RegisteredVisorKeys.Add((addressables_key, group_title)); + if (_isInitialized) + { + Logger.Error("AddressablesLoader has already been initialized, cannot register more keys for visors."); + return; + } + + RegisteredVisorKeys.Add((addressablesKey, groupTitle)); } internal static void LoadAll() { + if (_isInitialized) + { + Logger.Error("AddressablesLoader has already been initialized."); + return; + } + + _isInitialized = true; foreach (var (location, providerSuffix) in CatalogLocations) { Coroutines.Start(CoLoadAddressables(location, providerSuffix)); @@ -147,8 +186,8 @@ public static class AddressablesLoader { try { - var all_locations = Addressables.LoadResourceLocationsAsync(tag).WaitForCompletion(); - var assets = Addressables.LoadAssetsAsync(all_locations, null, false).WaitForCompletion(); + var allLocations = Addressables.LoadResourceLocationsAsync(tag).WaitForCompletion(); + var assets = Addressables.LoadAssetsAsync(allLocations, null, false).WaitForCompletion(); var array = new Il2CppSystem.Collections.Generic.List(assets.Pointer); behaviours.AddRange(array.ToArray()); } @@ -168,8 +207,8 @@ public static class AddressablesLoader { try { - var all_locations = Addressables.LoadResourceLocationsAsync(tag.Tag).WaitForCompletion(); - var assets = Addressables.LoadAssetsAsync(all_locations, null, false).WaitForCompletion(); + var allLocations = Addressables.LoadResourceLocationsAsync(tag.Tag).WaitForCompletion(); + var assets = Addressables.LoadAssetsAsync(allLocations, null, false).WaitForCompletion(); var array = new Il2CppSystem.Collections.Generic.List(assets.Pointer); behaviours.AddRange(array.ToArray().Select(x => (tag.Category, x))); }