Pārlūkot izejas kodu

[fix]: 修复 第一次登录如果错误 第二次过后就会失败的问题 (#576)

LiShengYang-yiyi 1 gadu atpakaļ
vecāks
revīzija
6235d00c4f

+ 6 - 0
Unity/Assets/Scripts/Hotfix/Client/Demo/Main/ClientSenderComponentSystem.cs

@@ -30,6 +30,12 @@ namespace ET.Client
             await FiberManager.Instance.Remove(fiberId);
         }
 
+        public static async ETTask DisposeClientSender(this ClientSenderComponent self)
+        {
+            await self.RemoveFiberAsync();
+            self.Dispose();
+        }
+
         public static async ETTask<long> LoginAsync(this ClientSenderComponent self, string account, string password)
         {
             self.fiberId = await FiberManager.Instance.Create(SchedulerType.ThreadPool, 0, SceneType.NetClient, "");

+ 5 - 3
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/LoginHelper.cs

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