mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
create loadable asset wrapper
This commit is contained in:
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!");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user