InfraredGuider.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. //根据mTipStep显示当前页数
  30. public Sprite[] pageSprites;
  31. public Image pageSprite;
  32. public int collisionCount = 0;
  33. bool bRemove = false;
  34. //相机感光部分
  35. [SerializeField]
  36. Slider slider;
  37. [Tooltip("异常校准时候步骤1")]
  38. public GameObject Step1;
  39. [Tooltip("正常游戏流程步骤2")]
  40. public GameObject Step2;
  41. [Tooltip("异常问题时候文字提示步骤1")]
  42. public GameObject Step3;
  43. // Start is called before the first frame update
  44. void Start()
  45. {
  46. if (InfraredDemo._ins)
  47. {
  48. slider.onValueChanged.AddListener((value) =>
  49. {
  50. InfraredDemo._ins.onSliderEvent(value, "PU_BRIGHTNESS");
  51. });
  52. InfraredDemo._ins.onSetSliderValue(slider, "PU_BRIGHTNESS");
  53. }
  54. #if UNITY_STANDALONE_WIN || UNITY_EDITOR
  55. resulutionButton.gameObject.SetActive(false);
  56. #endif
  57. ////枪暂时不显示
  58. //if (BluetoothAim.ins.isMainConnectToGun()) {
  59. // SetTipState(TipStep.None);
  60. //}
  61. //else
  62. ////切换ARTEMISPro
  63. //if (BluetoothAim.ins.isMainConnectToARTEMISPRO()) {
  64. // SetTipState(TipStep.CrossHairTip);
  65. //}
  66. }
  67. public void enterLightView() {
  68. Instantiate(infraredLightGuider);
  69. }
  70. public void enterInfraredResulutionGuider() {
  71. #if UNITY_ANDROID || UNITY_IOS
  72. Instantiate(infraredResulutionGuider);
  73. #endif
  74. }
  75. public void ExitGuider() {
  76. GameAssistUI.ins.onBtnBack();
  77. }
  78. /// <summary>
  79. /// 校准后到达最后一步射击退出
  80. /// </summary>
  81. public void SetTitleAfterCalibration() {
  82. SetTipState(TipStep.Finish);
  83. }
  84. /// <summary>
  85. /// 进入相机感光度的页面
  86. /// </summary>
  87. public void enterInfraredLightGuider2()
  88. {
  89. #if UNITY_ANDROID || UNITY_IOS
  90. Instantiate(infraredLightGuider2);
  91. #endif
  92. }
  93. /// <summary>
  94. /// 硬件按键按下
  95. /// </summary>
  96. public void onClickDevice() {
  97. //infraredGuider 待检测到用户操作了两次单击按键功能,进入下一步
  98. if (mTipStep == TipStep.CrossHairTip)
  99. {
  100. Button crossHairBtn = GameAssistUI.ins.transform.Find("Button5").GetComponent<Button>();
  101. crossHairBtn.onClick.Invoke();
  102. if (GameMgr.ButtonCount == 1)
  103. {
  104. GameMgr.ButtonCount = 0;
  105. //进入到偏移校准
  106. SetTipState(TipStep.CalibrationOffset);
  107. }
  108. else
  109. {
  110. GameMgr.ButtonCount++;
  111. //这里点击第二次为步骤2
  112. pageSprite.sprite = pageSprites[1];
  113. if (TitleCrossHair.activeSelf)
  114. {
  115. //HOUYI
  116. TitleCrossHair.GetComponent<TextAutoLanguage2>().SetTextKey("TopTip_CrossHair2");
  117. }
  118. else if (TitleCrossHair2.activeSelf)
  119. {
  120. //Artemis Pro
  121. TitleCrossHair2.GetComponent<TextAutoLanguage2>().SetTextKey("TopTip_CrossHairGunPro2");
  122. }
  123. else if (TitleCrossHairGun.activeSelf) {
  124. //GUN
  125. TitleCrossHairGun.GetComponent<TextAutoLanguage2>().SetTextKey("TopTip_CrossHairGunPro2");
  126. }
  127. }
  128. }
  129. }
  130. /// <summary>
  131. /// 长按或者栓剂触发
  132. /// </summary>
  133. public void onLongClickDevice()
  134. {
  135. if (Title1.activeSelf || Title1ARTEMISPro.activeSelf || Title1GunPro.activeSelf || Title2.activeSelf)
  136. {
  137. AutoResetView.onInfraredGuiderAutoResetView();
  138. }
  139. }
  140. /// <summary>
  141. /// 根据enum操作ui
  142. /// </summary>
  143. /// <param name="tipStep"></param>
  144. public void SetTipState(TipStep tipStep = TipStep.None) {
  145. mTipStep = tipStep;
  146. switch (tipStep)
  147. {
  148. case TipStep.None://全部隐藏
  149. AllTipFalse();
  150. break;
  151. case TipStep.CrossHairTip:
  152. AllTipFalse();
  153. if (BluetoothAim.ins.isMainConnectToHOUYIPRO())
  154. {
  155. TitleCrossHair.SetActive(true);
  156. TitleCrossHair.GetComponent<TextAutoLanguage2>().SetTextKey("TopTip_CrossHair");
  157. }
  158. else if (BluetoothAim.ins.isMainConnectToARTEMISPRO() || BluetoothAim.ins.isMainConnectToGunType().gunType == AimDeviceType.RifleM416)
  159. {
  160. TitleCrossHair2.SetActive(true);
  161. TitleCrossHair2.GetComponent<TextAutoLanguage2>().SetTextKey("TopTip_CrossHairPro");
  162. } else if (BluetoothAim.ins.isMainConnectToGun())
  163. { //这里包括RifleM416,但是目前m416走的是 ARTEMISPRO
  164. TitleCrossHairGun.SetActive(true);
  165. //再次进来时候设置
  166. TitleCrossHairGun.GetComponent<TextAutoLanguage2>().SetTextKey("TopTip_CrossHairGunPro");
  167. }
  168. pageSprite.sprite = pageSprites[0];
  169. break;
  170. case TipStep.CalibrationOffset:
  171. AllTipFalse();
  172. //按照连接的类型来区分
  173. if (BluetoothAim.ins.isMainConnectToHOUYIPRO())
  174. {
  175. Title1.SetActive(true);
  176. setShowTime(Title1);
  177. }
  178. else if (BluetoothAim.ins.isMainConnectToARTEMISPRO() || BluetoothAim.ins.isMainConnectToGunType().gunType == AimDeviceType.RifleM416)
  179. {
  180. Title1ARTEMISPro.SetActive(true);
  181. setShowTime(Title1ARTEMISPro);
  182. }
  183. else if (BluetoothAim.ins.isMainConnectToGun())
  184. {
  185. Title1GunPro.SetActive(true);
  186. //setShowTime(Title1GunPro);
  187. }
  188. pageSprite.sprite = pageSprites[2];
  189. break;
  190. case TipStep.Finish:
  191. AllTipFalse();
  192. Title2.SetActive(true);
  193. pageSprite.sprite = pageSprites[3];
  194. break;
  195. }
  196. }
  197. /**
  198. * 根据不同的设备设置时间
  199. */
  200. void setShowTime(GameObject obj) {
  201. float time = GlobalData.MyDeviceMode == DeviceMode.Gun ? CommonConfig.calibrationTimeGun : CommonConfig.calibrationTimeArchery;
  202. TextAutoLanguage2 language2 = obj.GetComponent<TextAutoLanguage2>();
  203. language2.textFormatArgs = new object[] { Mathf.CeilToInt(time) };
  204. language2.ApplyToText();
  205. }
  206. void AllTipFalse() {
  207. TitleCrossHair.SetActive(false);
  208. TitleCrossHair2.SetActive(false);
  209. TitleCrossHairGun.SetActive(false);
  210. Title1.SetActive(false);
  211. Title2.SetActive(false);
  212. Title1ARTEMISPro.SetActive(false);
  213. Title1GunPro.SetActive(false);
  214. }
  215. /// <summary>
  216. /// 异常问题处理时候的文字提示步骤页面
  217. /// </summary>
  218. public void OnStep3TextTip()
  219. {
  220. if (Step1.activeSelf && !bRemove)
  221. {
  222. bRemove = true;
  223. StartCoroutine(delaySet());
  224. }
  225. Step1.SetActive(false);
  226. Step2.SetActive(false);
  227. Step3.SetActive(true);
  228. SetTipState(TipStep.CrossHairTip);
  229. }
  230. /// <summary>
  231. /// 检测四个角跳转到准心开关界面
  232. /// </summary>
  233. public void OnStep2ShootTest()
  234. {
  235. if (Step1.activeSelf && !bRemove)
  236. {
  237. bRemove = true;
  238. bRemovedAlready = false;
  239. cameraSensitivityBtn.interactable = false;
  240. StartCoroutine(delaySet());
  241. }
  242. Step1.SetActive(false);
  243. Step2.SetActive(true);
  244. Step3.SetActive(false);
  245. SetTipState(TipStep.CrossHairTip);
  246. }
  247. /// <summary>
  248. /// 返回到首次检测四个角部分
  249. /// </summary>
  250. public void OnStep1Collision() {
  251. if (bRemove && bRemovedAlready) {
  252. //回到页面1时候,添加上去
  253. //SimulateMouseController.ins?.AddOpenLocker(this);
  254. if (SB_EventSystem.ins && !SB_EventSystem.ins.simulateMouseIsAwaked)
  255. {
  256. SB_EventSystem.ins.AwakenSimulateMouse();
  257. }
  258. bRemove = false;
  259. bRemovedAlready = false;
  260. Step1.SetActive(true);
  261. Step2.SetActive(false);
  262. Step3.SetActive(false);
  263. SetTipState(TipStep.None);
  264. }
  265. }
  266. public Button cameraSensitivityBtn;
  267. bool bRemovedAlready = false;
  268. IEnumerator delaySet() {
  269. yield return new WaitForEndOfFrame(); //WaitForSeconds(0.5f);
  270. bRemovedAlready = true;
  271. cameraSensitivityBtn.interactable = true;
  272. if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked)
  273. {
  274. SB_EventSystem.ins.AwakenSimulateMouse();
  275. }
  276. }
  277. public void SetCollisionEvent() {
  278. if (collisionCount < 3)
  279. {
  280. collisionCount++;
  281. }
  282. else {
  283. //这里直接判断一次跳转回Home页面
  284. if (PlayerPrefs.HasKey(BluetoothAim.ins.GetInfraredGuiderKey()) && PlayerPrefs.GetInt(BluetoothAim.ins.GetInfraredGuiderKey(), 0) == 1)
  285. {
  286. //如果是红外教程成功执行过一次
  287. GameMgr.bNavBack = false;
  288. //直接回到主页
  289. UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single);
  290. }
  291. else {
  292. //进入下一步
  293. OnStep2ShootTest();
  294. }
  295. }
  296. }
  297. void OnEnable()
  298. {
  299. //SimulateMouseController.ins?.AddOpenLocker(this);
  300. if (SB_EventSystem.ins && !SB_EventSystem.ins.simulateMouseIsAwaked)
  301. {
  302. SB_EventSystem.ins.AwakenSimulateMouse();
  303. }
  304. }
  305. //void OnDisable()
  306. //{
  307. //}
  308. #if UNITY_EDITOR
  309. private void Update()
  310. {
  311. //跳过引导
  312. if (Input.GetKeyDown(KeyCode.Alpha5))
  313. {
  314. onClickDevice();
  315. }
  316. if (Input.GetKeyDown(KeyCode.Alpha6))
  317. {
  318. onLongClickDevice();
  319. }
  320. }
  321. #endif
  322. }