InfraredGuider.cs 6.5 KB

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