PKGameReadyView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using DG.Tweening;
  6. /* PK模式的轮换选手的准备界面 */
  7. public class PKGameReadyView : MonoBehaviour
  8. {
  9. PKGameMode pKGameMode;
  10. PKGameMode_OnlinePK pKGameMode_OnlinePK;
  11. public bool showRound = false;
  12. bool isDiscarded = false;//丢弃的
  13. static PKGameReadyView ins;
  14. void Start()
  15. {
  16. if (ins) {
  17. ins.isDiscarded = true;
  18. Destroy(ins.gameObject);
  19. }
  20. ins = this;
  21. GameObject.FindObjectOfType<ArmBow>().Hide();
  22. InitPKGameMode();
  23. RenderPlayerInfo();
  24. RunAnimation();
  25. }
  26. void OnDestroy()
  27. {
  28. if (ins == this) ins = null;
  29. if (isDiscarded) return;
  30. if (ArmBow.ins) ArmBow.ins.Show();
  31. if (GameMgr.ins) GameMgr.ins.gameMode.UnbanBowReady();
  32. }
  33. void InitPKGameMode() {
  34. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  35. pKGameMode = (PKGameMode) GameMgr.ins.gameMode;
  36. }
  37. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  38. pKGameMode_OnlinePK = (PKGameMode_OnlinePK) GameMgr.ins.gameMode;
  39. }
  40. }
  41. void RenderPlayerInfo() {
  42. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  43. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[pKGameMode.currentPlayerIndex]);
  44. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  45. this.transform.Find("Panel/Name").GetComponent<Text>().text = nickName;
  46. }
  47. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  48. int curPlayerIndex = pKGameMode_OnlinePK.gameLogic.currentPlayerIndex;
  49. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(GlobalData.matchPlayerInfos[curPlayerIndex].avatarID);
  50. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  51. this.transform.Find("Panel/Name").GetComponent<Text>().text = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
  52. }
  53. }
  54. void RunAnimation() {
  55. // get data
  56. int roundNum = 0;
  57. int showRoundValue = 0;
  58. System.Action setShowRoundValue = null;
  59. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  60. roundNum = pKGameMode.round;
  61. showRoundValue = pKGameMode.showRoundValue;
  62. setShowRoundValue = () => {
  63. pKGameMode.showRoundValue = roundNum;
  64. };
  65. }
  66. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  67. roundNum = pKGameMode_OnlinePK.gameLogic.round;
  68. showRoundValue = pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView;
  69. setShowRoundValue = () => {
  70. pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView = roundNum;
  71. };
  72. } else {
  73. throw new System.Exception("pkMatchType Error");
  74. }
  75. // animate
  76. Image mask = this.transform.Find("Mask").GetComponent<Image>();
  77. Transform panel = this.transform.Find("Panel");
  78. TextAutoLanguage round = this.transform.Find("Round").GetComponent<TextAutoLanguage>();
  79. Sequence seq = DOTween.Sequence();
  80. if (showRoundValue < roundNum) {
  81. setShowRoundValue?.Invoke();
  82. seq.AppendCallback(delegate() {
  83. round.textFormatArgs = new string[]{roundNum.ToString()};
  84. round.transform.localScale = new Vector3(0, 0, 0);
  85. round.gameObject.SetActive(true);
  86. });
  87. seq.Append(round.transform.DOScale(new Vector3(1.1f, 1.1f, 1f), 0.6f));
  88. seq.Append(round.transform.DOScale(new Vector3(1, 1, 1), 0.6f));
  89. seq.Append(round.transform.GetComponent<Text>().DOFade(0, 0.3f));
  90. }
  91. seq.AppendCallback(delegate() {
  92. mask.gameObject.SetActive(true);
  93. });
  94. seq.Append(mask.DOFade(1, 0.5f));
  95. seq.AppendCallback(delegate() {
  96. panel.gameObject.SetActive(true);
  97. });
  98. seq.Append(mask.DOFade(0, 1f));
  99. seq.AppendInterval(1f);
  100. seq.Append(panel.DOScaleX(0, 0.4f));
  101. seq.AppendCallback(delegate() {
  102. Destroy(this.gameObject);
  103. });
  104. }
  105. }