Initial commit

This commit is contained in:
MuHua-123
2024-11-01 17:14:31 +08:00
commit 5f169b90bb
216 changed files with 24712 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
public static class ModuleCoreTool {
public static void FunctionRegister<Module>(this ModuleCore core, Module module) {
Type baseType = module.GetType().BaseType;
FieldInfo fieldInfo = FindField<ModuleCore>(baseType);
if (fieldInfo == null) {
Debug.LogError($"{typeof(ModuleCore).Name} 类型没有 {baseType.Name} 字段!");
return;
}
object obj = fieldInfo.GetValue(core);
if (obj != null) {
Debug.LogWarning($"{module.GetType().Name} 模块替换了 {obj.GetType().Name} 模块!");
return;
}
fieldInfo.SetValue(core, module);
}
public static FieldInfo FindField<T>(Type baseType) {
FieldInfo[] fileInfos = typeof(T).GetFields();
for (int i = 0; i < fileInfos.Length; i++) {
if (fileInfos[i].FieldType == baseType) { return fileInfos[i]; }
}
return null;
}
}