InfraredGuider.cs 11 KB

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