Browse Source

切换英灵按钮改为手柄右遥感和小键盘左右

LAPTOP-OM1V99U2\永远de小亡灵 1 năm trước cách đây
mục cha
commit
e051f67d73

+ 75 - 44
ActionTowerDefense/Assets/Resources/Actions/Player.inputactions

@@ -185,6 +185,15 @@
                     "interactions": "",
                     "initialStateCheck": false
                 },
+                {
+                    "name": "ChooseSpirit_LR",
+                    "type": "Value",
+                    "id": "ee055f9c-cd38-4453-b58d-c08221f12c55",
+                    "expectedControlType": "Button",
+                    "processors": "",
+                    "interactions": "",
+                    "initialStateCheck": true
+                },
                 {
                     "name": "Transfigurate",
                     "type": "Button",
@@ -425,17 +434,6 @@
                     "isComposite": false,
                     "isPartOfComposite": false
                 },
-                {
-                    "name": "",
-                    "id": "a02eb8e2-9ad4-4109-aecc-bbc9d58afd51",
-                    "path": "<Gamepad>/rightTrigger",
-                    "interactions": "",
-                    "processors": "",
-                    "groups": "",
-                    "action": "SummonSpirit",
-                    "isComposite": false,
-                    "isPartOfComposite": false
-                },
                 {
                     "name": "",
                     "id": "460166c5-e0bc-414e-b1df-2b3993b207a2",
@@ -458,17 +456,6 @@
                     "isComposite": false,
                     "isPartOfComposite": false
                 },
-                {
-                    "name": "",
-                    "id": "80d2e9fd-9fc8-4ed4-8db9-46422707386b",
-                    "path": "<Gamepad>/rightShoulder",
-                    "interactions": "",
-                    "processors": "",
-                    "groups": "",
-                    "action": "SummonSpirit1",
-                    "isComposite": false,
-                    "isPartOfComposite": false
-                },
                 {
                     "name": "",
                     "id": "a35998e9-a5c9-4751-8e0c-6bb47fe2f4f9",
@@ -601,17 +588,6 @@
                     "isComposite": false,
                     "isPartOfComposite": false
                 },
-                {
-                    "name": "",
-                    "id": "7fde0f34-3164-4b76-b382-5bbb99850166",
-                    "path": "<Gamepad>/rightTrigger",
-                    "interactions": "",
-                    "processors": "",
-                    "groups": "",
-                    "action": "SummonSpiritUp",
-                    "isComposite": false,
-                    "isPartOfComposite": false
-                },
                 {
                     "name": "",
                     "id": "bfcdc0d5-7fda-4489-a001-11da61df09fe",
@@ -634,17 +610,6 @@
                     "isComposite": false,
                     "isPartOfComposite": false
                 },
-                {
-                    "name": "",
-                    "id": "cdb985ee-b8dd-488c-89b4-2bef2226f479",
-                    "path": "<Gamepad>/rightShoulder",
-                    "interactions": "",
-                    "processors": "",
-                    "groups": "",
-                    "action": "SummonSpirit1Up",
-                    "isComposite": false,
-                    "isPartOfComposite": false
-                },
                 {
                     "name": "",
                     "id": "9d2b39a3-1797-4275-836d-862781e8aac2",
@@ -776,6 +741,72 @@
                     "action": "TransfigurateUp",
                     "isComposite": false,
                     "isPartOfComposite": false
+                },
+                {
+                    "name": "",
+                    "id": "10581194-1be2-428c-9212-b24dfe0d6c81",
+                    "path": "<Gamepad>/rightStick",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "ChooseSpirit_LR",
+                    "isComposite": false,
+                    "isPartOfComposite": false
+                },
+                {
+                    "name": "ArrowWASD",
+                    "id": "f24856ad-a86b-40b0-ad0a-5bc01872640e",
+                    "path": "2DVector",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "ChooseSpirit_LR",
+                    "isComposite": true,
+                    "isPartOfComposite": false
+                },
+                {
+                    "name": "up",
+                    "id": "c9a7c2c8-0941-4c92-8d58-37777be062d0",
+                    "path": "<Keyboard>/upArrow",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "ChooseSpirit_LR",
+                    "isComposite": false,
+                    "isPartOfComposite": true
+                },
+                {
+                    "name": "down",
+                    "id": "0874338b-a6d9-4549-8778-b24729f188d1",
+                    "path": "<Keyboard>/downArrow",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "ChooseSpirit_LR",
+                    "isComposite": false,
+                    "isPartOfComposite": true
+                },
+                {
+                    "name": "left",
+                    "id": "df81d4b3-f753-4b41-82e7-62887d94ae35",
+                    "path": "<Keyboard>/leftArrow",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "ChooseSpirit_LR",
+                    "isComposite": false,
+                    "isPartOfComposite": true
+                },
+                {
+                    "name": "right",
+                    "id": "75144e4a-3098-4b4e-90a0-671c92f9d1c9",
+                    "path": "<Keyboard>/rightArrow",
+                    "interactions": "",
+                    "processors": "",
+                    "groups": "",
+                    "action": "ChooseSpirit_LR",
+                    "isComposite": false,
+                    "isPartOfComposite": true
                 }
             ]
         }

