create loadable asset wrapper

This commit is contained in:
XtraCube committed 2025-03-29 14:25:57 -04:00
1 parent 2ecfa267d6
commit b99efaa420
1 file changed
+25
@@ -0,0 +1,25 @@
using Reactor.Utilities.Extensions;
namespace MiraAPI.Utilities.Assets;
/// <summary>
/// Wrapper class to turn any UnityEngine.Object into a <see cref="LoadableAsset{T}"/>.
/// </summary>
/// <typeparam name="T">The type of the asset to be loaded. Must be a subclass of <see cref="UnityEngine.Object"/>.</typeparam>
public class LoadableAssetWrapper<T> : LoadableAsset<T> where T : UnityEngine.Object
{
/// <summary>
/// Initializes a new instance of the <see cref="LoadableAssetWrapper{T}"/> class.
/// </summary>
/// <param name="asset">The asset to wrap. This should be a reference to a UnityEngine.Object.</param>
public LoadableAssetWrapper(T asset)
{
LoadedAsset = asset.DontDestroy();
}
/// <inheritdoc />
public override T LoadAsset()
{
return LoadedAsset ?? throw new System.InvalidOperationException("The asset could not be loaded!");
}
}