AutoResetView.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. public 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 == "Game") {
  31. (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
  32. }
  33. GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
  34. GetGuideTip().ApplyToText();
  35. ChallengeTargetForResetView.Show();
  36. }
  37. public Action action_OnDestroy;
  38. void OnDestroy() {
  39. if (ins == this) ins = null;
  40. action_OnDestroy?.Invoke();
  41. }
  42. float prepareTime = 3;
  43. int showedPrepareTime;
  44. void Update() {
  45. prepareTime -= Time.deltaTime;
  46. if (prepareTime <= 0) {
  47. try {
  48. AimHandler.ins.DoIdentity();
  49. Destroy(gameObject);
  50. }
  51. catch (System.Exception) {}
  52. Destroy(gameObject);
  53. } else {
  54. int curTime = Mathf.CeilToInt(prepareTime);
  55. if (showedPrepareTime != curTime) {
  56. showedPrepareTime = curTime;
  57. TextAutoLanguage2 gt = GetGuideTip();
  58. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  59. gt.ApplyToText();
  60. }
  61. }
  62. }
  63. TextAutoLanguage2 _guideTip;
  64. TextAutoLanguage2 GetGuideTip() {
  65. if (_guideTip == null) _guideTip = transform.Find("FrameTip").GetComponentInChildren<TextAutoLanguage2>();
  66. return _guideTip;
  67. }
  68. }