update other addressable related things

This commit is contained in:
XtraCube committed 2025-03-29 17:58:05 -04:00
1 parent 103c32f386
commit 32b368c1ef
3 files changed
+9 -15

No files matched your search

@@ -11,7 +11,7 @@ namespace MiraAPI.Utilities.Assets;
/// <typeparam name="T">The type of the asset to be loaded.</typeparam>
public class LoadableAddressableAsset<T>(string uid) : LoadableAsset<T> where T : UnityEngine.Object
{
private readonly Action<LoadableAddressableAsset<T>>? gcAction;
private readonly Action<LoadableAddressableAsset<T>>? _gcAction;
/// <summary>
/// Initializes a new instance of the <see cref="LoadableAddressableAsset{T}"/> class, with added garbageCollector logic,
@@ -21,7 +21,7 @@ public class LoadableAddressableAsset<T>(string uid) : LoadableAsset<T> where T
/// <param name="garbageCollection">A lambda that allows GCHandle.Alloc calls without garbage collection interferences.</param>
public LoadableAddressableAsset(string uid, Action<LoadableAddressableAsset<T>> garbageCollection) : this(uid)
{
gcAction = garbageCollection;
_gcAction = garbageCollection;
}
/// <summary>
@@ -47,10 +47,7 @@ public class LoadableAddressableAsset<T>(string uid) : LoadableAsset<T> where T
throw new InvalidOperationException($"INVALID ASSET: {uid}");
}
if (gcAction != null)
{
gcAction.Invoke(this);
}
_gcAction?.Invoke(this);
GC.EndNoGCRegion();
return LoadedAsset;
@@ -13,7 +13,7 @@ namespace MiraAPI.Utilities.Assets;
/// <typeparam name="T">The type of the asset to be loaded.</typeparam>
public class LoadableAddressableAssets<T>(string key) where T : UnityEngine.Object
{
private readonly Action<LoadableAddressableAssets<T>>? gcAction;
private readonly Action<LoadableAddressableAssets<T>>? _gcAction;
/// <summary>
/// Gets or sets reference to the loaded asset. Intended to be used for caching purposes.
@@ -28,7 +28,7 @@ public class LoadableAddressableAssets<T>(string key) where T : UnityEngine.Obje
/// <param name="garbageCollection">A lambda that allows GCHandle.Alloc calls without garbage collection interferences.</param>
public LoadableAddressableAssets(string key, Action<LoadableAddressableAssets<T>> garbageCollection) : this(key)
{
gcAction = garbageCollection;
_gcAction = garbageCollection;
}
/// <summary>
@@ -57,10 +57,7 @@ public class LoadableAddressableAssets<T>(string key) where T : UnityEngine.Obje
var assetsList = new Il2CppSystem.Collections.Generic.List<T>(assetsIList.Pointer);
LoadedAssets = assetsList.ToArray().ToList();
if (gcAction != null)
{
gcAction.Invoke(this);
}
_gcAction?.Invoke(this);
GC.EndNoGCRegion();
return LoadedAssets.AsReadOnly();
+3 -3
View File
@@ -3,17 +3,17 @@
namespace MiraAPI.Utilities.Assets;
/// <summary>
/// An implementation for creating loadable assets from preloaded assets.
/// An implementation for creating loadable assets from existing assets.
/// </summary>
/// <inheritdoc cref="LoadableAsset{T}"/>
/// <inheritdoc />
public class PreloadedAsset<T>(T asset) : LoadableAsset<T> where T : UnityEngine.Object
{
private readonly T loadedAsset = asset ?? throw new ArgumentNullException(nameof(asset));
private readonly T _loadedAsset = asset ?? throw new ArgumentNullException(nameof(asset));
/// <inheritdoc />
public override T LoadAsset()
{
return loadedAsset;
return _loadedAsset;
}
}