Эх сурвалжийг харах

自动记录瞄准道具和加速道具开关

lvjincheng 4 жил өмнө
parent
commit
09b6d4358b

+ 92 - 38
Assets/BowArrow/Scripts/Game/GameAssistUI.cs

@@ -10,6 +10,9 @@ public class GameAssistUI : MonoBehaviour
     [SerializeField] Material outlight;
     [SerializeField] Text text1;
     [SerializeField] Text text2;
+    Button btnScaleAim;
+    Button btnScaleShoot;
+
     public static GameAssistUI ins;
 
     void Awake() {
@@ -26,28 +29,22 @@ public class GameAssistUI : MonoBehaviour
             AudioMgr.ins.PlayBtn();
             GameRuleView.Create();
         });
-        Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
+        btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
         btnScaleAim.onClick.AddListener(delegate(){
             AudioMgr.ins.PlayBtn();
             if (btnScaleAim.GetComponentInChildren<Image>().material == outlight) {
-                btnScaleAim.GetComponentInChildren<Image>().material = null;
                 closeScaleAim();
             } else {
-                if (openScaleAim()) {
-                    btnScaleAim.GetComponentInChildren<Image>().material = outlight;
-                }
+                openScaleAim();
             }
         });
-        Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
+        btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
         btnScaleShoot.onClick.AddListener(delegate(){
             AudioMgr.ins.PlayBtn();
             if (btnScaleShoot.GetComponentInChildren<Image>().material == outlight) {
-                btnScaleShoot.GetComponentInChildren<Image>().material = null;
                 closeScaleShoot();
             } else {
-                if (openScaleShoot()) {
-                    btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
-                }
+                openScaleShoot();
             }
         });
         Button btnIdentity = this.transform.Find("Button4").GetComponent<Button>();
@@ -67,8 +64,11 @@ public class GameAssistUI : MonoBehaviour
             targetView.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 30);
             btnViewTarget.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 195);
         }
-        //看看是不是双人游戏的再次对战
+        //看看是不是双人游戏的再次对战,从静态内存中读取功能的开关记录
         applyPlayerRecordsWhenGameTryAgain();
+        //看看是不是其它模式,从本地数据库读取开关记录
+        applyScaleAimFromRecord();
+        applyScaleShootFromRecord();
     }
 
     // ------ 开镜瞄准功能 ------
@@ -94,6 +94,7 @@ public class GameAssistUI : MonoBehaviour
             float scopeScale = scaleAimScopeScales[scaleValue - 1];
             scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
             scaleAimOn = true;
+            btnScaleAim.GetComponentInChildren<Image>().material = outlight;
             onOpenScaleAimSuccess();
             return true;
         }
