CrossHairOutBoundChecker1.cs 2.4 KB

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