PKGameReadyView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. public 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 (isDiscarded) return;
  29. GameObject.FindObjectOfType<ArmBow>().Show();
  30. GameMgr.ins.gameMode.UnbanBowReady();
  31. }
  32. void InitPKGameMode() {
  33. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  34. pKGameMode = (PKGameMode) GameMgr.ins.gameMode;
  35. }
  36. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  37. pKGameMode_OnlinePK = (PKGameMode_OnlinePK) GameMgr.ins.gameMode;
  38. }
  39. }
  40. void RenderPlayerInfo() {
  41. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  42. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[pKGameMode.currentPlayerIndex]);
  43. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  44. this.transform.Find("Panel/Name").GetComponent<Text>().text = nickName;
  45. }
  46. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  47. int curPlayerIndex = pKGameMode_OnlinePK.gameLogic.currentPlayerIndex;
  48. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(GlobalData.matchPlayerInfos[curPlayerIndex].avatarID);
  49. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  50. this.transform.Find("Panel/Name").GetComponent<Text>().text = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
  51. }
  52. }
  53. void RunAnimation() {
  54. // get data
  55. int roundNum = 0;
  56. int showRoundValue = 0;
  57. System.Action setShowRoundValue = null;
  58. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  59. roundNum = pKGameMode.round;
  60. showRoundValue = pKGameMode.showRoundValue;
  61. setShowRoundValue = () => {
  62. pKGameMode.showRoundValue = roundNum;
  63. };
  64. }
  65. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  66. roundNum = pKGameMode_OnlinePK.gameLogic.round;
  67. showRoundValue = pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView;
  68. setShowRoundValue = () => {
  69. pKGameMode_OnlinePK.gameDisplay.showRoundValueOnReadyView = roundNum;
  70. };
  71. } else {
  72. throw new System.Exception("pkMatchType Error");
  73. }
  74. // animate
  75. Image mask = this.transform.Find("Mask").GetComponent<Image>();
  76. Transform panel = this.transform.Find("Panel");
  77. TextAutoLanguage round = this.transform.Find("Round").GetComponent<TextAutoLanguage>();
  78. Sequence seq = DOTween.Sequence();
  79. if (showRoundValue < roundNum) {
  80. setShowRoundValue?.Invoke();
  81. seq.AppendCallback(delegate() {
  82. round.textFormatArgs = new string[]{roundNum.ToString()};
  83. round.transform.localScale = new Vector3(0, 0, 0);
  84. round.gameObject.SetActive(true);
  85. });
  86. seq.Append(round.transform.DOScale(new Vector3(1.1f, 1.1f, 1f), 0.6f));
  87. seq.Append(round.transform.DOScale(new Vector3(1, 1, 1), 0.6f));
  88. seq.Append(round.transform.GetComponent<Text>().DOFade(0, 0.3f));
  89. }
  90. seq.AppendCallback(delegate() {
  91. mask.gameObject.SetActive(true);
  92. });
  93. seq.Append(mask.DOFade(1, 0.5f));
  94. seq.AppendCallback(delegate() {
  95. panel.gameObject.SetActive(true);
  96. });
  97. seq.Append(mask.DOFade(0, 1f));
  98. seq.AppendInterval(1f);
  99. seq.Append(panel.DOScaleX(0, 0.4f));
  100. seq.AppendCallback(delegate() {
  101. Destroy(this.gameObject);
  102. });
  103. }
  104. }