AutoResetView.cs 2.9 KB

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