| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class HunterGameView_LocalPK : MonoBehaviour
- {
- int[] hitScores = {0, 0};
- bool[] dieList = {false, false};
- int curPlayerIndex = -1;
- ChallengeGameModeLocalPK gameModeLocalPK;
- HunterGamePlayerScoreCounter scoreCounter;
- void Awake() {
- gameModeLocalPK = (ChallengeGameModeLocalPK) GameMgr.ins.gameMode;
- scoreCounter = gameModeLocalPK.getHunterGamePlayerScoreCounter();
- if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
- InitRenderPlayerInfo_Local(0, GlobalData.localPK_playerRoleIDs[0], 0);
- InitRenderPlayerInfo_Local(1, GlobalData.localPK_playerRoleIDs[1], 0);
- } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
- MatchPlayerInfo info0 = GlobalData.matchPlayerInfos[0];
- MatchPlayerInfo info1 = GlobalData.matchPlayerInfos[1];
- InitRenderPlayerInfo_Online(0, info0.avatarID, info0.nickname, 0);
- InitRenderPlayerInfo_Online(1, info1.avatarID, info1.nickname, 0);
- }
- }
- void Update() {
- if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) {
- curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex();
- (Sprite avatar, string nickName) = (null, null);
- if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
- (avatar, nickName) = RoleMgr.GetRoleInfo(GlobalData.localPK_playerRoleIDs[curPlayerIndex]);
- } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
- (avatar, nickName) = RoleMgr.GetRoleInfo(GlobalData.matchPlayerInfos[curPlayerIndex].avatarID);
- nickName = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
- }
- this.transform.Find("CurrentPlayer/Avatar").GetComponent<Image>().sprite = avatar;
- this.transform.Find("CurrentPlayer/Name").GetComponent<Text>().text = nickName;
- } else {
- //索引相同,则渲染对应的玩家时间
- (float t, float tMax) = gameModeLocalPK.GetSingleShootReadyTime();
- this.transform.Find("CurrentPlayer/Progress").GetComponent<Image>().fillAmount = t / tMax;
- this.transform.Find("CurrentPlayer/Time").GetComponent<Text>().text = TimeUtil.GetTimeStr(t);
- }
- //渲染得分
- for (int i = 0; i < 2; i++) {
- if (hitScores[i] != scoreCounter.hitScores[i]) {
- RenderScore(i, scoreCounter.hitScores[i]);
- }
- }
- //渲染死亡
- if (ChallengeGameMode.IsChallengeWolf()) {
- if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
- ShowPlayerDie(((WolfHuntGameMode_LocalPK)gameModeLocalPK).playerDieList);
- }
- if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
-
- }
- }
- //游戏结束
- if (GameMgr.ins.gameOver) {
- this.transform.Find("CurrentPlayer").gameObject.SetActive(false);
- }
- }
- void InitRenderPlayerInfo_Local(int posNum, int roleID, int score)
- {
- (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(roleID);
- 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 InitRenderPlayerInfo_Online(int posNum, int avatarID, string nickname, int score)
- {
- Sprite avatar = RoleMgr.GetAvatar(avatarID);
- 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) {
- hitScores[posNum] = score;
- this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent<Text>().text = "得分: " + score.ToString();
- }
- public void ShowPlayerDie(bool[] playerDieList) {
- for (int i = 0; i < playerDieList.Length; i++) {
- if (playerDieList[i] && !dieList[i]) {
- dieList[i] = true;
- this.transform.Find("ScoreBox/Item" + i + "/IconDie").gameObject.SetActive(true);
- this.transform.Find("ScoreBox/Item" + i + "/MaskDie").gameObject.SetActive(true);
- }
- }
- }
- }
|