AutoResetView.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. /*
  8. 按下自动校准键出现倒计时3秒,同时伴有文字提示用户“三秒后即将开始校准,
  9. 请扶稳弓箭。”倒计时3秒后出现一个进度条也是三秒,用户在3秒内自己尽量扶稳弓即可,
  10. 进度条完成后,取一个平均值作为校准值。
  11. */
  12. public class AutoResetView : MonoBehaviour
  13. {
  14. [SerializeField] TextAutoLanguage2 prepareTipText;
  15. public static AutoResetView ins;
  16. public static void DoIdentity() {
  17. if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("Game")) {
  18. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  19. } else {
  20. AimHandler.ins.DoIdentity();
  21. }
  22. }
  23. void Awake() {
  24. if (ins) {
  25. Destroy(gameObject);
  26. return;
  27. }
  28. ins = this;
  29. }
  30. void Start() {
  31. if (SceneManager.GetActiveScene().name == "GameChallenge") {
  32. transform.Find("IconHumanShoot").gameObject.SetActive(true);
  33. transform.Find("FrameTip").gameObject.SetActive(true);
  34. }
  35. prepareTipText.textFormatArgs = new object[]{Mathf.CeilToInt(prepareTime)};
  36. prepareTipText.ApplyToText();
  37. ChallengeTargetForResetView.Show();
  38. }
  39. public Action action_OnDestroy;
  40. void OnDestroy() {
  41. if (ins == this) ins = null;
  42. action_OnDestroy?.Invoke();
  43. }
  44. float prepareTime = 3;
  45. void Update() {
  46. prepareTime -= Time.deltaTime;
  47. if (prepareTime <= 0) {
  48. try {
  49. AimHandler.ins.DoIdentity();
  50. Destroy(gameObject);
  51. }
  52. catch (System.Exception) {}
  53. Destroy(gameObject);
  54. } else {
  55. prepareTipText.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  56. prepareTipText.ApplyToText();
  57. }
  58. }
  59. }