InfraredGuider.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. setShowTime(Title1);
  152. }
  153. else if (BluetoothAim.ins.isMainConnectToARTEMISPRO())
  154. {
  155. Title1ARTEMISPro.SetActive(true);
  156. setShowTime(Title1ARTEMISPro);
  157. }
  158. else if (BluetoothAim.ins.isMainConnectToGun())
  159. {
  160. Title1GunPro.SetActive(true);
  161. setShowTime(Title1GunPro);
  162. }
  163. break;
  164. case TipStep.Finish:
  165. AllTipFalse();
  166. Title2.SetActive(true);
  167. break;
  168. }
  169. }
  170. /**
  171. * 根据不同的设备设置时间
  172. */
  173. void setShowTime(GameObject obj) {
  174. float time = GlobalData.MyDeviceMode == DeviceMode.Gun ? CommonConfig.calibrationTimeGun : CommonConfig.calibrationTimeArchery;
  175. TextAutoLanguage2 language2 = obj.GetComponent<TextAutoLanguage2>();
  176. language2.textFormatArgs = new object[] { Mathf.CeilToInt(time) };
  177. language2.ApplyToText();
  178. }
  179. void AllTipFalse() {
  180. TitleCrossHair.SetActive(false);
  181. TitleCrossHair2.SetActive(false);
  182. TitleCrossHairGun.SetActive(false);
  183. Title1.SetActive(false);
  184. Title2.SetActive(false);
  185. Title1ARTEMISPro.SetActive(false);
  186. Title1GunPro.SetActive(false);
  187. }
  188. /// <summary>
  189. /// 异常问题处理时候的文字提示步骤页面
  190. /// </summary>
  191. public void OnStep3TextTip()
  192. {
  193. if (Step1.activeSelf && !bRemove)
  194. {
  195. bRemove = true;
  196. StartCoroutine(delaySet());
  197. }
  198. Step1.SetActive(false);
  199. Step2.SetActive(false);
  200. Step3.SetActive(true);
  201. SetTipState(TipStep.CrossHairTip);
  202. }
  203. /// <summary>
  204. /// 检测四个角跳转到准心开关界面
  205. /// </summary>
  206. public void OnStep2ShootTest()
  207. {
  208. Debug.Log("OnStep2ShootTest hui 1:" + Step1.activeSelf + " = " + bRemove);
  209. if (Step1.activeSelf && !bRemove)
  210. {
  211. bRemove = true;
  212. StartCoroutine(delaySet());
  213. Debug.Log("OnStep2ShootTest delaySet:" + Step1.activeSelf + " = " + bRemove);
  214. }
  215. Step1.SetActive(false);
  216. Step2.SetActive(true);
  217. Step3.SetActive(false);
  218. SetTipState(TipStep.CrossHairTip);
  219. }
  220. IEnumerator delaySet() {
  221. yield return new WaitForSeconds(0.5f);
  222. SimulateMouseController.ins?.RemoveOpenLocker(this);
  223. }
  224. public void SetCollisionEvent() {
  225. if (collisionCount < 3)
  226. {
  227. collisionCount++;
  228. }
  229. else {
  230. //进入下一步
  231. OnStep2ShootTest();
  232. }
  233. }
  234. void OnEnable()
  235. {
  236. SimulateMouseController.ins?.AddOpenLocker(this);
  237. }
  238. //void OnDisable()
  239. //{
  240. //}
  241. #if UNITY_EDITOR
  242. private void Update()
  243. {
  244. //跳过引导
  245. if (Input.GetKeyDown(KeyCode.Alpha5))
  246. {
  247. onClickDevice();
  248. }
  249. if (Input.GetKeyDown(KeyCode.Alpha6))
  250. {
  251. onLongClickDevice();
  252. }
  253. }
  254. #endif
  255. }