diff --git a/Src/Core/BITLog/BIT4Log.cs b/Src/Core/BITLog/BIT4Log.cs index 8c35e84..94d784d 100644 --- a/Src/Core/BITLog/BIT4Log.cs +++ b/Src/Core/BITLog/BIT4Log.cs @@ -8,7 +8,7 @@ namespace BITKit { public static class BIT4Log { - #if UNITY_EDITOR && UNITY_64 + #if UNITY_EDITOR && UNITY_5_3_OR_NEWER [RuntimeInitializeOnLoadMethod] private static void Reload() { diff --git a/Src/Core/Kcp/KcpNetClient.cs b/Src/Core/Kcp/KcpNetClient.cs index 23a5ad0..029f691 100644 --- a/Src/Core/Kcp/KcpNetClient.cs +++ b/Src/Core/Kcp/KcpNetClient.cs @@ -242,7 +242,7 @@ namespace BITKit.Net else { returnWriter.Write(false); - returnWriter.Write("未找到对应的Rpc方法"); + returnWriter.Write($"未找到对应的Rpc方法:{path}"); } } else diff --git a/Src/Core/Kcp/KcpNetServer.cs b/Src/Core/Kcp/KcpNetServer.cs index 3b7d716..72568fb 100644 --- a/Src/Core/Kcp/KcpNetServer.cs +++ b/Src/Core/Kcp/KcpNetServer.cs @@ -66,6 +66,10 @@ namespace BITKit.Net if (server.IsActive() is false || ManualTick) return; server.Tick(); } + catch (SocketException) + { + //丢失链接,有用户断开连接,通常是正常现象 + } catch (Exception exception) { BIT4Log.LogException(exception); @@ -254,7 +258,7 @@ namespace BITKit.Net } else { - throw new Exception("未找到对应的Rpc方法"); + throw new Exception($"未找到对应的Rpc方法:{path}"); } } @@ -262,7 +266,8 @@ namespace BITKit.Net { var commandObj = BITBinary.Read(reader) .As()[0]; - if (_rpc.TryGetValue(commandObj.GetType()!.FullName!, out var func)) + var funcName = commandObj.GetType()!.FullName!; + if (_rpc.TryGetValue(funcName, out var func)) { var value = await func.As>>().Invoke(commandObj); returnWriter.Write(true); @@ -270,7 +275,7 @@ namespace BITKit.Net } else { - throw new Exception("未找到对应的Rpc方法"); + throw new Exception($"未找到对应的Rpc方法:{funcName}"); } } { @@ -471,7 +476,10 @@ namespace BITKit.Net .Write((byte)commandType) .WriteObject(values) .Build(); - server.Send(id,bytes, KcpChannel.Reliable); + if (server.connections.ContainsKey(id)) + { + server.Send(id,bytes, KcpChannel.Reliable); + } } } diff --git a/Src/Core/kcp2k/highlevel/KcpServer.cs b/Src/Core/kcp2k/highlevel/KcpServer.cs index 64b990c..cc4dea4 100644 --- a/Src/Core/kcp2k/highlevel/KcpServer.cs +++ b/Src/Core/kcp2k/highlevel/KcpServer.cs @@ -166,6 +166,8 @@ namespace kcp2k // the other end closing the connection is not an 'error'. // but connections should never just end silently. // at least log a message for easier debugging. + + //sure I go next somewhere record it Log.Info($"KcpServer: ReceiveFrom failed: {e}"); } diff --git a/Src/Unity/Scripts/UX/Alert/UXAlert.cs b/Src/Unity/Scripts/UX/Alert/UXAlert.cs index 16c0152..8ba554d 100644 --- a/Src/Unity/Scripts/UX/Alert/UXAlert.cs +++ b/Src/Unity/Scripts/UX/Alert/UXAlert.cs @@ -107,6 +107,8 @@ namespace BITKit.UX private Button _cancelButton; private void Start() { + destroyCancellationToken.Register(Dispose); + DI.Register(); UXUtils.Inject(this); @@ -114,8 +116,14 @@ namespace BITKit.UX Close(); } + private void Dispose() + { + } + internal void PrintAlertMessage(AlertMessage message) { + if(destroyCancellationToken.IsCancellationRequested)return; + document.rootVisualElement.SetActive(true); _titleLabel.text = message.title; _contextLabel.text = message.message; diff --git a/Src/Unity/Scripts/UX/Service/UXService.cs b/Src/Unity/Scripts/UX/Service/UXService.cs index 4dfd6cd..ebd133f 100644 --- a/Src/Unity/Scripts/UX/Service/UXService.cs +++ b/Src/Unity/Scripts/UX/Service/UXService.cs @@ -54,6 +54,11 @@ namespace BITKit.UX /// private static readonly Stack EntryQueue = new(); + /// + /// 返回面板缓冲区 + /// + private static readonly DoubleBuffer ReturnBuffer = new(); + /// /// 已启用面板 /// @@ -74,12 +79,11 @@ namespace BITKit.UX { if (History.TryPop(out var returnPanel)) { - Entry(returnPanel); + ReturnBuffer.Release(returnPanel); } } public static void Entry(IUXPanel panel) => EntryQueue.Push(panel); - public static void Entry(string panelName) => EntryQueue.Push(Panels[panelName]); [SerializeReference, SubclassSelector] private IUXPanel initialPanel; @@ -103,7 +107,7 @@ namespace BITKit.UX } private static void OnExit(IUXPanel obj) { - History.Push(obj); + //History.Push(obj); } private static void OnEntry(IUXPanel obj) { @@ -125,8 +129,16 @@ namespace BITKit.UX Panels.Remove(result.Index); } + if (ReturnBuffer.TryGetRelease(out var returnPanel)) + { + EntryGroup.Entry(x=>x.Index==returnPanel.Index); + BITAppForUnity.AllowCursor.SetElements(this, returnPanel.AllowCursor); + BITInputSystem.AllowInput.SetElements(this, returnPanel.AllowInput); + } + if (EntryQueue.TryPop(out var nextPanel)) { + History.Push(CurrentPanel); EntryGroup.Entry(x=>x.Index==nextPanel.Index); BITAppForUnity.AllowCursor.SetElements(this, nextPanel.AllowCursor); BITInputSystem.AllowInput.SetElements(this, nextPanel.AllowInput); @@ -136,38 +148,6 @@ namespace BITKit.UX { currentPanel.OnUpdate(Time.deltaTime); }; - - - // if (initialized is false && initialPanel is not null) - // { - // initialized = true; - // Entry(initialPanel); - // } - // - // if (!EntryQueue.TryPop(out var next) || next is null) return; - // - // if (Panels.ContainsKey(next.Index) is false) return; - // - // while (EntryCompletedPanels.TryPop(out var entryCompletedPanel)) - // { - // entryCompletedPanel?.Exit(); - // } - // - // try - // { - // next.Entry(); - // } - // catch (Exception e) - // { - // Debug.LogWarning(next.Index); - // Debug.LogException(e); - // } - // - // BITAppForUnity.AllowCursor.SetElements(this, next.AllowCursor); - // BITInputSystem.AllowInput.SetElements(this, next.AllowInput); - // - // EntryCompletedPanels.Push(next); - // History.Push(next); } void IUXService.Register(IUXPanel panel) => Register(panel); diff --git a/Src/Unity/Scripts/UX/Utils/UXUtils.cs b/Src/Unity/Scripts/UX/Utils/UXUtils.cs index d97219d..83bf2e3 100644 --- a/Src/Unity/Scripts/UX/Utils/UXUtils.cs +++ b/Src/Unity/Scripts/UX/Utils/UXUtils.cs @@ -8,6 +8,7 @@ using UnityEngine.UIElements; namespace BITKit.UX { + [AttributeUsage(AttributeTargets.Field|AttributeTargets.Property)] public class UXBindPathAttribute : Attribute { public string Path;