Browse Source

主页使用临时全局数据

lvjincheng 3 years ago
parent
commit
8459ae40cb

+ 8 - 0
Assets/BowArrow/Scripts/GlobalData.cs

@@ -14,6 +14,14 @@ public class GlobalData
     public static int playerIndexInRoom;
     public static List<MatchPlayerInfo> matchPlayerInfos;
 }
+/**接收别人的PK邀请时,会设置GlobalData的数据,如果这时候主页存在层级页面,接收PK邀请但又突然要返回,
+这时候层级页面设置过的GlobalData可能会被好友邀请修改过,因此主页用GlobalDataTemp存储可能会被干涉的数据,
+在最后一步才把GlobalDataTemp数据赋值给GlobalData */
+public class GlobalDataTemp
+{
+    public static PKMatchType pkMatchType = PKMatchType.None;
+    public static int matchRoomType = 0; //Pk匹配房间类型
+}
 public enum PKMatchType {
     None, //不是PK,就是单击单人
     LocalPK, //本地PK

+ 12 - 2
Assets/BowArrow/Scripts/View/ChallengeOptionView.cs

@@ -14,13 +14,23 @@ public class ChallengeOptionView : MonoBehaviour
     }
 
     public void StartGame(int gameType) {
-        if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
+        AudioMgr.ins.PlayBtn();
+        if (GlobalDataTemp.pkMatchType == PKMatchType.OnlinePK) {
+            int roomType = 0;
+            if (gameType == 3) roomType = 1;
+            else if (gameType == 4) roomType = 2;
+            else if (gameType == 5) roomType = 3;
+            GlobalDataTemp.matchRoomType = roomType;
+            GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("PKMatchView").gameObject).SetActive(true);
+            return;   
+        }
+        if (GlobalDataTemp.pkMatchType == PKMatchType.LocalPK) {
             if (gameType == 3) gameType = 6;
             else if (gameType == 4) gameType = 7;
             else if (gameType == 5) gameType = 8;
         }
+        GlobalData.pkMatchType = GlobalDataTemp.pkMatchType;
         GameMgr.gameType = gameType;
-        AudioMgr.ins.PlayBtn();
         SceneManager.LoadScene("GameChallenge", LoadSceneMode.Single);
     }
 

+ 2 - 2
Assets/BowArrow/Scripts/View/GameStartView.cs

@@ -18,7 +18,7 @@ public class GameStartView : MonoBehaviour
         switch (target)
         {
             case "闯关":
-                GlobalData.pkMatchType = PKMatchType.None;
+                GlobalDataTemp.pkMatchType = PKMatchType.None;
                 GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ChallengeOptionView"));
                 break;
             case "限时":
@@ -27,7 +27,7 @@ public class GameStartView : MonoBehaviour
                 SceneManager.LoadScene("Game", LoadSceneMode.Single);
                 break;
             case "PK":
-                GlobalData.pkMatchType = PKMatchType.LocalPK;
+                GlobalDataTemp.pkMatchType = PKMatchType.LocalPK;
                 GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/RoleSelectView"));
                 break;
             default:

+ 1 - 1
Assets/BowArrow/Scripts/View/HomeView.cs

@@ -92,7 +92,7 @@ public class HomeView : MonoBehaviour
                 GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("GameStartView").gameObject).SetActive(true);
                 break;
             case "联机游戏":
-                GlobalData.pkMatchType = PKMatchType.OnlinePK;
+                GlobalDataTemp.pkMatchType = PKMatchType.OnlinePK;
                 GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("PKGameOptionView").gameObject).SetActive(true);
                 break;
             case "好友":

+ 4 - 4
Assets/BowArrow/Scripts/View/PKGameOptionView.cs

@@ -18,14 +18,14 @@ public class PKGameOptionView : MonoBehaviour
         switch (target)
         {
             case "双人闯关":
-                if (GlobalData.pkMatchType == PKMatchType.OnlinePK) return;
                 GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ChallengeOptionView"));
                 break;
             case "静止靶":
-                if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
-                    GlobalData.matchRoomType = 0;
+                if (GlobalDataTemp.pkMatchType == PKMatchType.OnlinePK) {
+                    GlobalDataTemp.matchRoomType = 0;
                     GameObject.Instantiate(GameObject.Find("WindowViews").transform.Find("PKMatchView").gameObject).SetActive(true);
-                } else {
+                } else if (GlobalDataTemp.pkMatchType == PKMatchType.LocalPK) {
+                    GlobalData.pkMatchType = GlobalDataTemp.pkMatchType;
                     GameMgr.gameType = 2;
                     SceneManager.LoadScene("Game", LoadSceneMode.Single);
                 }

+ 2 - 0
Assets/BowArrow/Scripts/View/PKMatchView.cs

@@ -73,6 +73,8 @@ public class PKMatchView : MonoBehaviour
     void Init() {
         this.transform.Find("BoxRight/BtnMatch").GetComponent<Button>().onClick.AddListener(() => {
             AudioMgr.ins.PlayBtn();
+            GlobalData.pkMatchType = GlobalDataTemp.pkMatchType;
+            GlobalData.matchRoomType = GlobalDataTemp.matchRoomType;
             PKMatchingView pkMatchingView = PKMatchingView.Create();
             if (curBtnTabIndex == 1) {
                 pkMatchingView.pkFriendInfoPack = selectedFriendInfo;