Bladeren bron

本地PK得分统计View

lvjincheng 4 jaren geleden
bovenliggende
commit
3d497bf99c

File diff suppressed because it is too large
+ 943 - 0
Assets/BowArrow/Scenes/GameChallengeScene/GameChallenge.unity


+ 8 - 0
Assets/BowArrow/Scenes/GameChallengeScene/LocalPK.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: b2038dcec374c9a479d1fd73446a32e5
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 51 - 0
Assets/BowArrow/Scenes/GameChallengeScene/LocalPK/HunterGameView_LocalPK.cs

@@ -0,0 +1,51 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class HunterGameView_LocalPK : MonoBehaviour
+{
+    int[] hitScores = {0, 0};
+    int curPlayerIndex = -1;
+    ChallengeGameModeLocalPK gameModeLocalPK;
+
+    void Awake() {
+        gameModeLocalPK = (ChallengeGameModeLocalPK) GameMgr.ins.gameMode;
+        InitRenderPlayerInfo(0, GlobalData.localPK_playerRoleIDs[0], 0);
+        InitRenderPlayerInfo(1, GlobalData.localPK_playerRoleIDs[1], 0);
+        GameEventCenter.ins.onTargetAnimalHurt += (a, hurtValue) => {
+            
+            int playerIndex = gameModeLocalPK.GetCurrentPlayIndex();
+            hitScores[playerIndex] += hurtValue;
+            RenderScore(playerIndex, hitScores[playerIndex]);
+        };
+    }
+
+    Color itemBG_ColorDark = new Color(0,0,0,155f/255);
+    Color itemBG_ColorLight = new Color(0,100f/255,0,155f/255);
+
+    void Update() {
+        if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) {
+            curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex();
+            RenderItemBG_Color(0, curPlayerIndex == 0 ? itemBG_ColorLight : itemBG_ColorDark);
+            RenderItemBG_Color(1, curPlayerIndex == 1 ? itemBG_ColorLight : itemBG_ColorDark);
+        }
+    }
+
+    void RenderItemBG_Color(int posNum, Color color) {
+        this.transform.Find("ScoreBox/Item" + posNum).GetComponent<Image>().color = color;
+        this.transform.Find("ScoreBox/Item" + posNum + "/Cur").gameObject.SetActive(color.Equals(itemBG_ColorLight));
+    }
+
+    void InitRenderPlayerInfo(int posNum, int playerID, int score)
+    {
+        (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(playerID);
+        this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
+        this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickName;
+        RenderScore(posNum, score);
+    }
+
+    void RenderScore(int posNum, int score) {
+        this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent<Text>().text = "得分: " + score.ToString();
+    }
+}

+ 11 - 0
Assets/BowArrow/Scenes/GameChallengeScene/LocalPK/HunterGameView_LocalPK.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: bc382051b24b258418f84de2350c0c56
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 6 - 3
Assets/BowArrow/Scenes/GameChallengeScene/Rabbit.cs

