PKGameReadyView.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. string nickName = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[pKGameMode.currentPlayerIndex],
  44. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>(), this);
  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. int avatarID = GlobalData.matchPlayerInfos[curPlayerIndex].avatarID;
  50. string avatarUrl = GlobalData.matchPlayerInfos[curPlayerIndex].avatarUrl;
  51. string nickname = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
  52. RoleMgr.SetAvatarToImage(
  53. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>(),
  54. this,
  55. avatarID, avatarUrl
  56. );
  57. this.transform.Find("Panel/Name").GetComponent<Text>().text = nickname;
  58. }
  59. }
  60. void RunAnimation() {
  61. // get data
  62. int roundNum = 0;
  63. int showRoundValue = 0;
  64. System.Action setShowRoundValue = null;
  65. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  66. roundNum = pKGameMode.round;
  67. showRoundValue = pKGameMode.showRoundValue;
  68. setShowRoundValue = () => {
  69. pKGameMode.showRoundValue = roundNum;
  70. };
  71. }
  72. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  73. roundNum = pKGameMode_OnlinePK.gameLogic.round;
  74. showRoundValue = pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView;
  75. setShowRoundValue = () => {
  76. pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView = roundNum;
  77. };
  78. } else {
  79. throw new System.Exception("pkMatchType Error");
  80. }
  81. // animate
  82. Image mask = this.transform.Find("Mask").GetComponent<Image>();
  83. Transform panel = this.transform.Find("Panel");
  84. TextAutoLanguage round = this.transform.Find("Round").GetComponent<TextAutoLanguage>();
  85. Sequence seq = DOTween.Sequence();
  86. if (showRoundValue < roundNum) {
  87. setShowRoundValue?.Invoke();
  88. seq.AppendCallback(delegate() {
  89. round.textFormatArgs = new string[]{roundNum.ToString()};
  90. round.transform.localScale = new Vector3(0, 0, 0);
  91. round.gameObject.SetActive(true);
  92. });
  93. seq.Append(round.transform.DOScale(new Vector3(1.1f, 1.1f, 1f), 0.6f));
  94. seq.Append(round.transform.DOScale(new Vector3(1, 1, 1), 0.6f));
  95. seq.Append(round.transform.GetComponent<Text>().DOFade(0, 0.3f));
  96. }
  97. seq.AppendCallback(delegate() {
  98. mask.gameObject.SetActive(true);
  99. });
  100. seq.Append(mask.DOFade(1, 0.5f));
  101. seq.AppendCallback(delegate() {
  102. panel.gameObject.SetActive(true);
  103. });
  104. seq.Append(mask.DOFade(0, 1f));
  105. seq.AppendInterval(1f);
  106. seq.Append(panel.DOScaleX(0, 0.4f));
  107. seq.AppendCallback(delegate() {
  108. Destroy(this.gameObject);
  109. });
  110. }
  111. }