AutoResetView.cs 1.9 KB

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