VRMiniGameScoreBoard.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. public class VRMiniGameScoreBoard : MonoBehaviour
  6. {
  7. public int score
  8. {
  9. get
  10. {
  11. return this.m_Score;
  12. }
  13. set
  14. {
  15. if (this.m_Score != value)
  16. {
  17. this.m_Score = value;
  18. }
  19. }
  20. }
  21. public int life
  22. {
  23. get
  24. {
  25. return this.m_Life;
  26. }
  27. set
  28. {
  29. if (this.m_Life != value)
  30. {
  31. this.m_Life = value;
  32. this.m_TextLife.text = "残弾数:" + this.m_Life.ToString();
  33. }
  34. }
  35. }
  36. public static VRMiniGameScoreBoard Create(Vector3 WorldPos, Quaternion Qt)
  37. {
  38. VRMiniGameScoreBoard vrminiGameScoreBoard = UnityEngine.Object.FindObjectOfType<VRMiniGameScoreBoard>();
  39. GameObject gameObject;
  40. if (!vrminiGameScoreBoard)
  41. {
  42. string path = "SceneVRCommunication/Tablet/MiniGameScoreBoard";
  43. UnityEngine.Object original = Resources.Load(path);
  44. gameObject = (UnityEngine.Object.Instantiate(original, WorldPos, Qt) as GameObject);
  45. }
  46. else
  47. {
  48. gameObject = vrminiGameScoreBoard.gameObject;
  49. }
  50. gameObject.GetComponent<VRMiniGameScoreBoard>().Init();
  51. gameObject.GetComponent<UICanvasFade>().FadeIn();
  52. return gameObject.GetComponent<VRMiniGameScoreBoard>();
  53. }
  54. private void Init()
  55. {
  56. this.m_ParentPlayingUI.gameObject.SetActive(true);
  57. this.m_ParentResultUI.gameObject.SetActive(false);
  58. this.score = 0;
  59. this.life = 10;
  60. }
  61. private void Update()
  62. {
  63. int num = this.m_Score - this.m_CalculatingScore;
  64. if (num > 10)
  65. {
  66. this.m_CalculatingScore++;
  67. }
  68. else
  69. {
  70. if (num <= 0)
  71. {
  72. return;
  73. }
  74. this.m_CalculatingScore++;
  75. }
  76. this.m_TextScore.text = this.m_CalculatingScore.ToString("00");
  77. }
  78. private void OnEnable()
  79. {
  80. this.m_TextScore.text = this.m_Score.ToString("00");
  81. this.m_TextLife.text = "残弾数:" + this.m_Life.ToString();
  82. }
  83. public void Result(string message, UnityAction callback)
  84. {
  85. this.m_ParentResultUI.gameObject.SetActive(true);
  86. this.m_ParentPlayingUI.gameObject.SetActive(false);
  87. this.m_TextResultMessage.text = message;
  88. UICanvasFade fade = base.GetComponent<UICanvasFade>();
  89. this.m_ButtonExit.onClick.RemoveAllListeners();
  90. this.m_ButtonExit.onClick.AddListener(delegate()
  91. {
  92. fade.FadeOut(fade.fadeTime, fade.isTimeScaling, delegate()
  93. {
  94. callback();
  95. });
  96. });
  97. }
  98. [SerializeField]
  99. private RectTransform m_ParentPlayingUI;
  100. [SerializeField]
  101. private Text m_TextScore;
  102. [SerializeField]
  103. private Text m_TextLife;
  104. [SerializeField]
  105. private RectTransform m_ParentResultUI;
  106. [SerializeField]
  107. private Text m_TextResultMessage;
  108. [SerializeField]
  109. private Button m_ButtonExit;
  110. [SerializeField]
  111. private int m_Score;
  112. private int m_CalculatingScore;
  113. [SerializeField]
  114. private int m_Life = 10;
  115. }