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().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(), this); this.transform.Find("Panel/Name").GetComponent().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(), this, avatarID, avatarUrl ); this.transform.Find("Panel/Name").GetComponent().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(); Transform panel = this.transform.Find("Panel"); TextAutoLanguage round = this.transform.Find("Round").GetComponent(); 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().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); }); } }