PKGameReadyView_Challenge.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_Challenge : MonoBehaviour
  8. {
  9. GameMode gameMode;
  10. [System.NonSerialized] public int currentPlayerIndex = 0;
  11. bool isDiscarded = false;//丢弃的
  12. static PKGameReadyView_Challenge ins;
  13. void Awake()
  14. {
  15. if (ins) {
  16. ins.isDiscarded = true;
  17. Destroy(ins.gameObject);
  18. }
  19. ins = this;
  20. GameMgr.ins.addLockerForGamePause(this);
  21. }
  22. void Start()
  23. {
  24. if (isDiscarded) return;
  25. gameMode = GameMgr.ins.gameMode;
  26. GameObject.FindObjectOfType<ArmBow>().Hide();
  27. RenderPlayerInfo();
  28. RunAnimation();
  29. }
  30. void RenderPlayerInfo() {
  31. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  32. int curPlayerIndex = ((ChallengeGameModeLocalPK) gameMode).GetCurrentPlayIndex();
  33. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[curPlayerIndex]);
  34. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  35. this.transform.Find("Panel/Name").GetComponent<Text>().text = nickName;
  36. }
  37. else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  38. int curPlayerIndex = ((ChallengeGameModeLocalPK) gameMode).GetCurrentPlayIndex();
  39. Sprite avatar = RoleMgr.GetAvatar(GlobalData.matchPlayerInfos[curPlayerIndex].avatarID);
  40. string nickname = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
  41. this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  42. this.transform.Find("Panel/Name").GetComponent<Text>().text = nickname;
  43. }
  44. }
  45. void RunAnimation() {
  46. Image mask = this.transform.Find("Mask").GetComponent<Image>();
  47. Transform panel = this.transform.Find("Panel");
  48. Sequence seq = DOTween.Sequence();
  49. seq.AppendCallback(delegate() {
  50. mask.gameObject.SetActive(true);
  51. });
  52. seq.Append(mask.DOFade(1, 0.5f));
  53. seq.AppendCallback(delegate() {
  54. panel.gameObject.SetActive(true);
  55. });
  56. seq.Append(mask.DOFade(0, 1f));
  57. seq.AppendInterval(1f);
  58. seq.Append(panel.DOScaleX(0, 0.4f));
  59. seq.AppendCallback(delegate() {
  60. Destroy(this.gameObject);
  61. });
  62. seq.SetUpdate(true);
  63. }
  64. void OnDestroy()
  65. {
  66. if (ins == this) ins = null;
  67. if (GameMgr.ins) GameMgr.ins.removeLockerForGamePause(this);
  68. if (isDiscarded) return;
  69. if (ArmBow.ins) ArmBow.ins.Show();
  70. gameMode.UnbanBowReady();
  71. }
  72. }