InfraredGuider.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public enum TipStep {
  6. None = 0,
  7. //准心显示和隐藏
  8. CrossHairTip = 1,
  9. //校准偏移量
  10. CalibrationOffset =2,
  11. //完成
  12. Finish = 3,
  13. }
  14. public class InfraredGuider : MonoBehaviour
  15. {
  16. public GameObject infraredLightGuider;
  17. public GameObject infraredLightGuider2;
  18. public GameObject infraredResulutionGuider;
  19. public Button resulutionButton;
  20. public GameObject Title1ARTEMISPro;
  21. public GameObject Title1GunPro;
  22. public GameObject Title1;
  23. public GameObject Title2;
  24. //准心
  25. public GameObject TitleCrossHair; //HOUYIPro
  26. public GameObject TitleCrossHair2;//ARTEMISProGun
  27. public GameObject TitleCrossHairGun;//Gun
  28. public TipStep mTipStep { get; private set; } = TipStep.None;
  29. public int collisionCount = 0;
  30. bool bRemove = false;
  31. //相机感光部分
  32. [SerializeField]
  33. Slider slider;
  34. [Tooltip("异常校准时候步骤1")]
  35. public GameObject Step1;
  36. [Tooltip("正常游戏流程步骤2")]
  37. public GameObject Step2;
  38. [Tooltip("异常问题时候文字提示步骤1")]
  39. public GameObject Step3;
  40. // Start is called before the first frame update
  41. void Start()
  42. {
  43. if (InfraredDemo._ins)
  44. {
  45. slider.onValueChanged.AddListener((value) =>
  46. {
  47. InfraredDemo._ins.onSliderEvent(value, "PU_BRIGHTNESS");
  48. });
  49. InfraredDemo._ins.onSetSliderValue(slider, "PU_BRIGHTNESS");
  50. }
  51. #if UNITY_STANDALONE_WIN || UNITY_EDITOR
  52. resulutionButton.gameObject.SetActive(false);
  53. #endif
  54. ////枪暂时不显示
  55. //if (BluetoothAim.ins.isMainConnectToGun()) {
  56. // SetTipState(TipStep.None);
  57. //}
  58. //else
  59. ////切换ARTEMISPro
  60. //if (BluetoothAim.ins.isMainConnectToARTEMISPRO()) {
  61. // SetTipState(TipStep.CrossHairTip);
  62. //}
  63. }
  64. public void enterLightView() {
  65. Instantiate(infraredLightGuider);
  66. }
  67. public void enterInfraredResulutionGuider() {
  68. #if UNITY_ANDROID
  69. Instantiate(infraredResulutionGuider);
  70. #endif
  71. }
  72. public void ExitGuider() {
  73. GameAssistUI.ins.onBtnBack();
  74. }
  75. /// <summary>
  76. /// 校准后到达最后一步射击退出
  77. /// </summary>
  78. public void SetTitleAfterCalibration() {
  79. SetTipState(TipStep.Finish);
  80. }
  81. /// <summary>
  82. /// 进入相机感光度的页面
  83. /// </summary>
  84. public void enterInfraredLightGuider2()
  85. {
  86. #if UNITY_ANDROID
  87. Instantiate(infraredLightGuider2);
  88. #endif
  89. }
  90. /// <summary>
  91. /// 硬件按键按下
  92. /// </summary>
  93. public void onClickDevice() {
  94. //infraredGuider 待检测到用户操作了两次单击按键功能,进入下一步
  95. if (mTipStep == TipStep.CrossHairTip)
  96. {
  97. Button crossHairBtn = GameAssistUI.ins.transform.Find("Button5").GetComponent<Button>();
  98. crossHairBtn.onClick.Invoke();
  99. if (GameMgr.ButtonCount == 1)
  100. {
  101. GameMgr.ButtonCount = 0;
  102. //进入到偏移校准
  103. SetTipState(TipStep.CalibrationOffset);
  104. }
  105. else
  106. {
  107. GameMgr.ButtonCount++;
  108. }
  109. }
  110. }
  111. /// <summary>
  112. /// 长按或者栓剂触发
  113. /// </summary>
  114. public void onLongClickDevice()
  115. {
  116. if (Title1.activeSelf || Title1ARTEMISPro.activeSelf || Title1GunPro.activeSelf || Title2.activeSelf)
  117. {
  118. AutoResetView.onInfraredGuiderAutoResetView();
  119. }
  120. }
  121. /// <summary>
  122. /// 根据enum操作ui
  123. /// </summary>
  124. /// <param name="tipStep"></param>
  125. public void SetTipState(TipStep tipStep = TipStep.None) {
  126. mTipStep = tipStep;
  127. switch (tipStep)
  128. {
  129. case TipStep.None://全部隐藏
  130. AllTipFalse();
  131. break;
  132. case TipStep.CrossHairTip:
  133. AllTipFalse();
  134. if (BluetoothAim.ins.isMainConnectToHOUYIPRO())
  135. {
  136. TitleCrossHair.SetActive(true);
  137. }
  138. else if (BluetoothAim.ins.isMainConnectToARTEMISPRO())
  139. {
  140. TitleCrossHair2.SetActive(true);
  141. } else if (BluetoothAim.ins.isMainConnectToGun()) {
  142. TitleCrossHairGun.SetActive(true);
  143. }
  144. break;
  145. case TipStep.CalibrationOffset:
  146. AllTipFalse();
  147. //按照连接的类型来区分
  148. if (BluetoothAim.ins.isMainConnectToHOUYIPRO())
  149. {
  150. Title1.SetActive(true);
  151. }
  152. else if (BluetoothAim.ins.isMainConnectToARTEMISPRO())
  153. {
  154. Title1ARTEMISPro.SetActive(true);
  155. }else if (BluetoothAim.ins.isMainConnectToGun())
  156. {
  157. Title1GunPro.SetActive(true);
  158. }
  159. break;
  160. case TipStep.Finish:
  161. AllTipFalse();
  162. Title2.SetActive(true);
  163. break;
  164. }
  165. }
  166. void AllTipFalse() {
  167. TitleCrossHair.SetActive(false);
  168. TitleCrossHair2.SetActive(false);
  169. TitleCrossHairGun.SetActive(false);
  170. Title1.SetActive(false);
  171. Title2.SetActive(false);
  172. Title1ARTEMISPro.SetActive(false);
  173. Title1GunPro.SetActive(false);
  174. }
  175. /// <summary>
  176. /// 异常问题处理时候的文字提示步骤页面
  177. /// </summary>
  178. public void OnStep3TextTip()
  179. {
  180. if (Step1.activeSelf && !bRemove)
  181. {
  182. bRemove = true;
  183. StartCoroutine(delaySet());
  184. }
  185. Step1.SetActive(false);
  186. Step2.SetActive(false);
  187. Step3.SetActive(true);
  188. SetTipState(TipStep.CrossHairTip);
  189. }
  190. /// <summary>
  191. /// 检测四个角跳转到准心开关界面
  192. /// </summary>
  193. public void OnStep2ShootTest()
  194. {
  195. Debug.Log("OnStep2ShootTest hui 1:" + Step1.activeSelf + " = " + bRemove);
  196. if (Step1.activeSelf && !bRemove)
  197. {
  198. bRemove = true;
  199. StartCoroutine(delaySet());
  200. Debug.Log("OnStep2ShootTest delaySet:" + Step1.activeSelf + " = " + bRemove);
  201. }
  202. Step1.SetActive(false);
  203. Step2.SetActive(true);
  204. Step3.SetActive(false);
  205. SetTipState(TipStep.CrossHairTip);
  206. }
  207. IEnumerator delaySet() {
  208. yield return new WaitForSeconds(0.5f);
  209. SimulateMouseController.ins?.RemoveOpenLocker(this);
  210. }
  211. public void SetCollisionEvent() {
  212. if (collisionCount < 3)
  213. {
  214. collisionCount++;
  215. }
  216. else {
  217. //进入下一步
  218. OnStep2ShootTest();
  219. }
  220. }
  221. void OnEnable()
  222. {
  223. SimulateMouseController.ins?.AddOpenLocker(this);
  224. }
  225. //void OnDisable()
  226. //{
  227. //}
  228. //private void Update()
  229. //{
  230. // if (Input.GetKeyDown(KeyCode.Alpha5))
  231. // {
  232. // onLongClickDevice();
  233. // }
  234. //}
  235. }