| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using AppUI.Bluetooth;
- 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 (SmartBowDeviceHub.ins && (SmartBowDeviceHub.ins.IsMainConnectToInfraredDevice() || SmartBowDeviceHub.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;
- }
- }
|