codex talán fixálta idk

This commit is contained in:
2025-12-14 13:09:32 +01:00
parent b02af4d0c7
commit b05c3415f2
4 changed files with 83 additions and 19 deletions

60
ResourceStorageHelper.cs Normal file
View File

@@ -0,0 +1,60 @@
using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace KCM
{
internal static class ResourceStorageHelper
{
private static Type resourceStorageType;
private static MethodInfo getComponentsMethod;
private static MethodInfo isPrivateMethod;
private static MethodInfo addResourceStorageMethod;
private static void EnsureInitialized()
{
if (resourceStorageType != null)
return;
resourceStorageType = AppDomain.CurrentDomain
.GetAssemblies()
.Select(a => a.GetType("Assets.Interface.IResourceStorage", false))
.FirstOrDefault(t => t != null);
if (resourceStorageType == null)
return;
getComponentsMethod = typeof(Component).GetMethod("GetComponents", new[] { typeof(Type) });
isPrivateMethod = resourceStorageType.GetMethod("IsPrivate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
addResourceStorageMethod = typeof(FreeResourceManager).GetMethod("AddResourceStorage", new[] { resourceStorageType });
}
public static Component[] GetStorages(Component owner)
{
EnsureInitialized();
if (resourceStorageType == null || getComponentsMethod == null)
return Array.Empty<Component>();
return (Component[])getComponentsMethod.Invoke(owner, new object[] { resourceStorageType });
}
public static bool IsPrivate(Component storage)
{
EnsureInitialized();
if (isPrivateMethod == null)
return true;
return (bool)isPrivateMethod.Invoke(storage, null);
}
public static void Register(Component storage)
{
EnsureInitialized();
if (addResourceStorageMethod == null || FreeResourceManager.inst == null)
return;
addResourceStorageMethod.Invoke(FreeResourceManager.inst, new object[] { storage });
}
}
}