diff --git a/Src/Core/Applation/BITApp.cs b/Src/Core/Applation/BITApp.cs
index 7fcd6f0..9f8d4ac 100644
--- a/Src/Core/Applation/BITApp.cs
+++ b/Src/Core/Applation/BITApp.cs
@@ -176,12 +176,7 @@ namespace BITKit
///
/// 依赖服务提供接口
///
- public static ServiceProvider ServiceProvider
- {
- get=>_serviceProvider??=ServiceCollection.BuildServiceProvider();
- set => _serviceProvider = value;
- }
- private static ServiceProvider _serviceProvider;
+ public static ServiceProvider ServiceProvider { get; set; }
///
/// 主线程
///
diff --git a/Src/Core/Applation/BITAppForNet.cs b/Src/Core/Applation/BITAppForNet.cs
index 0cd644e..664e211 100644
--- a/Src/Core/Applation/BITAppForNet.cs
+++ b/Src/Core/Applation/BITAppForNet.cs
@@ -8,19 +8,15 @@ namespace BITKit;
public class BITAppForNet
{
- [Obsolete("Use InitializeAsync instead")]
- public static UniTask Init(string name)=>UniTask.CompletedTask;
+ private static readonly Timer _timer = new();
- private static Timer _timer = new();
-
- private static DateTime _startTime = DateTime.UtcNow;
+ private static readonly DateTime _startTime = DateTime.UtcNow;
public static async UniTask InitializeAsync(string name)
{
BIT4Log.OnLog += Console.WriteLine;
BIT4Log.OnWarning += Console.WriteLine;
BIT4Log.OnException += e => Console.WriteLine(e.ToString());
- BIT4Log.OnSetConsoleColor += color => Console.ForegroundColor = color;
BIT4Log.OnNextLine += Console.WriteLine;
diff --git a/Src/Core/BITLog/BIT4Log.cs b/Src/Core/BITLog/BIT4Log.cs
index 6934f2a..aa26fe7 100644
--- a/Src/Core/BITLog/BIT4Log.cs
+++ b/Src/Core/BITLog/BIT4Log.cs
@@ -1,79 +1,99 @@
using System;
using System.Diagnostics;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
#endif
namespace BITKit
{
- public static class BIT4Log
- {
- #if UNITY_EDITOR && UNITY_5_3_OR_NEWER
- [RuntimeInitializeOnLoadMethod]
- private static void Reload()
+ public static class BIT4Log
{
- OnLog = null;
- OnException = null;
- OnWarning = null;
- OnSetConsoleColor = null;
- OnNextLine = null;
- }
- #endif
- public static event Action OnLog;
- public static event Action OnLogCallback;
- public static event Action OnException;
- public static event Action OnExceptionCallback;
- public static event Action OnWarning;
- public static event Action OnWarningCallback;
- public static event Action OnSetConsoleColor;
- public static event Action OnNextLine;
- private static Type currentType;
-#if UNITY_5_3_OR_NEWER
- //[HideInCallstack]
+#if UNITY_EDITOR && UNITY_5_3_OR_NEWER
+ [RuntimeInitializeOnLoadMethod]
+ private static void Reload()
+ {
+ OnLog = null;
+ OnException = null;
+ OnWarning = null;
+ OnNextLine = null;
+ }
#endif
- public static void Log(object x, ConsoleColor color = ConsoleColor.White)
- {
- OnSetConsoleColor?.Invoke(color);
- OnLog?.Invoke(x?.ToString());
- OnLogCallback?.Invoke(x?.ToString(),currentType);
- }
+ public static event Action OnLog;
+ public static event Action OnException;
+ public static event Action OnWarning;
+ public static event Action OnNextLine;
#if UNITY_5_3_OR_NEWER
- [HideInCallstack]
+ [HideInCallstack]
#endif
- public static void Log(object x, ConsoleColor color = ConsoleColor.White)
- {
- if (currentType != typeof(T))
- {
- OnNextLine?.Invoke();
- }
- #if NET5_0_OR_GREATER
- Log($"[{DateTime.Now}]{typeof(T).Name}:{x}");
- #else
- Log($"{typeof(T).Name}:{x}");
- #endif
-
- currentType = typeof(T);
- }
+ public static void Log(object x)
+ {
+ if (OnLog is not null)
+ {
+ OnLog.Invoke(x?.ToString());
+ return;
+ }
#if UNITY_5_3_OR_NEWER
- [HideInCallstack]
+ UnityEngine.Debug.Log(x);
#endif
- public static void LogException(Exception e)
- {
- OnException?.Invoke(e);
- }
+ }
#if UNITY_5_3_OR_NEWER
- [HideInCallstack]
+ [HideInCallstack]
#endif
- public static void Warning(object x)
- {
- OnWarning?.Invoke(x.ToString());
- }
+ public static void Log(object x)
+ {
+ if (OnLog is not null)
+ {
+ OnLog.Invoke(x?.ToString());
+ return;
+ }
#if UNITY_5_3_OR_NEWER
- [HideInCallstack]
+ UnityEngine.Debug.Log($"{typeof(T).Name}" + x);
#endif
- public static void Warning(object x)
- {
- Warning($"{typeof(T).Name}:{x}");
+ }
+#if UNITY_5_3_OR_NEWER
+ [HideInCallstack]
+#endif
+ public static void LogException(Exception e)
+ {
+ if (OnException is not null)
+ {
+ OnException.Invoke(e);
+ return;
+ }
+#if UNITY_5_3_OR_NEWER
+ UnityEngine.Debug.LogException(e);
+#endif
+
+ }
+#if UNITY_5_3_OR_NEWER
+ [HideInCallstack]
+#endif
+ public static void Warning(object x)
+ {
+ if (OnWarning is not null)
+ {
+ OnWarning.Invoke(x.ToString());
+ return;
+ }
+#if UNITY_5_3_OR_NEWER
+ UnityEngine.Debug.LogWarning(x);
+#endif
+ }
+#if UNITY_5_3_OR_NEWER
+ [HideInCallstack]
+#endif
+ public static void Warning(object x)
+ {
+ if (OnWarning is not null)
+ {
+ OnWarning.Invoke(x.ToString());
+ return;
+ }
+#if UNITY_5_3_OR_NEWER
+ UnityEngine.Debug.LogWarning($"{typeof(T).Name}" + x);
+#endif
+ }
}
- }
}
diff --git a/Src/Core/Group/ActivableGroup.cs b/Src/Core/Group/ActivableGroup.cs
index 368bfe0..e01105b 100644
--- a/Src/Core/Group/ActivableGroup.cs
+++ b/Src/Core/Group/ActivableGroup.cs
@@ -126,7 +126,12 @@ namespace BITKit
}
catch (Exception e)
{
- BIT4Log.LogException(e);
+ #if UNITY_EDITOR
+ UnityEngine.Debug.LogException(e);
+ #else
+ BIT4Log.LogException(e);
+ #endif
+
}
}
diff --git a/Src/Core/Kcp/KcpNetClient.cs b/Src/Core/Kcp/KcpNetClient.cs
index 1663058..c37b468 100644
--- a/Src/Core/Kcp/KcpNetClient.cs
+++ b/Src/Core/Kcp/KcpNetClient.cs
@@ -17,6 +17,7 @@ using BITKit.Net.Examples;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Unity.Mathematics;
+using UnityEngine;
namespace BITKit.Net
{
@@ -132,7 +133,7 @@ namespace BITKit.Net
{
if (IsConnecting)
{
- BIT4Log.Warning("正在连接中");
+ _logger.LogWarning("正在连接中");
return false;
}
_userConnected = true;
@@ -203,7 +204,7 @@ namespace BITKit.Net
}
catch (Exception e)
{
- BIT4Log.LogException(e);
+ _logger.LogCritical(e,e.Message);
if (BITApp.SynchronizationContext is not null)
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
OnConnectedFailed?.Invoke();
@@ -223,7 +224,7 @@ namespace BITKit.Net
}
catch (Exception e)
{
- BIT4Log.LogException(e);
+ _logger.LogCritical(e,e.Message);
}
}
private async void OnDataInternel(ArraySegment bytes, KcpChannel channel)
@@ -255,7 +256,7 @@ namespace BITKit.Net
}
catch (Exception e)
{
- BIT4Log.LogException(e);
+ _logger.LogCritical(e,e.Message);
}
break;
@@ -270,7 +271,11 @@ namespace BITKit.Net
Ping = (int)(DateTime.Now - _lastPingTime).TotalMilliseconds;
break;
case NetCommandType.ReturnToClient:
+
var id = reader.ReadInt32();
+
+
+
try
{
if (reader.ReadBoolean())
@@ -281,13 +286,14 @@ namespace BITKit.Net
else
{
var message = reader.ReadString();
+
_p2p.TryAdd(id,new Exception(message));
}
}
catch (Exception e)
{
- BIT4Log.Warning($"请求返回失败:{id}");
- BIT4Log.LogException(e);
+ _logger.LogWarning($"请求返回失败:{id}");
+ _logger.LogCritical(e,e.Message);
}
break;
case NetCommandType.GetFromClient:
@@ -327,9 +333,9 @@ namespace BITKit.Net
value = methodInfo.Invoke(handle, pars);
}
}
- catch (Exception e)
+ catch (Exception)
{
- BIT4Log.Warning(path);
+ _logger.LogWarning(path);
throw;
}
@@ -369,7 +375,7 @@ namespace BITKit.Net
}
catch (Exception e)
{
- BIT4Log.LogException(e);
+ _logger.LogCritical(e,e.Message);
returnWriter.Write(false);
returnWriter.Write(e.Message);
}
@@ -379,7 +385,7 @@ namespace BITKit.Net
}
catch(Exception e)
{
- BIT4Log.LogException(e);
+ _logger.LogCritical(e,e.Message);
}
break;
case NetCommandType.AllRpc:
@@ -419,13 +425,12 @@ namespace BITKit.Net
reportBuilder.AppendLine($"参数{parameter.GetType()}类型匹配:{parameterInfo.ParameterType}");
}
}
-
- BIT4Log.Warning(reportBuilder);
+ _logger.LogWarning(reportBuilder.ToString());
throw;
}
catch (Exception e)
{
- BIT4Log.Warning(rpcName);
+ _logger.LogWarning(rpcName);
throw;
}
@@ -439,6 +444,7 @@ namespace BITKit.Net
if (eventDelegate is null)
{
+
//BIT4Log.Warning($"未找到对应的事件:{rpcName}");
}
else
@@ -451,14 +457,13 @@ namespace BITKit.Net
}
else
{
-
-
- BIT4Log.Warning($"未找到对应的Rpc方法:{rpcName}");
+
+ _logger.LogWarning($"未找到对应的Rpc方法:{rpcName}");
}
}
break;
default:
- _logger.LogInformation($"未知消息类型:{type},字节:{(byte)type}");
+ _logger.LogWarning($"未知消息类型:{type},字节:{(byte)type}");
if (bytes.Array != null)
_logger.LogInformation(
$"已收到:({Id}, {BitConverter.ToString(bytes.Array, bytes.Offset, bytes.Count)} @ {channel})");
@@ -553,7 +558,6 @@ namespace BITKit.Net
}
if ((_now - startTime).TotalSeconds > RpcTimeOut)
{
- await BITApp.SwitchToMainThread();
if (string.IsNullOrEmpty(path))
{
throw new TimeoutException("请求超时或已断开连接");
@@ -561,7 +565,6 @@ namespace BITKit.Net
}
throw new TimeoutException($"请求超时或已断开连接,请求为{path}");
}
-
if (_p2p.TryRemove(id, out var value))
{
@@ -696,7 +699,7 @@ namespace BITKit.Net
{
if (DateTime.Now - _lastHeartbeat > TimeSpan.FromSeconds(5))
{
- BIT4Log.Warning("心跳超时,自动断开");
+ _logger.LogWarning("心跳超时,自动断开");
DisconnectInternal();
_commandQueue.Clear();
return;
@@ -728,7 +731,7 @@ namespace BITKit.Net
}
catch (Exception e)
{
- BIT4Log.LogException(e);
+ _logger.LogCritical(e,e.Message);
}
}
diff --git a/Src/Core/Kcp/KcpNetServer.cs b/Src/Core/Kcp/KcpNetServer.cs
index 01c13d0..246938c 100644
--- a/Src/Core/Kcp/KcpNetServer.cs
+++ b/Src/Core/Kcp/KcpNetServer.cs
@@ -62,7 +62,7 @@ namespace BITKit.Net
KCPNet.Config
);
_timer.Elapsed += Tick;
- BIT4Log.Log("已创建KCP服务器");
+ //BIT4Log.Log("已创建KCP服务器");
AddCommandListener(F);
diff --git a/Src/Core/Mod/ModService.cs b/Src/Core/Mod/ModService.cs
index ec23a06..7aa0f43 100644
--- a/Src/Core/Mod/ModService.cs
+++ b/Src/Core/Mod/ModService.cs
@@ -130,10 +130,6 @@ namespace BITKit.Mod
{
public static async UniTask SearchPackages()
{
- //Todo
- IUXWaiting waiting = null;
- var handle = waiting?.Get();
- handle?.SetMessage("正在搜索Mod包");
var list=new List();
var path = Path.Combine(Environment.CurrentDirectory, "Mods");
@@ -149,7 +145,6 @@ namespace BITKit.Mod
list.Add(package);
}
- waiting?.Release(handle);
return list.ToArray();
}
public static async UniTask Reload()
@@ -184,16 +179,7 @@ namespace BITKit.Mod
public static IMod[] Mods { get; private set; }=Array.Empty();
- public static bool IsLocked
- {
- get => _IsLocked;
- set
- {
- if (_IsLocked == value) return;
- _IsLocked = value;
- OnLocked?.Invoke(value);
- }
- }
+ public static readonly ValidHandle IsBusy = new();
public static event Action OnPackageLoad;
public static event Action OnPackageLoaded;
@@ -207,179 +193,72 @@ namespace BITKit.Mod
public static event Action OnReload;
public static event Action OnReloaded;
-
- public static event Action OnLocked;
public static event Func OnModLoadAsync;
public static event Func OnModUnloadAsync;
private static CancellationTokenSource _CancellationTokenSource;
- private static readonly ConcurrentQueue _RegisterQueue=new();
- private static readonly ConcurrentQueue _UnRegisterQueue = new();
- private static readonly List _CacheMods = new();
private static readonly ConcurrentDictionary _InstalledMods=new();
- private static Thread _Thread;
- private static bool _IsRunning;
- private static bool _IsLocked;
- public static void Initialize()
+ public static async UniTask Initialize()
{
BIT4Log.Log("Mod服务已启动");
- _IsRunning = true;
_CancellationTokenSource = new CancellationTokenSource();
- _Thread = new Thread(InternalInitialize);
- _Thread.Start();
- return;
-
- async void InternalInitialize()
+ try
{
+
+
+
try
{
-
-
-
- try
+ var modPath = Path.Combine(Environment.CurrentDirectory, "Mods\\");
+ PathHelper.EnsureDirectoryCreated(modPath);
+ var directoryInfo = new DirectoryInfo(modPath);
+ foreach (var fileInfo in directoryInfo.GetFiles())
{
- var modPath = Path.Combine(Environment.CurrentDirectory, "Mods\\");
- PathHelper.EnsureDirectoryCreated(modPath);
- var directoryInfo = new DirectoryInfo(modPath);
- foreach (var fileInfo in directoryInfo.GetFiles())
+ switch (fileInfo.Extension)
{
- switch (fileInfo.Extension)
+ case ".dll":
{
- case ".dll":
- {
- var assembly = Assembly.LoadFile(fileInfo.FullName);
- await Load(assembly);
- continue;
- }
+ var assembly = Assembly.LoadFile(fileInfo.FullName);
+ await Load(assembly);
+ continue;
+ }
#if UNITY_5_3_OR_NEWER
- case ".cs":
- {
- var code = await File.ReadAllTextAsync(fileInfo.FullName);
- var assembly = BITSharp.Compile(code);
- await Load(assembly, fileInfo.DirectoryName);
- continue;
- }
-#endif
- }
- }
-
- }
- catch (Exception e)
- {
- BIT4Log.Warning("自动加载Mod失败");
- BIT4Log.LogException(e);
- }
-
-
- while (_IsRunning)
- {
- //todo
- IUXWaiting waiting = null;
-
- _CacheMods.Clear();
-
- while (_UnRegisterQueue.TryDequeue(out var mod))
- {
- var handle = waiting?.Get();
- handle?.SetMessage($":正在卸载{mod.PackageName}");
-
- mod.OnDispose();
- _CacheMods.Add(mod);
- OnModUnLoad?.Invoke(mod);
-
- waiting?.Release(handle);
- }
-
- foreach (var mod in _CacheMods)
- {
- await mod.OnDisposeAsync(_CancellationTokenSource.Token);
- foreach (var x in OnModUnloadAsync.CastAsFunc())
+ case ".cs":
{
- await x.Invoke(mod);
+ var code = await File.ReadAllTextAsync(fileInfo.FullName);
+ var assembly = BITSharp.Compile(code);
+ await Load(assembly, fileInfo.DirectoryName);
+ continue;
}
- }
-
- foreach (var mod in _CacheMods)
- {
- mod.OnDisposed();
- OnModUnLoaded?.Invoke(mod);
- BIT4Log.Log($"卸载Mod:{mod.GetType().FullName}");
- }
-
- _CacheMods.Clear();
-
- while (_RegisterQueue.TryDequeue(out var mod))
- {
- var handle = waiting?.Get();
-
- handle?.SetMessage($"正在加载:{mod.PackageName}");
-
- _CacheMods.Add(mod);
- mod.OnInitialize();
- OnModLoad?.Invoke(mod);
- BIT4Log.Log($"加载Mod:{mod.GetType().FullName}");
-
- waiting?.Release(handle);
- }
-
- foreach (var mod in _CacheMods)
- {
- var handle = waiting?.Get();
- handle?.SetMessage($"正在初始化:{mod.PackageName}");
-
- await mod.OnInitializedAsync(_CancellationTokenSource.Token);
- foreach (var x in OnModLoadAsync.CastAsFunc())
- {
- await x.Invoke(mod);
- }
-
- waiting?.Release(handle);
- }
-
- foreach (var mod in _CacheMods)
- {
- var handle = waiting?.Get();
- handle?.SetMessage($":正在完成初始化中{mod.PackageName}");
-
- mod.OnInitialized();
- OnModLoaded?.Invoke(mod);
-
- waiting?.Release(handle);
- }
-
- _CacheMods.Clear();
-
-
- //Thread.Sleep(1000);
-#if UNITY_5_3_OR_NEWER
- await UniTask.Delay(1000);
-#else
- await Task.Delay(1000);
#endif
- IsLocked = false;
+ }
}
- BIT4Log.Log("Mod服务已停止");
}
catch (Exception e)
{
+ BIT4Log.Warning("自动加载Mod失败");
BIT4Log.LogException(e);
- BIT4Log.Warning("Mod服务遇到了错误,已停止");
}
+
}
+ catch (Exception e)
+ {
+ BIT4Log.LogException(e);
+ BIT4Log.Warning("Mod服务遇到了错误,已停止");
+ }
+
+
}
public static void Dispose()
- {_IsRunning = false;
+ {
_CancellationTokenSource.Cancel();
try
{
- _Thread.Join(100);
- _RegisterQueue.Clear();
- _UnRegisterQueue.Clear();
Mods = Array.Empty();
_InstalledMods.Clear();
}
@@ -387,8 +266,9 @@ namespace BITKit.Mod
{
BIT4Log.LogException(e);
}
-
+
}
+
public static UniTask Load(Assembly assembly,string folderPath=null)
{
BIT4Log.Log($"加载程序集:{assembly.FullName}");
@@ -480,20 +360,35 @@ namespace BITKit.Mod
}
OnPackageLoaded?.Invoke(package);
}
- public static void Load(IMod mod)
+ public static async UniTask Load(IMod mod)
{
- IsLocked = true;
- _RegisterQueue.Enqueue(mod);
+ mod.OnInitialize();
+ OnModLoad?.Invoke(mod);
+ BIT4Log.Log($"加载Mod:{mod.GetType().FullName}");
}
- public static void UnLoad(IMod mod)
+ public static async UniTask UnLoad(IMod mod)
{
- IsLocked = true;
- _UnRegisterQueue.Enqueue(mod);
+ mod.OnDispose();
+ OnModUnLoad?.Invoke(mod);
+
+ await mod.OnDisposeAsync(_CancellationTokenSource.Token);
+ foreach (var x in OnModUnloadAsync.CastAsFunc())
+ {
+ await x.Invoke(mod);
+ }
+
+ mod.OnDisposed();
+ OnModUnLoaded?.Invoke(mod);
+ BIT4Log.Log($"卸载Mod:{mod.GetType().FullName}");
}
- public static void Install(IMod mod)
+ public static async void Install(IMod mod)
{
+ await IsBusy;
+
+ using var _ = IsBusy.GetHandle();
+
if (_InstalledMods.ContainsKey(mod.PackageName))
{
throw new ArgumentException("Mod已安装");
@@ -501,9 +396,21 @@ namespace BITKit.Mod
_InstalledMods.TryAdd(mod.PackageName,mod);
Mods = _InstalledMods.Values.ToArray();
OnModInstalled?.Invoke(mod);
+
+ await mod.OnInitializedAsync(_CancellationTokenSource.Token);
+ foreach (var x in OnModLoadAsync.CastAsFunc())
+ {
+ await x.Invoke(mod);
+ }
+
+ mod.OnInitialized();
+ OnModLoaded?.Invoke(mod);
}
public static void UnInstall(IMod mod)
{
+ using var _ = IsBusy.GetHandle();
+
+
if(_InstalledMods.ContainsKey(mod.PackageName) is false) return;
_InstalledMods.TryRemove(mod.PackageName);
Mods = _InstalledMods.Values.ToArray();
diff --git a/Src/Core/Sharp/BITSharp.cs b/Src/Core/Sharp/BITSharp.cs
index 96a70af..3161fa2 100644
--- a/Src/Core/Sharp/BITSharp.cs
+++ b/Src/Core/Sharp/BITSharp.cs
@@ -66,12 +66,6 @@ namespace BITKit
{
var outputPath = PathHelper.GetTempFilePath();
- //DI.TryGet(out var waiting);
- //todo
- IUXWaiting waiting = null;
-
- var handle = waiting?.Get();
- handle?.SetMessage("正在编译");
try
{
if (Installed is false)
@@ -125,7 +119,7 @@ namespace BITKit
// CreateNoWindow = false,
// };
- var StartInfo = new ProcessStartInfo
+ var startInfo = new ProcessStartInfo
{
//FileName = MCSPath,
FileName = "dotnet",
@@ -142,7 +136,7 @@ namespace BITKit
var process = new Process()
{
- StartInfo = StartInfo,
+ StartInfo = startInfo,
};
var reportBuilder = new StringBuilder();
process.OutputDataReceived += (sender, args) =>
@@ -184,14 +178,10 @@ namespace BITKit
BIT4Log.Log(reportBuilder);
- waiting?.Release(handle);
-
return Assembly.Load(bytes);
}
catch (Exception e)
{
- waiting?.Release(handle);
-
throw new Exception($"编译失败:{e}");
}
diff --git a/Src/Core/Ticker/ITicker.cs b/Src/Core/Ticker/ITicker.cs
index f6820aa..aeb78e1 100644
--- a/Src/Core/Ticker/ITicker.cs
+++ b/Src/Core/Ticker/ITicker.cs
@@ -103,10 +103,11 @@ namespace BITKit
if (IsSyncContext)
{
await BITApp.SwitchToMainThread();
-
#if UNITY_EDITOR
+ await BITApp.SwitchToMainThread();
if (UnityEditor.EditorApplication.isPaused)
{
+ _timer.Interval = 1000d / TickRate;
_timer.Start();
return;
}
@@ -164,12 +165,19 @@ namespace BITKit
TickCount++;
if(_isDisposed)return;
+ _timer.Interval = 1000d / TickRate;
_timer.Start();
}
public bool IsSyncContext { get; set; } = true;
public ulong TickCount { get; set; }
- public int TickRate { get; set; }
+
+ public int TickRate
+ {
+ get => _tickRate;
+ set => _tickRate = Math.Clamp(value, 1, int.MaxValue);
+ }
+ private int _tickRate;
public bool IsConcurrent { get; set; }
public event Func OnTickAsync;
diff --git a/Src/Core/UX/IUXService.cs b/Src/Core/UX/IUXService.cs
index 74fcaa9..b2c4724 100644
--- a/Src/Core/UX/IUXService.cs
+++ b/Src/Core/UX/IUXService.cs
@@ -8,6 +8,7 @@ namespace BITKit.UX
///
public interface IUXService:IDisposable
{
+ public string SettingsPath { get; set; }
object Root { get; }
///
/// 初始化
diff --git a/Src/Core/Utility/ValidHandle.cs b/Src/Core/Utility/ValidHandle.cs
index 6703cb8..be4f52c 100644
--- a/Src/Core/Utility/ValidHandle.cs
+++ b/Src/Core/Utility/ValidHandle.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
@@ -87,7 +88,7 @@ namespace BITKit
public readonly List
public static void ClearHistory() => History.Clear();
+ public string SettingsPath { get; set; } = "ux_panel_settings";
public object Root { get; private set; }
public async UniTask InitializeAsync()
{
@@ -86,7 +87,7 @@ Object.Destroy(gameObject);
var document = gameObject.AddComponent();
try
{
- var panelSettings =await ModService.LoadAsset("ux_panel_settings");
+ var panelSettings =await ModService.LoadAsset(SettingsPath);
document.panelSettings = panelSettings;
}
catch (Exception e)
diff --git a/Src/Unity/Scripts/UX/Waiting/UXWaiting.cs b/Src/Unity/Scripts/UX/Waiting/UXWaiting.cs
index 621afd9..1bfd894 100644
--- a/Src/Unity/Scripts/UX/Waiting/UXWaiting.cs
+++ b/Src/Unity/Scripts/UX/Waiting/UXWaiting.cs
@@ -102,7 +102,16 @@ namespace BITKit
handle.VisualElement.RemoveFromHierarchy();
_visibleHandle.RemoveElement(handle);
}
- _visibleHandle.Invoke();
+
+ try
+ {
+ _visibleHandle.Invoke();
+ }
+ catch (Exception e)
+ {
+ Debug.LogException(e);
+ }
+
}
public override async UniTask InitializeAsync()
@@ -116,6 +125,8 @@ namespace BITKit
UXUtils.Inject(this);
_container.Clear();
+
+ _visibleHandle.Invoke();
_initializationState = InitializationState.Initialized;
}
diff --git a/Src/Unity/Scripts/Utility/Extensions.cs b/Src/Unity/Scripts/Utility/Extensions.cs
index 2429962..f40ec6c 100644
--- a/Src/Unity/Scripts/Utility/Extensions.cs
+++ b/Src/Unity/Scripts/Utility/Extensions.cs
@@ -714,5 +714,48 @@ namespace BITKit
self.SetOpacity(visible ? 1 : 0);
}
+
+ public static void ClearTooltipsOnPointerLeave(this VisualElement visualElement)
+ {
+ visualElement.RegisterCallback(OnLeave);
+ return;
+
+ void OnLeave(PointerLeaveEvent evt)
+ {
+ if (string.IsNullOrEmpty(visualElement.tooltip) is false)
+ visualElement.tooltip = string.Empty;
+ }
+ }
+
+ public static void BlinkingCursor(this TextField tf,int interval=1000)
+ {
+ tf.schedule.Execute(() =>
+ {
+ if(tf.ClassListContains("transparentCursor"))
+ tf.RemoveFromClassList("transparentCursor");
+ else
+ tf.AddToClassList("transparentCursor");
+ }).Every(interval);
+ }
+ public static Vector2 GetAbsolutePositionInUI(this VisualElement element)
+ {
+var position = Vector2.zero;
+ var currentElement = element;
+
+ // 遍历每一个父元素,并累计位置
+ while (currentElement != null)
+ {
+ var style = currentElement.resolvedStyle;
+
+ // 累加该元素相对于父元素的位置
+ position.x += style.left;
+ position.y += style.top;
+
+ // 移动到父元素
+ currentElement = currentElement.parent;
+ }
+
+ return position;
+ }
}
}
\ No newline at end of file
diff --git a/Src/Unity/UX/Common/Common.asset b/Src/Unity/UX/Common/Common.asset
index b270384..3acee11 100644
--- a/Src/Unity/UX/Common/Common.asset
+++ b/Src/Unity/UX/Common/Common.asset
@@ -21,7 +21,7 @@ MonoBehaviour:
m_FallbackDpi: 96
m_ReferenceResolution: {x: 1920, y: 1080}
m_ScreenMatchMode: 0
- m_Match: 0.421
+ m_Match: 0.5
m_SortingOrder: 0
m_TargetDisplay: 0
m_ClearDepthStencil: 1
diff --git a/Src/Unity/UX/Common/Common.uss b/Src/Unity/UX/Common/Common.uss
index e0f3f8a..e024962 100644
--- a/Src/Unity/UX/Common/Common.uss
+++ b/Src/Unity/UX/Common/Common.uss
@@ -93,6 +93,37 @@ TabBar Button:disabled {
margin-left: 32px;
}
+.gap-8 {
+ margin-top: -8px;
+ margin-right: -8px;
+ margin-bottom: -8px;
+ margin-left: -8px;
+}
+
+.gap-8 > * {
+ margin: 8px;
+}
+
+.gap-x-8 {
+ margin-right: -8px;
+ margin-left: -8px;
+}
+
+.gap-x-8 > * {
+ margin-left: 8px;
+ margin-right: 8px;
+}
+
+.gap-y-8 {
+ margin-top: -8px;
+ margin-bottom: -8px;
+}
+
+.gap-y-8 > * {
+ margin-top: 8px;
+ margin-bottom: 8px;
+}
+
.r-8 {
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
@@ -473,3 +504,7 @@ Button.clear {
border-top-color: rgba(0, 0, 0, 0);
border-bottom-color: rgba(0, 0, 0, 0);
}
+
+TabContainer > * {
+ flex-grow: 1;
+}
diff --git a/Src/Unity/UX/ux_mod_Service.uxml b/Src/Unity/UX/ux_mod_Service.uxml
index 796c6b1..31c87d5 100644
--- a/Src/Unity/UX/ux_mod_Service.uxml
+++ b/Src/Unity/UX/ux_mod_Service.uxml
@@ -1,5 +1,5 @@
-
+
@@ -31,12 +31,13 @@
-
+
+
diff --git a/Src/UnityEditor/TMPFontCheckWindow.cs b/Src/UnityEditor/TMPFontCheckWindow.cs
new file mode 100644
index 0000000..63cbd47
--- /dev/null
+++ b/Src/UnityEditor/TMPFontCheckWindow.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+using UnityEditor;
+using UnityEditor.UIElements;
+using UnityEngine;
+using UnityEngine.TextCore.Text;
+using UnityEngine.UIElements;
+
+namespace BITKit.GameEditor
+{
+ public class TMPFontCheck : EditorWindow
+ {
+ public static FontAsset CurrentFont;
+ [MenuItem("Tools/TextMeshPro Font Check")]
+ public static void ShowExample()
+ {
+ GetWindow().Show();
+ }
+ private void CreateGUI()
+ {
+ rootVisualElement.Clear();
+
+ var refreshButton = rootVisualElement.Create