Replace DestroyableSingleton with direct access

This commit is contained in:
Gurge44 committed 2025-10-21 11:48:28 +02:00
1 parent 1c0f8f93d9
commit 026bd1e05b
30 files changed
+123 -144

No files matched your search

-31
View File
@@ -46,37 +46,6 @@ public static class ObjectHelper
}
}
// From: https://github.com/TheOtherRolesAU/TheOtherRoles/blob/a5126c5d1eae15e8a9def2dc27dc1e3f63681f2c/TheOtherRoles/Utilities/FastDestroyableSingleton.cs
public static unsafe class FastDestroyableSingleton<T> where T : MonoBehaviour
{
private static readonly IntPtr FieldPtr;
private static readonly Func<IntPtr, T> CreateObject;
static FastDestroyableSingleton()
{
FieldPtr = IL2CPP.GetIl2CppField(Il2CppClassPointerStore<DestroyableSingleton<T>>.NativeClassPtr, nameof(DestroyableSingleton<T>._instance));
ConstructorInfo constructor = typeof(T).GetConstructor([typeof(IntPtr)]);
ParameterExpression ptr = Expression.Parameter(typeof(IntPtr));
NewExpression create = Expression.New(constructor!, ptr);
Expression<Func<IntPtr, T>> lambda = Expression.Lambda<Func<IntPtr, T>>(create, ptr);
CreateObject = lambda.Compile();
}
public static T Instance
{
get
{
#if ANDROID
return DestroyableSingleton<T>.Instance;
#else
IntPtr objectPointer;
IL2CPP.il2cpp_field_static_get_value(FieldPtr, &objectPointer);
return objectPointer == IntPtr.Zero ? DestroyableSingleton<T>.Instance : CreateObject(objectPointer);
#endif
}
}
}
// The codes below I stole from TommyXL
public static class Il2CppCastHelper
{