diff --git a/MiraAPI/Utilities/Assets/LoadableAssetWrapper.cs b/MiraAPI/Utilities/Assets/LoadableAssetWrapper.cs new file mode 100644 index 0000000..578c051 --- /dev/null +++ b/MiraAPI/Utilities/Assets/LoadableAssetWrapper.cs @@ -0,0 +1,25 @@ +using Reactor.Utilities.Extensions; + +namespace MiraAPI.Utilities.Assets; + +/// +/// Wrapper class to turn any UnityEngine.Object into a . +/// +/// The type of the asset to be loaded. Must be a subclass of . +public class LoadableAssetWrapper : LoadableAsset where T : UnityEngine.Object +{ + /// + /// Initializes a new instance of the class. + /// + /// The asset to wrap. This should be a reference to a UnityEngine.Object. + public LoadableAssetWrapper(T asset) + { + LoadedAsset = asset.DontDestroy(); + } + + /// + public override T LoadAsset() + { + return LoadedAsset ?? throw new System.InvalidOperationException("The asset could not be loaded!"); + } +}