diff --git a/BITKit.csproj b/BITKit.csproj index 12370d8..56abe9b 100644 --- a/BITKit.csproj +++ b/BITKit.csproj @@ -38,7 +38,7 @@ - + diff --git a/Src/Core/Binary/BITBinary.cs b/Src/Core/Binary/BITBinary.cs index b143b61..5997070 100644 --- a/Src/Core/Binary/BITBinary.cs +++ b/Src/Core/Binary/BITBinary.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Text; using Cysharp.Threading.Tasks; +using MemoryPack; using Microsoft.SqlServer.Server; #if NET5_0_OR_GREATER using Microsoft.SqlServer.Server; @@ -107,22 +108,27 @@ namespace BITKit return instance; } - var json = reader.ReadString(); - if (string.IsNullOrEmpty(json)) + if (BITSharp.TryGetTypeFromFullName(typeName, out type)) { - throw new Exception($"从二进制中读取的json值为空"); + return MemoryPackSerializer.Deserialize(type, reader.ReadBytes(reader.ReadInt32())); } - try - { - if (BITSharp.TryGetTypeFromFullName(typeName, out type)) - return JsonConvert.DeserializeObject(json, type); - } - catch (Exception e) - { - BIT4Log.Warning($"反序列化失败,类型:{typeName},值:\n{json}"); - BIT4Log.LogException(e); - } + // var json = reader.ReadString(); + // if (string.IsNullOrEmpty(json)) + // { + // throw new Exception($"从二进制中读取的json值为空"); + // } + // + // try + // { + // if (BITSharp.TryGetTypeFromFullName(typeName, out type)) + // return JsonConvert.DeserializeObject(json, type); + // } + // catch (Exception e) + // { + // BIT4Log.Warning($"反序列化失败,类型:{typeName},值:\n{json}"); + // BIT4Log.LogException(e); + // } throw new Exception("未找到读取该二进制的BinaryReader"); } @@ -172,7 +178,11 @@ namespace BITKit { try { - writer.Write(JsonConvert.SerializeObject(value)); + var bytes = MemoryPackSerializer.Serialize(value.GetType(),value); + writer.Write(bytes.Length); + writer.Write(bytes); + + //writer.Write(JsonConvert.SerializeObject(value)); } catch (Exception) { diff --git a/Src/Core/Kcp/KcpNetClient.cs b/Src/Core/Kcp/KcpNetClient.cs index c37b468..66ca6d3 100644 --- a/Src/Core/Kcp/KcpNetClient.cs +++ b/Src/Core/Kcp/KcpNetClient.cs @@ -17,7 +17,6 @@ using BITKit.Net.Examples; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Unity.Mathematics; -using UnityEngine; namespace BITKit.Net { diff --git a/Src/Core/Net/Commands/NetClientAllocateIdCommand.cs b/Src/Core/Net/Commands/NetClientAllocateIdCommand.cs index 5aaee96..6c0c536 100644 --- a/Src/Core/Net/Commands/NetClientAllocateIdCommand.cs +++ b/Src/Core/Net/Commands/NetClientAllocateIdCommand.cs @@ -1,6 +1,9 @@ +using MemoryPack; + namespace BITKit.Net.Examples { - public struct NetClientAllocateIdCommand + [MemoryPackable] + public partial struct NetClientAllocateIdCommand { public int Id; public string Ip; diff --git a/Src/Core/StateMachine/AsyncStateMachine.cs b/Src/Core/StateMachine/AsyncStateMachine.cs index 98c4458..b581c0b 100644 --- a/Src/Core/StateMachine/AsyncStateMachine.cs +++ b/Src/Core/StateMachine/AsyncStateMachine.cs @@ -64,8 +64,11 @@ namespace BITKit.StateMachine if(_cancellationTokenSource.IsCancellationRequested)return; if (CurrentState is null) return; using var _ = IsBusy.GetHandle(); + if (CurrentState is not null) + { + CurrentState.Enabled = false; + } await CurrentState.OnStateExitAsync(CurrentState, null); - if(_cancellationTokenSource.IsCancellationRequested)return; CurrentState.OnStateExit(CurrentState, null); CurrentState = null; } diff --git a/Src/Unity/Scripts/Assets/BITFramework.cs b/Src/Unity/Scripts/Assets/BITFramework.cs index 0ffbe94..8510616 100644 --- a/Src/Unity/Scripts/Assets/BITFramework.cs +++ b/Src/Unity/Scripts/Assets/BITFramework.cs @@ -6,6 +6,7 @@ using System.IO; using BITKit.IO; using BITKit.UX; using Cysharp.Threading.Tasks; +using UnityEditorInternal; using UnityEngine; using UnityEngine.Events; using UnityEngine.Rendering; diff --git a/Src/Unity/UX/Common/Common.uss b/Src/Unity/UX/Common/Common.uss index e024962..30dc58d 100644 --- a/Src/Unity/UX/Common/Common.uss +++ b/Src/Unity/UX/Common/Common.uss @@ -508,3 +508,21 @@ Button.clear { TabContainer > * { flex-grow: 1; } + +.transition_entry { + opacity: 0; +} + +.transition_entry_async { + opacity: 1; + transition-duration: 0.1s; +} + +.transition_exit { + opacity: 1; +} + +.transition_exit_async { + opacity: 0; + transition-duration: 0.1s; +}