CrossHairOutBoundChecker1.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using AppUI.Bluetooth;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /* 检测器-检测游戏射击准心是否出屏幕边界 (打鸭子、塔防关卡、水果大人) */
  7. public class CrossHairOutBoundChecker1 : MonoBehaviour
  8. {
  9. [SerializeField] GameObject outTip;
  10. string[] tips = null;
  11. int tipIndex = -1;
  12. void Awake()
  13. {
  14. outTip.SetActive(false);
  15. }
  16. void Start() {
  17. tips = new string[]{
  18. TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_0"),
  19. TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_1"),
  20. TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_2"),
  21. TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_3"),
  22. };
  23. if (SmartBowDeviceHub.ins && (SmartBowDeviceHub.ins.IsMainConnectToInfraredDevice() || SmartBowDeviceHub.ins.IsMainConnectToGun()))
  24. {
  25. //当使用HOUYI Pro和枪这种红外定位方案的连接时,需在游戏中,将“瞄准方向已超出视野范围,请将弓往左移动”这种提示语去掉
  26. gameObject.SetActive(false);
  27. }
  28. }
  29. void Update()
  30. {
  31. int newTipIndex = GetNetTipIndex();
  32. if (newTipIndex != tipIndex) {
  33. tipIndex = newTipIndex;
  34. if (tipIndex >= 0) {
  35. outTip.GetComponent<Text>().text = tips[tipIndex];
  36. }
  37. }
  38. if (newTipIndex >= 0) {
  39. if (!outTip.activeSelf) outTip.SetActive(true);
  40. } else {
  41. if (outTip.activeSelf) outTip.SetActive(false);
  42. }
  43. }
  44. [SerializeField] public RectTransform crossHair;
  45. public System.Func<int> FetchOutBoundIndex;
  46. int GetNetTipIndex()
  47. {
  48. if (crossHair)
  49. {
  50. if (crossHair.gameObject.activeInHierarchy)
  51. {
  52. Vector3 pos = crossHair.position;
  53. if (pos.x < 3)
  54. {
  55. return 0;
  56. }
  57. if (pos.x > Screen.width - 3)
  58. {
  59. return 1;
  60. }
  61. if (pos.y > Screen.height - 3)
  62. {
  63. return 2;
  64. }
  65. if (pos.y < 3)
  66. {
  67. return 3;
  68. }
  69. }
  70. }
  71. else if (FetchOutBoundIndex != null)
  72. {
  73. return FetchOutBoundIndex.Invoke();
  74. }
  75. return -1;
  76. }
  77. }