+ 64 - 4
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -46,6 +46,7 @@ public class PlayerController : MoveCharacter
     public int[] needCorpses;
     private GameObject spiritObj;           //当前变身的对象
     public int endChange = 0;               //结束变身后召唤的英灵
+    public Vector2 rightDir;
 
     [Header("玩家组件")]
     public UIHP uiMp;
@@ -389,6 +390,11 @@ public class PlayerController : MoveCharacter
                 portalsController.rbs.Remove(rb);
             }
         }
+        if(rightDir.x<-0.5 || rightDir.x > 0.5)
+        {
+            ChangeSpirit();
+        }
+        
     }
 
 
@@ -469,22 +475,30 @@ public class PlayerController : MoveCharacter
             isClickBtnEast = true;
         }
     }
-
-    void OnChooseSpirit()   //选英灵
+    
+    //选英灵 (手柄右扳机,键盘TAB)
+    void OnChooseSpirit()
     {
         switch (playerId)
         {
             case 0:
-                SpiritSystem.isP1CardChange = true;
+                SpiritSystem.isP1CardChangeR = true;
                 break;
             case 1:
-                SpiritSystem.isP2CardChange = true;
+                SpiritSystem.isP2CardChangeR = true;
                 break;
             default:
                 break;
         }
     }
 
+    //选英灵(手柄右摇杆,小键盘左右)
+    void OnChooseSpirit_LR(InputValue value)
+    {
+        rightDir = value.Get<Vector2>();
+
+    }
+
     void OnTransfigurate()      //变身
     {
         if (!keyTransfigurateRelease && !isFloat && canMove && !isBaseBtnOut)
@@ -501,6 +515,7 @@ public class PlayerController : MoveCharacter
         }
     }
 
