| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- /*
- 按下自动校准键出现倒计时3秒,同时伴有文字提示用户“三秒后即将开始校准,
- 请扶稳弓箭。”倒计时3秒后出现一个进度条也是三秒,用户在3秒内自己尽量扶稳弓即可,
- 进度条完成后,取一个平均值作为校准值。
- */
- public class AutoResetView : MonoBehaviour
- {
- public static AutoResetView ins;
- public static Action onInstantiate;
- public static void DoIdentity() {
- if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("Game")) {
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- } else if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("DuckHunter")) {
- GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- } else {
- SmartBowSDK.SmartBowHelper.GetInstance().ResetAim();
- }
- }
-
- void Awake() {
- if (ins) {
- Destroy(gameObject);
- return;
- }
- ins = this;
- }
- void Start() {
- if (SceneManager.GetActiveScene().name == "Game") {
- (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
- }
- SetText();
- // ChallengeTargetForResetView.Show();
- onInstantiate?.Invoke();
- }
- public Action action_OnDestroy;
- void OnDestroy() {
- if (ins == this) ins = null;
- action_OnDestroy?.Invoke();
- }
- float prepareTime = 3;
- int showedPrepareTime;
- void Update() {
- prepareTime -= Time.deltaTime;
- if (prepareTime <= 0) {
- try {
- SmartBowSDK.SmartBowHelper.GetInstance().ResetAim();
- Destroy(gameObject);
- }
- catch (System.Exception) {}
- Destroy(gameObject);
- } else {
- int curTime = Mathf.CeilToInt(prepareTime);
- if (showedPrepareTime != curTime) {
- showedPrepareTime = curTime;
- SetText();
- }
- }
- }
- void SetText()
- {
- transform.Find("FrameTip").GetComponentInChildren<Text>().text =
- string.Format(
- "请参考图中姿势,立即瞄准靶心,\n<size=40><color=#FFA500>{0}</color></size>秒后完成视角归位。",
- Mathf.CeilToInt(prepareTime));
- }
- }
|