1
This commit is contained in:
@@ -20,6 +20,8 @@ namespace BITKit
|
||||
}
|
||||
public class BITApp
|
||||
{
|
||||
public static int Count => _count++;
|
||||
private static int _count;
|
||||
public static async UniTask SwitchToMainThread()
|
||||
{
|
||||
await UniTask.SwitchToSynchronizationContext(SynchronizationContext);
|
||||
@@ -243,6 +245,7 @@ namespace BITKit
|
||||
private static DateTime InitialTime { get; set; }=DateTime.Now;
|
||||
public static async UniTask Start(string appName = nameof(BITApp),AppSettings settings=default)
|
||||
{
|
||||
_count = 0;
|
||||
Time.TimeAsDouble = 0;
|
||||
Time.DeltaTime = 1 / 60f;
|
||||
SynchronizationContext=SynchronizationContext.Current;
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -8,7 +8,7 @@ namespace BITKit
|
||||
{
|
||||
public static class BIT4Log
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR && !UNITY_WEBGL
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
private static void Reload()
|
||||
{
|
||||
|
@@ -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
|
||||
|
@@ -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,例如
|
||||
|
@@ -31,12 +31,12 @@ namespace BITKit
|
||||
{
|
||||
public int frameRate = 30;
|
||||
public PlayerState state;
|
||||
protected List<T> list = new();
|
||||
public List<T> list { get; protected set; } =new();
|
||||
public bool isPlaying;
|
||||
public event Action onStart;
|
||||
public event Action onStop;
|
||||
protected T current;
|
||||
Timer timer = new() { AutoReset = true };
|
||||
private Timer timer = new() { AutoReset = true };
|
||||
public void Start()
|
||||
{
|
||||
if (isPlaying is false)
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -11,8 +11,8 @@ namespace BITKit
|
||||
public event Action<float> onProgess;
|
||||
public event Action<string> onSetTotalTime;
|
||||
public event Action<string> onTime;
|
||||
float totalTime => (float)list.Count / frameRate;
|
||||
protected override void OnUpdate()
|
||||
public float totalTime => (float)list.Count / frameRate;
|
||||
protected override async void OnUpdate()
|
||||
{
|
||||
if (list.Count > 0)
|
||||
{
|
||||
@@ -20,6 +20,7 @@ namespace BITKit
|
||||
if (state is PlayerState.Playing)
|
||||
index = Math.Clamp(++index, 0, list.Count + 32);
|
||||
|
||||
await BITApp.SwitchToMainThread();
|
||||
if (index > list.Count)
|
||||
{
|
||||
if (index - list.Count > frameRate / 2)
|
||||
@@ -27,6 +28,8 @@ namespace BITKit
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (BITApp.CancellationToken.IsCancellationRequested) return;
|
||||
output?.Invoke(list[index]);
|
||||
onProgess?.Invoke(progess);
|
||||
onTime?.Invoke(GetTime(totalTime * progess));
|
||||
@@ -63,5 +66,6 @@ namespace BITKit
|
||||
{
|
||||
return new DateTime().AddSeconds(sec).ToString(timeFormat);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -138,13 +138,16 @@ namespace BITKit
|
||||
{
|
||||
StartInfo = StartInfo,
|
||||
};
|
||||
var reportBuilder = new StringBuilder();
|
||||
process.OutputDataReceived += (sender, args) =>
|
||||
{
|
||||
BIT4Log.Log<BITSharp>(args.Data);
|
||||
//BIT4Log.Log<BITSharp>(args.Data);
|
||||
reportBuilder.AppendLine(args.Data);
|
||||
};
|
||||
process.ErrorDataReceived += (sender, args) =>
|
||||
{
|
||||
BIT4Log.Warning<BITSharp>(args.Data);
|
||||
//BIT4Log.Warning<BITSharp>(args.Data);
|
||||
reportBuilder.AppendLine($"<color=yellow>{args.Data}</color>");
|
||||
};
|
||||
|
||||
process.Start();
|
||||
@@ -173,6 +176,8 @@ namespace BITKit
|
||||
}
|
||||
}
|
||||
|
||||
BIT4Log.Log<BITSharp>(reportBuilder);
|
||||
|
||||
waiting?.Release(handle);
|
||||
|
||||
return Assembly.Load(bytes);
|
||||
|
@@ -104,7 +104,7 @@ namespace BITKit
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream(zippedData);
|
||||
System.IO.Compression.GZipStream compressedzipStream = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress);
|
||||
System.IO.MemoryStream outBuffer = new System.IO.MemoryStream();
|
||||
byte[] block = new byte[1024];
|
||||
byte[] block = new byte[1024*16];
|
||||
while (true)
|
||||
{
|
||||
int bytesRead = compressedzipStream.Read(block, 0, block.Length);
|
||||
|
Reference in New Issue
Block a user