+
     public void Jump()
     {
         SetUpSpeed(jumpSpeed);
@@ -1924,4 +1939,49 @@ public class PlayerController : MoveCharacter
     {
         targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
     }
+
+    public void ChangeSpirit()
+    {
+        if ((playerId == 0 && SpiritSystem.canP1CardChange) || (playerId == 1 && SpiritSystem.canP2CardChange))
+        {
+            if (rightDir.x >= 0.5)
+            {
+
+                switch (playerId)
+                {
+                    case 0:
+                        SpiritSystem.P1CardChangeTime = 0;
+                        SpiritSystem.canP1CardChange = false;
+                        SpiritSystem.isP1CardChangeR = true;
+                        break;
+                    case 1:
+                        SpiritSystem.P2CardChangeTime = 0;
+                        SpiritSystem.canP2CardChange = false;
+                        SpiritSystem.isP2CardChangeR = true;
+                        break;
+                    default:
+                        break;
+                }
+            }
+            else if (rightDir.x <= -0.5)
+            {
+
+                switch (playerId)
+                {
+                    case 0:
+                        SpiritSystem.P1CardChangeTime = 0;
+                        SpiritSystem.canP1CardChange = false;
+                        SpiritSystem.isP1CardChangeL = true;
+                        break;
+                    case 1:
+                        SpiritSystem.P2CardChangeTime = 0;
+                        SpiritSystem.canP2CardChange = false;
+                        SpiritSystem.isP2CardChangeL = true;
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+    }
 }

+ 78 - 21
ActionTowerDefense/Assets/Scripts/Spirits/Base_Spirits/SpiritSystem.cs

@@ -20,24 +20,32 @@ public class SpiritSystem : MonoBehaviour
     public float uiSpeed;
 
     [Header("玩家1图标")]
-    static public GameObject player1;
-    static public Spirits p1Spirits;
     public Image[] player1cards;
     public GameObject choose1;
+    static public GameObject player1;
+    static public Spirits p1Spirits;
     private int curCard1;
-    static public bool isP1CardChange;
+    static public bool isP1CardChangeR;         //向右选择
+    static public bool isP1CardChangeL;         //向左选择
+    static public bool canP1CardChange;         //能否切换
+    static public float P1CardChangeTime;       //切换后的计时器
+    public float P1CardChangeTotalTime;         //距离下一次切换要间隔的总时间
     public GameObject P1icon;
-    public TextMeshProUGUI[] P1nums;    //玩家1每一个英灵可变身数量UI文字
+    public TextMeshProUGUI[] P1nums;            //玩家1每一个英灵可变身数量UI文字
 
     [Header("玩家2图标")]
-    static public GameObject player2;
-    static public Spirits p2Spirits;
     public Image[] player2cards;
     public GameObject choose2;
+    static public GameObject player2;
+    static public Spirits p2Spirits;
     private int curCard2;
-    static public bool isP2CardChange;
+    static public bool isP2CardChangeR;         //向右选择
+    static public bool isP2CardChangeL;         //向左选择
+    static public bool canP2CardChange;         //能否切换
+    static public float P2CardChangeTime;       //切换后的计时器
+    public float P2CardChangeTotalTime;         //距离下一次切换要间隔的总时间
     public GameObject P2icon;
-    public TextMeshProUGUI[] P2nums;    //玩家2每一个英灵可变身数量UI文字
+    public TextMeshProUGUI[] P2nums;            //玩家2每一个英灵可变身数量UI文字
 
     [Header("英灵图标")]
     public Sprite floatHead;
@@ -295,7 +303,7 @@ public class SpiritSystem : MonoBehaviour
         }
     }
 
-    private void ChangeSpirit(int id)
+    public void ChangeSpirit(int id, bool chooseLeft)
     {
         switch (id)
         {
@@ -303,10 +311,21 @@ public class SpiritSystem : MonoBehaviour
                 int man = p1Spirits.hasSpirits;
                 if (man != 0)
                 {
-                    curCard1 += 1;
-                    if (curCard1 == man)
+                    if (chooseLeft)
                     {
-                        curCard1 = 0;
+                        curCard1 -= 1;
+                        if(curCard1 == -1)
+                        {
+                            curCard1 = man - 1;
+                        }
+                    }
+                    else
+                    {
+                        curCard1 += 1;
+                        if (curCard1 == man)
+                        {
+                            curCard1 = 0;
+                        }
                     }
                     choose1.transform.position = player1cards[curCard1].transform.position;
                     p1Spirits.currentSpirit = p1Spirits.ownSpirits[curCard1];
@@ -317,10 +336,21 @@ public class SpiritSystem : MonoBehaviour
                 int mann = p2Spirits.hasSpirits;
                 if (mann != 0)
                 {
-                    curCard2 += 1;
-                    if (curCard2 == mann)
+                    if (chooseLeft)
                     {
-                        curCard2 = 0;
+                        curCard2 -= 1;
+                        if (curCard2 == -1)
+                        {
+                            curCard2 = mann - 1;
+                        }
+                    }
+                    else
+                    {
+                        curCard2 += 1;
+                        if (curCard2 == mann)
+                        {
+                            curCard2 = 0;
+                        }
                     }
                     choose2.transform.position = player2cards[curCard2].transform.position;
                     p2Spirits.currentSpirit = p2Spirits.ownSpirits[curCard2];
@@ -438,15 +468,42 @@ public class SpiritSystem : MonoBehaviour
             playerUIin(1);
         }
 
-        if (isP1CardChange)
+        //切换英灵选择
+        if (isP1CardChangeR)
+        {
+            isP1CardChangeR = false;
+            ChangeSpirit(0,false);
+        }
+        if (isP2CardChangeR)
+        {
+            isP2CardChangeR = false;
+            ChangeSpirit(1,false);
+        }
+        if (isP1CardChangeL)
+        {
+            isP1CardChangeL = false;
+            ChangeSpirit(0, true);
+        }
+        if (isP2CardChangeL)
+        {
+            isP2CardChangeL = false;
+            ChangeSpirit(1, true);
+        }
+        if (!canP1CardChange)
         {
-            isP1CardChange = false;
-            ChangeSpirit(0);
+            P1CardChangeTime += Time.deltaTime;
+            if(P1CardChangeTime >= P1CardChangeTotalTime)
+            {
+                canP1CardChange = true;
+            }
         }
-        if (isP2CardChange)
+        if (!canP2CardChange)
         {
-            isP2CardChange = false;
-            ChangeSpirit(1);
+            P2CardChangeTime += Time.deltaTime;
+            if(P2CardChangeTime >= P2CardChangeTotalTime)
+            {
+                canP2CardChange = true;
+            }
         }
 
         if (isSelect1)