@@ -109,6 +110,8 @@ public class GameAssistUI : MonoBehaviour
 
     void closeScaleAim()
     {
+        if (!scope) return;
+        btnScaleAim.GetComponentInChildren<Image>().material = null;
         BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
         bowCamera.banCameraFieldOfView = false;
         CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
@@ -142,17 +145,15 @@ public class GameAssistUI : MonoBehaviour
 
     bool openScaleShoot()
     {   
-        List<PropInfo> props = PropMgr.ins.ListForEquipped();
-        foreach (var prop in props)
-        {
-            if (prop.config.type == 2) {
-                PropScaleShoot config = prop.config as PropScaleShoot;
-                shootScaleValue = config.scaleValue;
-                if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
-                scaleShootOn = true;
-                onOpenScaleShootSuccess();
-                return true;
-            }
+        PropInfo prop = getScaleShootProp();
+        if (prop != null) {
+            PropScaleShoot config = prop.config as PropScaleShoot;
+            shootScaleValue = config.scaleValue;
+            if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
+            scaleShootOn = true;
+            btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
+            onOpenScaleShootSuccess();
+            return true;
         }
         if (seq2 != null && !seq2.IsComplete()) {
             seq2.Complete();
@@ -165,43 +166,104 @@ public class GameAssistUI : MonoBehaviour
     }
     void closeScaleShoot()
     {
+        btnScaleShoot.GetComponentInChildren<Image>().material = null;
         shootScaleValue = 1;
         if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
         scaleShootOn = false;
         onCloseScaleShootSuccess();
     }
+    PropInfo getScaleShootProp() {
+        List<PropInfo> props = PropMgr.ins.ListForEquipped();
+        foreach (var prop in props)
+        {
+            if (prop.config.type == 2) {
+                return prop;
+            }
+        }
+        return null;
+    }
 
-    //------ 以下给双人模式分别记录提供的接口 ------
-
-    //两位玩家的开镜情况
-    bool[] playerScaleAimRecords = {false, false};
-    //两位玩家的加速情况
-    bool[] playerScaleShootRecords = {false, false};
+    //---道具功能开关监听---
 
     private void onOpenScaleAimSuccess() {
         if (GameMgr.gameType == 2) {
             playerScaleAimRecords[getPlayerIndex()] = true;
+        } else {
+            saveScaleAim(true);
         }
     }
 
     private void onCloseScaleAimSuccess() {
         if (GameMgr.gameType == 2) {
             playerScaleAimRecords[getPlayerIndex()] = false;
+        } else {
+            saveScaleAim(false);
         }
     }
 
     private void onOpenScaleShootSuccess() {
         if (GameMgr.gameType == 2) {
             playerScaleShootRecords[getPlayerIndex()] = true;
+        } else {
+            saveScaleShoot(true);
         }
     }
 
     private void onCloseScaleShootSuccess() {
         if (GameMgr.gameType == 2) {
             playerScaleShootRecords[getPlayerIndex()] = false;
+        } else {
+            saveScaleShoot(false);
+        }
+    }
+
+    //---以下为其它模式提供的道具开关记录和应用接口
+
+    private void saveScaleAim(bool isOpen) {
+        if (GameMgr.gameType == 2) return;
+        PlayerPrefs.SetInt("ScaleAim," + GameMgr.gameType + "," + LoginMgr.myUserInfo.user, isOpen ? 1 : 0);
+    }
+
+    private void applyScaleAimFromRecord() {
+        if (GameMgr.gameType == 2) return;
+        int saveValue = PlayerPrefs.GetInt("ScaleAim," + GameMgr.gameType + "," + LoginMgr.myUserInfo.user, 0);
+        if (saveValue == 1) {
+            if (GetPropScaleAimValue() == 0) {
+                saveScaleAim(false);
+            } else {
+                openScaleAim();
+            }
+        } else {
+            closeScaleAim();
         }
     }
 
+    private void saveScaleShoot(bool isOpen) {
+        if (GameMgr.gameType == 2) return;
+        PlayerPrefs.SetInt("ScaleShoot," + GameMgr.gameType + "," + LoginMgr.myUserInfo.user, isOpen ? 1 : 0);
+    }
+
+    private void applyScaleShootFromRecord() {
+        if (GameMgr.gameType == 2) return;
+        int saveValue = PlayerPrefs.GetInt("ScaleShoot," + GameMgr.gameType + "," + LoginMgr.myUserInfo.user, 0);
+        if (saveValue == 1) {
+            if (getScaleShootProp() == null) {
+                saveScaleShoot(false);
+            } else {
+                openScaleShoot();
+            }
+        } else {
+            closeScaleShoot();
+        }
+    }
+
+    //------ 以下给双人模式分别记录提供的接口 ------
+
+    //两位玩家的开镜情况
+    bool[] playerScaleAimRecords = {false, false};
+    //两位玩家的加速情况
+    bool[] playerScaleShootRecords = {false, false};
+
     private int getPlayerIndex() {
         return ((PKGameMode) GameMgr.ins.gameMode).currentPlayerIndex;
     }
@@ -210,24 +272,16 @@ public class GameAssistUI : MonoBehaviour
         if (GameMgr.gameType != 2) return;
         int playerIndex = getPlayerIndex();
         if (scaleAimOn != playerScaleAimRecords[playerIndex]) {
-            Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
             if (playerScaleAimRecords[playerIndex]) {
-                if (openScaleAim()) {
-                    btnScaleAim.GetComponentInChildren<Image>().material = outlight;
-                }
+                openScaleAim();
             } else {
-                btnScaleAim.GetComponentInChildren<Image>().material = null;
                 closeScaleAim();
             }
         }
         if (scaleShootOn != playerScaleShootRecords[playerIndex]) {
-            Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
             if (playerScaleShootRecords[playerIndex]) {
-                if (openScaleShoot()) {
-                    btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
-                }
+                openScaleShoot();
             } else {
-                btnScaleShoot.GetComponentInChildren<Image>().material = null;
                 closeScaleShoot();
             }
         }