| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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) {
- ShowPlayerDie(((WolfHuntGameMode_OnlinePK)gameModeLocalPK).playerDieList);
- }
- }
- //游戏结束
- 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 =
- System.String.Format(TextAutoLanguage2.GetTextByKey("game_challenge_pk_score"), score);
- }
- 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);
- }
- }
- }
- }
|