diff --git a/src/SpaceWarp.Core/Patching/LoadingActions/AddressableAction.cs b/src/SpaceWarp.Core/Patching/LoadingActions/AddressableAction.cs index 6f1b6cf..2fc6fe7 100644 --- a/src/SpaceWarp.Core/Patching/LoadingActions/AddressableAction.cs +++ b/src/SpaceWarp.Core/Patching/LoadingActions/AddressableAction.cs @@ -18,6 +18,7 @@ public class AddressableAction : FlowAction where T : UnityObject { private string _label; private Action _action; + private bool _keepAssets; /// /// Creates a new addressable loading action. @@ -30,6 +31,19 @@ public AddressableAction(string name, string label, Action action) : base(nam _label = label; _action = action; } + + /// + /// Creates a new addressable loading action, with the option to keep the asset in memory after loading. + /// This is useful for textures or UXML templates, for example. + /// + /// Name of the action. + /// Label of the asset to load. + /// Action to perform on the loaded asset. + /// Allows to keep asset in memory after loading them. + public AddressableAction(string name, string label, bool keepAssets, Action action) : this(name, label, action) + { + _keepAssets = keepAssets; + } private bool DoesLabelExist(object label) { @@ -55,7 +69,7 @@ public override void DoAction(Action resolve, Action reject) { GameManager.Instance.Assets.LoadByLabel(_label,_action,delegate(IList assetLocations) { - if (assetLocations != null) + if (assetLocations != null && !_keepAssets) { Addressables.Release(assetLocations); }