@@ -54,9 +54,12 @@ public class Rabbit : TargetAnimal
     {
         arrow.Head().position = hitPoint + arrow.transform.forward * 0.1f;
         arrow.Hit();
-        if (partName == "Leg" || partName == "Ear") hp -= 1;
-        else if (partName == "Body") hp -= 2;
-        else if (partName == "Head") hp -= 3;
+        int hurtValue = 0;
+        if (partName == "Leg" || partName == "Ear") hurtValue = 1;
+        else if (partName == "Body") hurtValue = 2;
+        else if (partName == "Head") hurtValue = 3;
+        hp -= hurtValue;
+        GameEventCenter.ins.onTargetAnimalHurt?.Invoke(this, hurtValue);
         if (hp <= 0) {
             Die(arrow);
         } else {

+ 6 - 3
Assets/BowArrow/Scenes/GameChallengeScene/Wolf.cs

@@ -85,15 +85,18 @@ public class Wolf : TargetAnimal
     {
         arrow.Head().position = hitPoint + arrow.transform.forward * 0.1f;
         arrow.Hit();
+        int hurtValue = 0;
         if (partName == "Leg" || partName == "Tail") {
-            hp -= 2;
+            hurtValue = 2;
         }
         else if (partName == "Body") {
-            hp -= 3;
+            hurtValue = 3;
         }
         else if (partName == "Head") {
-            hp -= 100;
+            hurtValue = 10;
         }
+        hp -= hurtValue;
+        GameEventCenter.ins.onTargetAnimalHurt?.Invoke(this, hurtValue);
         if (hp > 0) {
             Hurt();
         } else {

+ 6 - 4
Assets/BowArrow/Scenes/GameChallengeScene/Yeji.cs

@@ -64,12 +64,14 @@ public class Yeji : TargetAnimal
         {
             arrow.Head().position = hitPoint + arrow.transform.forward * 0.1f;
             arrow.Hit();
+            int hurtValue = 0;
             if (partName == "Wing") {
-                hp -= 1;
-                this.agent.speed /= 2f;
+                hurtValue = 1;
             }
-            else if (partName == "Body") hp -= 2;
-            else if (partName == "Head") hp -= 3;
+            else if (partName == "Body") hurtValue = 2;
+            else if (partName == "Head") hurtValue = 3;
+            hp -= hurtValue;
+            GameEventCenter.ins.onTargetAnimalHurt?.Invoke(this, hurtValue);
             if (hp <= 0) {
                 Die(arrow);
             } else {

+ 1 - 0
Assets/BowArrow/Scripts/Game/GameEventCenter.cs

@@ -5,6 +5,7 @@ using UnityEngine;
 public class GameEventCenter : MonoBehaviour
 {   
     public System.Action<ArmBow, Arrow> onBowArrowShootOut;
+    public System.Action<TargetAnimal, int> onTargetAnimalHurt;
 
     private static GameEventCenter _ins;
     public static GameEventCenter ins {

+ 10 - 1
Assets/BowArrow/Scripts/Manager/GameMode/RabbitHuntGameMode_LocalPK.cs

@@ -2,7 +2,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
-public class RabbitHuntGameMode_LocalPK : RabbitHuntGameMode
+public class RabbitHuntGameMode_LocalPK : RabbitHuntGameMode, ChallengeGameModeLocalPK
 {
     int currentPlayerIndex = 0; // 双人0和1
     public RabbitHuntGameMode_LocalPK(GameMgr gameMgr) : base(gameMgr) {
@@ -13,6 +13,7 @@ public class RabbitHuntGameMode_LocalPK : RabbitHuntGameMode
     {
         SetLevel(5);
         AddHuntGameView();
+        this.gameMgr.transform.Find("HunterGameView_LocalPK").gameObject.SetActive(true);
         AddReadyView();
     }
     
@@ -38,4 +39,12 @@ public class RabbitHuntGameMode_LocalPK : RabbitHuntGameMode
         currentPlayerIndex++;
         currentPlayerIndex %= 2;
     }
+
+    //localPK interface
+    public int GetCurrentPlayIndex() {
+        return currentPlayerIndex;
+    }
 }
+public interface ChallengeGameModeLocalPK {
+    public int GetCurrentPlayIndex();
+}

+ 7 - 1
Assets/BowArrow/Scripts/Manager/GameMode/WolfHuntGameMode_LocalPK.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using UnityEngine;
 using DG.Tweening;
 
-public class WolfHuntGameMode_LocalPK : WolfHuntGameMode
+public class WolfHuntGameMode_LocalPK : WolfHuntGameMode, ChallengeGameModeLocalPK
 {
     int currentPlayerIndex = 0; // 双人0和1
     int[] playerHpList = {20, 20}; 
@@ -31,6 +31,7 @@ public class WolfHuntGameMode_LocalPK : WolfHuntGameMode
         GameMgr.ins.transform.Find("WolfActGrid").gameObject.SetActive(true);
         SetLevel(5);
         AddHuntGameView();
+        this.gameMgr.transform.Find("HunterGameView_LocalPK").gameObject.SetActive(true);
         AddReadyView();
     }
     
@@ -87,4 +88,9 @@ public class WolfHuntGameMode_LocalPK : WolfHuntGameMode
     void RecordByCurPlayerIndex() {
         playerHpList[currentPlayerIndex] = hp;
     }
+
+    //localPK interface
+    public int GetCurrentPlayIndex() {
+        return currentPlayerIndex;
+    }
 }

+ 7 - 1
Assets/BowArrow/Scripts/Manager/GameMode/YejiHuntGameMode_LocalPK.cs

@@ -2,7 +2,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
-public class YejiHuntGameMode_LocalPK : YejiHuntGameMode
+public class YejiHuntGameMode_LocalPK : YejiHuntGameMode, ChallengeGameModeLocalPK
 {
     int currentPlayerIndex = 0; // 双人0和1
     public YejiHuntGameMode_LocalPK(GameMgr gameMgr) : base(gameMgr) {
@@ -14,6 +14,7 @@ public class YejiHuntGameMode_LocalPK : YejiHuntGameMode
         Yeji.InitPreHeights();
         SetLevel(5);
         AddHuntGameView();
+        this.gameMgr.transform.Find("HunterGameView_LocalPK").gameObject.SetActive(true);
         AddReadyView();
     }
     
@@ -39,4 +40,9 @@ public class YejiHuntGameMode_LocalPK : YejiHuntGameMode
         currentPlayerIndex++;
         currentPlayerIndex %= 2;
     }
+
+    //localPK interface
+    public int GetCurrentPlayIndex() {
+        return currentPlayerIndex;
+    }
 }

Some files were not shown because too many files changed in this diff