Просмотр исходного кода

修复一个大bug,由于Unity的响应回调比如按钮点击回调并不在任何Fiber,那么Unity的同步上下文应该在Fiber调度完成后重置。
该bug导致了很多用户发现登录的时候删除ClientSenderComponent会导致await无法返回。很多用户都是等一帧再创建来解决问题。

tanghai 1 год назад
Родитель
Сommit
30cca7c6f8

+ 6 - 0
Unity/Assets/Scripts/Core/World/Module/Fiber/MainThreadScheduler.cs

@@ -54,6 +54,9 @@ namespace ET
                 
                 
                 this.idQueue.Enqueue(id);
                 this.idQueue.Enqueue(id);
             }
             }
+            
+            // Fiber调度完成,要还原成默认的上下文,否则unity的回调会找不到正确的上下文
+            SynchronizationContext.SetSynchronizationContext(this.threadSynchronizationContext);
         }
         }
 
 
         public void LateUpdate()
         public void LateUpdate()
@@ -90,6 +93,9 @@ namespace ET
                 this.addIds.TryDequeue(out int result);
                 this.addIds.TryDequeue(out int result);
                 this.idQueue.Enqueue(result);
                 this.idQueue.Enqueue(result);
             }
             }
+            
+            // Fiber调度完成,要还原成默认的上下文,否则unity的回调会找不到正确的上下文
+            SynchronizationContext.SetSynchronizationContext(this.threadSynchronizationContext);
         }
         }
 
 
 
 

+ 2 - 6
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/LoginHelper.cs

@@ -4,13 +4,9 @@ namespace ET.Client
     {
     {
         public static async ETTask Login(Scene root, string account, string password)
         public static async ETTask Login(Scene root, string account, string password)
         {
         {
-            ClientSenderComponent clientSenderComponent = root.GetComponent<ClientSenderComponent>();
-            if (clientSenderComponent != null)
-            {
-                await clientSenderComponent.DisposeAsync();
-            }
+            root.RemoveComponent<ClientSenderComponent>();
             
             
-            clientSenderComponent = root.AddComponent<ClientSenderComponent>();
+            ClientSenderComponent clientSenderComponent = root.AddComponent<ClientSenderComponent>();
             
             
             long playerId = await clientSenderComponent.LoginAsync(account, password);
             long playerId = await clientSenderComponent.LoginAsync(account, password);
 
 

+ 0 - 35
Unity/Assets/Scripts/ThirdParty/Recast/Recast.cs

@@ -1,35 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace ET
-{
-    public static class Recast
-    {
-#if UNITY_IPHONE && !UNITY_EDITOR
-        const string RecastDLL = "__Internal";
-#else
-        const string RecastDLL = "RecastDll";
-#endif
-        public const int MAX_POLYS = 256;
-        
-        [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern IntPtr RecastLoad(byte[] buffer, int n);
-        
-        [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern void RecastClear(IntPtr navPtr);
-        
-        [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFind(IntPtr navPtr, float[] extents, float[] startPos, float[] endPos, float[] straightPath);
-        
-        
-        [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFindNearestPoint(IntPtr navPtr, float[] extents, float[] pos, float[] nearestPos);
-
-        
-        [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFindRandomPointAroundCircle(IntPtr navPtr, float[] extents, float[] centerPos, float radius, float[] randomPos);
-        
-        [DllImport(RecastDLL, CallingConvention=CallingConvention.Cdecl)]
-        public static extern int RecastFindRandomPoint(IntPtr navPtr, float[] randomPos);
-    }
-}

+ 0 - 11
Unity/Assets/Scripts/ThirdParty/Recast/Recast.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 14567fd01a0bc7b438d6579e38a9cfc4
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: