AutoResetView.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 Action onInstantiate;
  16. public static void DoIdentity() {
  17. if (SceneManager.GetActiveScene().name.StartsWith("Game")) {
  18. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  19. }
  20. else if (SceneManager.GetActiveScene().name.StartsWith("DuckHunter")) {
  21. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  22. }
  23. else if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
  24. {
  25. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  26. }
  27. else if (SceneManager.GetActiveScene().name.StartsWith("FruitMaster"))
  28. {
  29. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  30. }
  31. else {
  32. AimHandler.ins.DoIdentity();
  33. }
  34. }
  35. void Awake() {
  36. if (ins) {
  37. Destroy(gameObject);
  38. return;
  39. }
  40. ins = this;
  41. }
  42. void Start() {
  43. if (SceneManager.GetActiveScene().name == "Game") {
  44. (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
  45. }
  46. GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
  47. GetGuideTip().ApplyToText();
  48. ChallengeTargetForResetView.Show();
  49. onInstantiate?.Invoke();
  50. }
  51. public Action action_OnDestroy;
  52. void OnDestroy() {
  53. if (ins == this) ins = null;
  54. action_OnDestroy?.Invoke();
  55. }
  56. float prepareTime = 3;
  57. int showedPrepareTime;
  58. void Update() {
  59. prepareTime -= Time.deltaTime;
  60. if (prepareTime <= 0) {
  61. try {
  62. AimHandler.ins.DoIdentity();
  63. }
  64. catch (Exception) {}
  65. Destroy(gameObject);
  66. } else {
  67. int curTime = Mathf.CeilToInt(prepareTime);
  68. if (showedPrepareTime != curTime) {
  69. showedPrepareTime = curTime;
  70. TextAutoLanguage2 gt = GetGuideTip();
  71. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  72. gt.ApplyToText();
  73. }
  74. }
  75. }
  76. TextAutoLanguage2 _guideTip;
  77. TextAutoLanguage2 GetGuideTip() {
  78. if (_guideTip == null) _guideTip = transform.Find("FrameTip").GetComponentInChildren<TextAutoLanguage2>();
  79. return _guideTip;
  80. }
  81. }