| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using DG.Tweening;
- /* PK模式的轮换选手的准备界面 */
- public class PKGameReadyView : MonoBehaviour
- {
- PKGameMode pKGameMode;
- PKGameMode_OnlinePK pKGameMode_OnlinePK;
- public bool showRound = false;
- bool isDiscarded = false;//丢弃的
- static PKGameReadyView ins;
- void Start()
- {
- if (ins) {
- ins.isDiscarded = true;
- Destroy(ins.gameObject);
- }
- ins = this;
- GameObject.FindObjectOfType<ArmBow>().Hide();
-
- InitPKGameMode();
- RenderPlayerInfo();
- RunAnimation();
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- if (isDiscarded) return;
- if (ArmBow.ins) ArmBow.ins.Show();
- if (GameMgr.ins) GameMgr.ins.gameMode.UnbanBowReady();
- }
- void InitPKGameMode() {
- if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
- pKGameMode = (PKGameMode) GameMgr.ins.gameMode;
- }
- else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
- pKGameMode_OnlinePK = (PKGameMode_OnlinePK) GameMgr.ins.gameMode;
- }
- }
- void RenderPlayerInfo() {
- if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
- string nickName = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[pKGameMode.currentPlayerIndex],
- this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>(), this);
- this.transform.Find("Panel/Name").GetComponent<Text>().text = nickName;
- }
- else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
- int curPlayerIndex = pKGameMode_OnlinePK.gameLogic.currentPlayerIndex;
- int avatarID = GlobalData.matchPlayerInfos[curPlayerIndex].avatarID;
- string avatarUrl = GlobalData.matchPlayerInfos[curPlayerIndex].avatarUrl;
- string nickname = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
- RoleMgr.SetAvatarToImage(
- this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>(),
- this,
- avatarID, avatarUrl
- );
- this.transform.Find("Panel/Name").GetComponent<Text>().text = nickname;
- }
- }
- void RunAnimation() {
- // get data
- int roundNum = 0;
- int showRoundValue = 0;
- System.Action setShowRoundValue = null;
- if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
- roundNum = pKGameMode.round;
- showRoundValue = pKGameMode.showRoundValue;
- setShowRoundValue = () => {
- pKGameMode.showRoundValue = roundNum;
- };
- }
- else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
- roundNum = pKGameMode_OnlinePK.gameLogic.round;
- showRoundValue = pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView;
- setShowRoundValue = () => {
- pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView = roundNum;
- };
- } else {
- throw new System.Exception("pkMatchType Error");
- }
- // animate
- Image mask = this.transform.Find("Mask").GetComponent<Image>();
- Transform panel = this.transform.Find("Panel");
- TextAutoLanguage round = this.transform.Find("Round").GetComponent<TextAutoLanguage>();
- Sequence seq = DOTween.Sequence();
- if (showRoundValue < roundNum) {
- setShowRoundValue?.Invoke();
- seq.AppendCallback(delegate() {
- round.textFormatArgs = new string[]{roundNum.ToString()};
- round.transform.localScale = new Vector3(0, 0, 0);
- round.gameObject.SetActive(true);
- });
- seq.Append(round.transform.DOScale(new Vector3(1.1f, 1.1f, 1f), 0.6f));
- seq.Append(round.transform.DOScale(new Vector3(1, 1, 1), 0.6f));
- seq.Append(round.transform.GetComponent<Text>().DOFade(0, 0.3f));
- }
- seq.AppendCallback(delegate() {
- mask.gameObject.SetActive(true);
- });
- seq.Append(mask.DOFade(1, 0.5f));
- seq.AppendCallback(delegate() {
- panel.gameObject.SetActive(true);
- });
- seq.Append(mask.DOFade(0, 1f));
- seq.AppendInterval(1f);
- seq.Append(panel.DOScaleX(0, 0.4f));
- seq.AppendCallback(delegate() {
- Destroy(this.gameObject);
- });
- }
- }
|