This commit is contained in:
CortexCore
2024-04-22 03:48:37 +08:00
parent 0362b2c606
commit c1f51826b3
35 changed files with 556 additions and 270 deletions

View File

@@ -3,12 +3,15 @@
namespace BITKit
{
[AttributeUsage(AttributeTargets.Method)]
public class BITCommandAttribute : Attribute { }
public class BITCommandAttribute : Attribute
{
}
/// <summary>
/// 自动注入依赖
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class InjectAttribute : System.Attribute
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class InjectAttribute : Attribute
{
public static void Clear(object obj)
{

View File

@@ -125,6 +125,29 @@ namespace BITKit
/// <param name="obj"></param>
public static void Inject(object obj)
{
foreach (var propertyInfo in obj.GetType().GetProperties(ReflectionHelper.Flags))
{
try
{
if (propertyInfo.GetCustomAttribute<ObsoleteAttribute>() is null &&
propertyInfo.GetCustomAttribute<InjectAttribute>() is not null)
{
lock (dictionary)
{
if(dictionary!.TryGetValue(propertyInfo.PropertyType,out var value))
{
BIT4Log.Log<DI>($"已为{obj.GetType().Name}.{propertyInfo.Name}注入{value.GetType().Name}");
propertyInfo.SetValue(obj,value);
}
}
}
}
catch (Exception e)
{
BIT4Log.LogException(e);
}
}
foreach (var field in obj.GetType().GetFields(ReflectionHelper.Flags))
{
try

View File

@@ -15,7 +15,7 @@ namespace BITKit.Entities
/// 等待初始化完成,通常用于其他系统需要等待实体初始化完成
/// </summary>
void WaitForInitializationComplete();
ulong Id { get; }
int Id { get; }
CancellationToken CancellationToken { get; }
bool TryGetComponent<T>(out T component);
IEntityComponent[] Components { get; }
@@ -81,18 +81,18 @@ namespace BITKit.Entities
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
IEntity Get(ulong id);
IEntity Get(int id);
/// <summary>
/// 尝试通过Id获取Entity
/// </summary>
/// <param name="id"></param>
/// <param name="entity"></param>
/// <returns></returns>
bool TryGetEntity(ulong id, out IEntity entity);
bool TryGetEntity(int id, out IEntity entity);
/// <summary>
/// 通过Id获取或添加Entity
/// </summary>
IEntity GetOrAdd(ulong id,Func<ulong,IEntity> factory);
IEntity GetOrAdd(int id,Func<int,IEntity> factory);
/// <summary>
/// 查询Entity,例如

View File

@@ -220,7 +220,6 @@ namespace BITKit.Mod
private static Thread _Thread;
private static bool _IsRunning;
private static bool _IsLocked;
private static AppDomain _ModDomain;
public static void Initialize()
{
@@ -241,8 +240,6 @@ namespace BITKit.Mod
try
{
_ModDomain = AppDomain.CreateDomain("ModDomain");
var modPath = Path.Combine(Environment.CurrentDirectory, "Mods\\");
PathHelper.EnsureDirectoryCreated(modPath);
var directoryInfo = new DirectoryInfo(modPath);
@@ -383,7 +380,6 @@ namespace BITKit.Mod
_UnRegisterQueue.Clear();
Mods = Array.Empty<IMod>();
_InstalledMods.Clear();
AppDomain.Unload(_ModDomain);
}
catch (Exception e)
{