lvjincheng il y a 4 ans
Parent
commit
8e64a4b487

+ 3 - 0
Assets/BowArrow/Scripts/Manager/GameMode/PKGameMode_OnlinePK.cs

@@ -157,6 +157,9 @@ public class PKGameMode_OnlinePK : GameMode {
         }
         upload2();
         gameDisplay.Update(this);
+        if (this.gameLogic.gameEnd) {
+            socketPlayer.canBackHome = false;
+        }
     }
     Dictionary<int, ArrowSync> arrowSyncMap = new Dictionary<int, ArrowSync>();
     void upload1() {

+ 6 - 0
Assets/BowArrow/Scripts/Network/SocketPlayer.cs

@@ -45,9 +45,15 @@ public class SocketPlayer : JC.SocketIO.SocketIOClient
     {
         Debug.Log("onReload");
     }
+    public Action onDestroy_;
+    [NonSerialized] public bool canBackHome = true;
     public override void onDestroy()
     {
         Debug.Log("onDestroy");
+        onDestroy_?.Invoke();
+        if (canBackHome && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("Game")) {
+            SceneManager.LoadScene("Home", LoadSceneMode.Single);
+        }
     }
     public override void onMiss()
     {

+ 18 - 3
Assets/BowArrow/Scripts/View/PKMatchingView.cs

@@ -43,9 +43,11 @@ public class PKMatchingView : MonoBehaviour
         };
         socketPlayer.onAgreeStartGame = () => {
             DontDestroyOnLoad(socketPlayer);
-            if (GlobalData.matchRoomType == 0) {
-                GameMgr.gameType = 9;
-                SceneManager.LoadScene("Game", LoadSceneMode.Single);
+            toLoadGame = true;
+        };
+        socketPlayer.onDestroy_ += () => {
+            if (this && this.gameObject) {
+                DestroyImmediate(this.gameObject);
             }
         };
     }
@@ -70,11 +72,24 @@ public class PKMatchingView : MonoBehaviour
         };
     }
 
+    bool toLoadGame = false;
+    float loadGameSceneCountdown = 1;
     void Update() {
         if (waitingTime >= 0) {
             waitingTime += Time.deltaTime;
             this.transform.Find("BoxRight/TimeBG").GetComponentInChildren<Text>().text = TimeUtil.GetTimeStr(waitingTime, false);
         }
+        if (toLoadGame) {
+            loadGameSceneCountdown -= Time.deltaTime;
+            if (loadGameSceneCountdown <= 0) {
+                toLoadGame = false;
+                //loadscene
+                if (GlobalData.matchRoomType == 0) {
+                    GameMgr.gameType = 9;
+                    SceneManager.LoadScene("Game", LoadSceneMode.Single);
+                }
+            }
+        }
     }
 
     void PauseWaitingTime() {