PKGameReadyView.cs 4.4 KB

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