| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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.avatarUrl, info0.nickname, 0);
- InitRenderPlayerInfo_Online(1, info1.avatarID, info1.avatarUrl, info1.nickname, 0);
- }
- }
- void Update() {
- if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) {
- curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex();
- string nickName = null;
- Image avatarImage = this.transform.Find("CurrentPlayer/Avatar").GetComponent<Image>();
- if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
- nickName = RoleMgr.GetRoleInfo(GlobalData.localPK_playerRoleIDs[curPlayerIndex], avatarImage);
- } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
- int avatarID = GlobalData.matchPlayerInfos[curPlayerIndex].avatarID;
- string avatarUrl = GlobalData.matchPlayerInfos[curPlayerIndex].avatarUrl;
- RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl);
- nickName = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
- }
- //this.transform.Find("CurrentPlayer/Name").GetComponent<Text>().text = nickName;
- TextEllipsis.SetTextWithEllipsis(transform.Find("CurrentPlayer/Name").GetComponent<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)
- {
- string nickName = RoleMgr.GetRoleInfo(roleID,
- this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>());
- //this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickName;
- TextEllipsis.SetTextWithEllipsis(transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>(), nickName);
- RenderScore(posNum, score);
- }
- void InitRenderPlayerInfo_Online(int posNum, int avatarID, string avatarUrl, string nickname, int score)
- {
- RoleMgr.SetAvatarToImage(
- this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>(),
- avatarID, avatarUrl
- );
- //this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickname;
- TextEllipsis.SetTextWithEllipsis(transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<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);
- }
- }
- }
- }
|