From 000a079985cba24f7aa6ed5943a0294ded4a7b5d Mon Sep 17 00:00:00 2001
From: CortexCore <2630229280@qq.com>
Date: Sun, 12 Jan 2025 11:57:37 +0800
Subject: [PATCH] breakpoint
---
Src/Core/Applation/BITApp.cs | 7 +-
Src/Core/BITLog/BIT4Log.cs | 132 ++++++++++++++++++++---------------
Src/Core/Kcp/KcpNetClient.cs | 43 +++++++-----
Src/Core/Sharp/BITSharp.cs | 14 +---
4 files changed, 104 insertions(+), 92 deletions(-)
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/BITLog/BIT4Log.cs b/Src/Core/BITLog/BIT4Log.cs
index 2f333d2..aa26fe7 100644
--- a/Src/Core/BITLog/BIT4Log.cs
+++ b/Src/Core/BITLog/BIT4Log.cs
@@ -8,70 +8,92 @@ using UnityEngine;
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;
- OnNextLine = null;
- }
- #endif
- 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]
+#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)
- {
- if (OnLog is null)
- {
- BITApp.ServiceProvider.GetRequiredService>().LogInformation(x.ToString());
- }
- else
- {
- OnLog?.Invoke(x?.ToString());
- }
- }
+ 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)
- {
- if (OnLog is null)
- {
- BITApp.ServiceProvider.GetRequiredService>().LogInformation(x.ToString());
- }
- else
- {
- OnLog?.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(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/Kcp/KcpNetClient.cs b/Src/Core/Kcp/KcpNetClient.cs
index df21905..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})");
@@ -694,7 +699,7 @@ namespace BITKit.Net
{
if (DateTime.Now - _lastHeartbeat > TimeSpan.FromSeconds(5))
{
- BIT4Log.Warning("心跳超时,自动断开");
+ _logger.LogWarning("心跳超时,自动断开");
DisconnectInternal();
_commandQueue.Clear();
return;
@@ -726,7 +731,7 @@ namespace BITKit.Net
}
catch (Exception e)
{
- BIT4Log.LogException(e);
+ _logger.LogCritical(e,e.Message);
}
}
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}");
}