AutoResetView.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 (InfraredDemo.running) return;
  18. if (SceneManager.GetActiveScene().name.StartsWith("GameDouble"))
  19. {
  20. if (GameObject.Find("AutoResetViewNewLeft")) return;
  21. GameObject resetView = Instantiate(Resources.Load<GameObject>("AutoResetViewNew"));
  22. resetView.name = "AutoResetViewNewLeft";
  23. AutoResetViewNew autoResetViewNewScript = resetView.GetComponent<AutoResetViewNew>();
  24. autoResetViewNewScript.setPosLeft();
  25. autoResetViewNewScript.action_OnDestroy += () =>
  26. {
  27. //使用旧模式重置1p
  28. AimHandler.ins?.DoIdentity();
  29. };
  30. }
  31. else if (SceneManager.GetActiveScene().name.StartsWith("Game"))
  32. {
  33. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  34. }
  35. else if (SceneManager.GetActiveScene().name.StartsWith("DuckHunter"))
  36. {
  37. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  38. }
  39. else if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
  40. {
  41. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  42. }
  43. else if (SceneManager.GetActiveScene().name.StartsWith("FruitMaster"))
  44. {
  45. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  46. }
  47. else if (SceneManager.GetActiveScene().name.StartsWith("Hyperspace")) {
  48. //Hyperspace01 Hyperspace02 Hyperspace03
  49. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  50. }
  51. else
  52. {
  53. AimHandler.ins.DoIdentity();
  54. }
  55. }
  56. void Awake() {
  57. if (ins) {
  58. Destroy(gameObject);
  59. return;
  60. }
  61. ins = this;
  62. }
  63. void Start() {
  64. prepareTime = UserSettings.ins.calibrationTime;
  65. Debug.Log("弓箭重置时间:" + prepareTime);
  66. if (SceneManager.GetActiveScene().name == "Game") {
  67. (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
  68. }
  69. GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
  70. GetGuideTip().ApplyToText();
  71. ChallengeTargetForResetView.Show();
  72. onInstantiate?.Invoke();
  73. }
  74. public Action action_OnDestroy;
  75. void OnDestroy() {
  76. if (ins == this) ins = null;
  77. action_OnDestroy?.Invoke();
  78. }
  79. float prepareTime = 3;
  80. int showedPrepareTime;
  81. bool bEnd = false;
  82. void Update() {
  83. prepareTime -= Time.deltaTime;
  84. if (prepareTime <= 0) {
  85. //防止多次调用
  86. if (bEnd) return;
  87. bEnd = true;
  88. try {
  89. if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
  90. {
  91. WildAttack.GameMananger.GetInstance().ResetAim();
  92. }
  93. else
  94. {
  95. if (AimHandler.ins.bRuning9Axis())
  96. {
  97. AimHandler.ins.DoIdentity();
  98. }
  99. else
  100. {
  101. //红外设备校准偏离点
  102. InfraredDemo._ins?.OnClick_SetAdjustPointsOffset();
  103. }
  104. }
  105. }
  106. catch (Exception) {}
  107. //先隐藏子物体
  108. foreach (Transform child in transform)
  109. {
  110. child.gameObject.SetActive(false);
  111. }
  112. Destroy(gameObject,2.0f);
  113. } else {
  114. int curTime = Mathf.CeilToInt(prepareTime);
  115. if (showedPrepareTime != curTime) {
  116. showedPrepareTime = curTime;
  117. TextAutoLanguage2 gt = GetGuideTip();
  118. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  119. gt.ApplyToText();
  120. }
  121. }
  122. }
  123. TextAutoLanguage2 _guideTip;
  124. TextAutoLanguage2 GetGuideTip() {
  125. if (_guideTip == null) {
  126. if (AimHandler.ins.bRuning9Axis())
  127. {
  128. Transform text = transform.Find("FrameTip/Text");
  129. text.gameObject.SetActive(true);
  130. _guideTip = text.GetComponentInChildren<TextAutoLanguage2>();
  131. }
  132. else {
  133. Transform textInfrared = transform.Find("FrameTip/Text-Infrared");
  134. textInfrared.gameObject.SetActive(true);
  135. _guideTip = textInfrared.GetComponentInChildren<TextAutoLanguage2>();
  136. }
  137. }
  138. return _guideTip;
  139. }
  140. }