UIManager.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. namespace HyperspaceGame
  7. {
  8. public class UIManager : MonoBehaviour
  9. {
  10. public static UIManager _ins;
  11. /// <summary>
  12. /// ��¼һ���ܷ�
  13. /// </summary>
  14. public static int mHyperspaceScore { get; set; } = 0;
  15. [SerializeField] Button _btnQuit;
  16. [SerializeField] Button _btnReload;
  17. [SerializeField] Button _btnCrosshair;
  18. [SerializeField] Button _btnCalibrationOffset;
  19. [SerializeField] Material outlight;
  20. //׼�IJ���
  21. private bool open = false;
  22. private bool visiable = false;
  23. private bool onlyShow = true;
  24. private Image image = null;
  25. private void Awake()
  26. {
  27. if (_ins != null && _ins != this)
  28. {
  29. //Destroy(this.gameObject); // ����Ѿ�����ʵ���������ٵ�ǰ����
  30. return;
  31. }
  32. _ins = this;
  33. //DontDestroyOnLoad(this.gameObject); // ��֤�����ڳ����л�ʱ��������
  34. //����ʱ���ʼ��һ��״̬
  35. if (ShootCheck.ins) ShootCheck.ins.bluetoothDeviceStatus = SmartBowSDK.BluetoothDeviceStatus.MagazineLoading;
  36. }
  37. private void OnDestroy()
  38. {
  39. if (_ins == this)
  40. {
  41. _ins = null; // ������ʱ�ͷŵ���
  42. }
  43. GlobalEventCenter.ins.onSimulateMouseAwakeChanged -= UpdateHideShow;
  44. }
  45. // Start is called before the first frame update
  46. void Start()
  47. {
  48. //�ر�ԭ��׼��
  49. SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
  50. image = GeneratingTarget.gm.shootingEvent.GetComponent<Image>();
  51. //b�˵���
  52. if (CommonConfig.StandaloneModeOrPlatformB)
  53. {
  54. _btnCrosshair.gameObject.SetActive(false);
  55. _btnCalibrationOffset.gameObject.SetActive(false);
  56. } else {
  57. //��ȡ����ֵ��һ���洢ֵ
  58. bool onInitOpen = InfraredDemo._ins ? InfraredDemo._ins.bInitCrosshairShow() : true;
  59. Image crossHairImage = _btnCrosshair.GetComponentInChildren<Image>();
  60. crossHairImage.material = onInitOpen ? outlight : null;
  61. _btnCrosshair.onClick.AddListener(delegate () {
  62. AudioMgr.ins.PlayBtn();
  63. bool onlyShow = !GetOnlyShow();
  64. SetOnlyShow(onlyShow);
  65. //��¼׼��ֵ
  66. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  67. if (onlyShow)
  68. {
  69. crossHairImage.material = outlight;
  70. }
  71. else
  72. {
  73. crossHairImage.material = null;
  74. }
  75. });
  76. //У׼
  77. _btnCalibrationOffset.onClick.AddListener(delegate () {
  78. AudioMgr.ins.PlayBtn();
  79. AutoResetView.DoIdentity();
  80. });
  81. }
  82. _btnQuit.onClick.AddListener(OnShutDown);
  83. _btnReload.onClick.AddListener(Reload);
  84. SetOpen(UserSettings.ins.openCrossHair);
  85. visiable = open;
  86. OnValueChanged(visiable);
  87. UpdateHideShow(SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked);
  88. GlobalEventCenter.ins.onSimulateMouseAwakeChanged += UpdateHideShow;
  89. //CrossHairOutBoundChecker1 outBoundChecker = Instantiate(Resources.Load<GameObject>("Prefabs/CrossHairOutBoundChecker1")).GetComponent<CrossHairOutBoundChecker1>();
  90. //outBoundChecker.crossHair = transform as RectTransform;
  91. //��ȡ׼��ֵ
  92. if (InfraredDemo._ins) SetOnlyShow(InfraredDemo._ins.getCrosshairValue() == 1);
  93. }
  94. void UpdateHideShow(bool mouseAwaked)
  95. {
  96. //transform.Find("Image").GetComponent<Image>().enabled = !mouseAwaked;
  97. SetOnlyShow(!mouseAwaked);
  98. }
  99. public void ShowQuit()
  100. {
  101. _btnQuit.gameObject.SetActive(true);
  102. }
  103. void OnShutDown()
  104. {
  105. //SceneManager.LoadScene("Home",LoadSceneMode.Single);
  106. GeneratingTarget.gm.onUploadScore();
  107. //������Ϸҳ��
  108. GeneratingTarget.gm.userGameAnalyse1.showResultView(() =>
  109. {
  110. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  111. });
  112. }
  113. public void Reload()
  114. {
  115. GeneratingTarget.gm.OnSeparation();
  116. GeneratingTarget.gm.OnLoading();
  117. }
  118. public bool GetArrowBtnState()
  119. {
  120. if (open)
  121. return true;
  122. return false;
  123. }
  124. // Update is called once per frame
  125. void Update()
  126. {
  127. if (AutoResetView.ins != null)
  128. {
  129. //����У׼ʱ��һ����ʾ׼��
  130. SetVisiable(true);
  131. }
  132. else
  133. {
  134. if (open)
  135. SetVisiable(onlyShow);
  136. else
  137. SetVisiable(false);
  138. }
  139. }
  140. void SetVisiable(bool value)
  141. {
  142. if (this.visiable == value) return;
  143. this.visiable = value;
  144. OnValueChanged(this.visiable);
  145. }
  146. void OnValueChanged(bool isOn)
  147. {
  148. var color = image.color;
  149. if (isOn)
  150. {
  151. color.a = 1;
  152. image.color = color;
  153. //_togImge.sprite = _togSprites[0];
  154. }
  155. else
  156. {
  157. color.a = 0;
  158. image.color = color;
  159. //_togImge.sprite = _togSprites[1];
  160. }
  161. }
  162. public void SetOpen(bool open)
  163. {
  164. this.open = open;
  165. if (!this.open)
  166. {
  167. SetVisiable(false);
  168. }
  169. }
  170. public bool GetOpen()
  171. {
  172. return this.open;
  173. }
  174. public void SetOnlyShow(bool onlyShow)
  175. {
  176. this.onlyShow = onlyShow;
  177. }
  178. public bool GetOnlyShow()
  179. {
  180. return this.onlyShow;
  181. }
  182. }
  183. }