| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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 (SceneManager.GetActiveScene().name.StartsWith("Game")) {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else if (SceneManager.GetActiveScene().name.StartsWith("DuckHunter")) {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
- {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else if (SceneManager.GetActiveScene().name.StartsWith("FruitMaster"))
- {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else {
- AimHandler.ins.DoIdentity();
- }
- }
-
- 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);
- }
- GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
- GetGuideTip().ApplyToText();
- 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 {
- AimHandler.ins.DoIdentity();
- }
- catch (Exception) {}
- Destroy(gameObject);
- } else {
- int curTime = Mathf.CeilToInt(prepareTime);
- if (showedPrepareTime != curTime) {
- showedPrepareTime = curTime;
- TextAutoLanguage2 gt = GetGuideTip();
- gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
- gt.ApplyToText();
- }
- }
- }
- TextAutoLanguage2 _guideTip;
- TextAutoLanguage2 GetGuideTip() {
- if (_guideTip == null) _guideTip = transform.Find("FrameTip").GetComponentInChildren<TextAutoLanguage2>();
- return _guideTip;
- }
- }
|