| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /* 检测器-检测游戏射击准心是否出屏幕边界 (打鸭子、塔防关卡、水果大人) */
- public class CrossHairOutBoundChecker1 : MonoBehaviour
- {
- [SerializeField] GameObject outTip;
- string[] tips = null;
- int tipIndex = -1;
- void Awake()
- {
- outTip.SetActive(false);
- }
- void Start() {
- tips = new string[]{
- TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_0"),
- TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_1"),
- TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_2"),
- TextAutoLanguage2.GetTextByKey("game_crosshair_outbound_3"),
- };
- if (BluetoothAim.ins && (BluetoothAim.ins.isMainConnectToInfraredDevice() || BluetoothAim.ins.isMainConnectToGun()))
- {
- //当使用HOUYI Pro和枪这种红外定位方案的连接时,需在游戏中,将“瞄准方向已超出视野范围,请将弓往左移动”这种提示语去掉
- gameObject.SetActive(false);
- }
- }
- void Update()
- {
- int newTipIndex = GetNetTipIndex();
- if (newTipIndex != tipIndex) {
- tipIndex = newTipIndex;
- if (tipIndex >= 0) {
- outTip.GetComponent<Text>().text = tips[tipIndex];
- }
- }
- if (newTipIndex >= 0) {
- if (!outTip.activeSelf) outTip.SetActive(true);
- } else {
- if (outTip.activeSelf) outTip.SetActive(false);
- }
- }
- [SerializeField] public RectTransform crossHair;
- public System.Func<int> FetchOutBoundIndex;
- int GetNetTipIndex()
- {
- if (crossHair)
- {
- if (crossHair.gameObject.activeInHierarchy)
- {
- Vector3 pos = crossHair.position;
- if (pos.x < 3)
- {
- return 0;
- }
- if (pos.x > Screen.width - 3)
- {
- return 1;
- }
- if (pos.y > Screen.height - 3)
- {
- return 2;
- }
- if (pos.y < 3)
- {
- return 3;
- }
- }
- }
- else if (FetchOutBoundIndex != null)
- {
- return FetchOutBoundIndex.Invoke();
- }
- return -1;
- }
- }
|