| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /*
- 按下自动校准键出现倒计时3秒,同时伴有文字提示用户“三秒后即将开始校准,
- 请扶稳弓箭。”倒计时3秒后出现一个进度条也是三秒,用户在3秒内自己尽量扶稳弓即可,
- 进度条完成后,取一个平均值作为校准值。
- */
- public class AutoResetView : MonoBehaviour
- {
- [SerializeField] Text prepareTipText;
- [SerializeField] GameObject rootBox;
- [SerializeField] Text tipText;
- [SerializeField] Transform progressBar;
- [SerializeField] Text progressText;
- static AutoResetView ins;
- public static void DoIdentity() {
- if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("Game")) {
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- } else {
- AimHandler.ins.DoIdentity();
- }
- }
-
- void Awake() {
- if (ins) {
- Destroy(gameObject);
- return;
- }
- ins = this;
- }
- void Start() {
- rootBox.gameObject.SetActive(false);
- prepareTipText.gameObject.SetActive(true);
- prepareTipText.text = "";
- }
- void OnDestroy() {
- if (ins == this) ins = null;
- }
- float prepareTime = 3;
- // float doTime = 0, doTimeMax = 3;
- // float showTipTime = 1;
- int step = 0;
- void Update() {
- if (step == 0) {
- prepareTime -= Time.deltaTime;
- if (prepareTime <= 0) {
- try {
- AimHandler.ins.DoIdentity();
- Destroy(gameObject);
- }
- catch (System.Exception) {}
- Destroy(gameObject);
- } else {
- prepareTipText.text = $"{Mathf.CeilToInt(prepareTime)}秒后即将开始校准,请扶稳弓箭!";
- }
- }
- // if (step == 0) {
- // prepareTime -= Time.deltaTime;
- // if (prepareTime <= 0) {
- // step = 1;
- // prepareTipText.gameObject.SetActive(false);
- // rootBox.gameObject.SetActive(true);
- // tipText.text = "正在自动校准,请扶稳弓箭!";
- // SetProgress(0);
- // }
- // prepareTipText.text = $"{Mathf.CeilToInt(prepareTime)}秒后即将开始校准,请扶稳弓箭!";
- // } else if (step == 1) {
- // doTime += Time.deltaTime;
- // if (doTime > doTimeMax) {
- // doTime = doTimeMax;
- // step = 2;
- // }
- // SetProgress(doTime / doTimeMax);
- // } else if (step == 2) {
- // step = 3;
- // try {
- // AimHandler.ins.DoIdentity();
- // tipText.text = "校准完成";
- // }
- // catch (System.Exception) {
- // tipText.text = "校准失败";
- // }
- // } else if (step == 3) {
- // showTipTime -= Time.deltaTime;
- // if (showTipTime <= 0) {
- // Destroy(gameObject);
- // }
- // }
- }
- //最高1
- void SetProgress(float percent) {
- Vector3 sv = progressBar.localScale;
- sv.x = percent;
- progressBar.localScale = sv;
- progressText.text = Mathf.FloorToInt(percent * 100) + "%";
- }
- }
- /*
- * 自动视角归位
- * 每次开启app第一次进入游戏,在一个范围静止3秒钟直接调用归位函数
- */
- // public class AutoResetView : MonoBehaviour
- // {
- // [SerializeField] GameObject rootBox;
- // [SerializeField] Text tipText;
- // [SerializeField] Transform progressBar;
- // [SerializeField] Text progressText;
- // public static AutoResetView ins;
-
- // //是否已经对焦过(全局记录)
- // static bool doneReset = false;
- // bool finished = false;
- // public static void Create() {
- // GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- // }
-
- // void Awake() {
- // ins = this;
- // if (doneReset) Destroy(gameObject);
- // }
- // void Start() {
- // tipText.text = "正在自动对焦,请瞄准正前方并静止直至对焦完成!";
- // SetProgress(0);
- // }
- // void OnDestroy() {
- // if (ins == this) ins = null;
- // }
- // void Update() {
- // //如果游戏处于停止状态,则隐藏校准界面
- // if (GameMgr.ins.gamePause) {
- // if (rootBox.activeSelf) rootBox.SetActive(false);
- // } else {
- // if (!rootBox.activeSelf) rootBox.SetActive(true);
- // }
- // }
- // Quaternion cachedRotation;
- // int cachedRotationCount = 0;
- // float totalTime = 0;
- // const float needCheckTime = 3f;
- // public void CheckRotation(Quaternion quat) {
- // if (GameMgr.ins.gamePause) return;
- // if (doneReset) return;
- // if (finished) return;
- // if (cachedRotationCount == 0) {
- // cachedRotation = quat;
- // cachedRotationCount++;
- // totalTime = 0;
- // return;
- // }
- // float deltaAngle = Quaternion.Angle(quat, cachedRotation) / Time.deltaTime;
- // if (deltaAngle > 300) {
- // cachedRotationCount = 0; //重置
- // return;
- // }
- // totalTime += Time.deltaTime;
- // SetProgress(Mathf.Clamp(totalTime / needCheckTime, 0, 0.99f));
- // if (totalTime >= needCheckTime) {
- // try
- // {
- // AimHandler.ins.DoIdentity();
- // if (BluetoothAim.ins.status != BluetoothStatusEnum.ConnectSuccess) {
- // throw new Exception("还没有连接模块");
- // }
- // doneReset = true;
- // tipText.text = "对焦完成";
- // SetProgress(1);
- // }
- // catch (System.Exception)
- // {
- // tipText.text = "自动对焦失败,请检查是否已连接模块!";
- // }
- // finished = true;
- // DoTweenUtil.CallDelay(1f, () => {
- // Destroy(gameObject);
- // });
- // }
- // }
- // //最高1
- // void SetProgress(float percent) {
- // Vector3 sv = progressBar.localScale;
- // sv.x = percent;
- // progressBar.localScale = sv;
- // progressText.text = Mathf.FloorToInt(percent * 100) + "%";
- // }
- // }
|