AutoResetView.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked) return;
  19. if (SceneManager.GetActiveScene().name.StartsWith("GameDouble"))
  20. {
  21. if (GameObject.Find("AutoResetViewNewLeft")) return;
  22. GameObject resetView = Instantiate(Resources.Load<GameObject>("AutoResetViewNew"));
  23. resetView.name = "AutoResetViewNewLeft";
  24. AutoResetViewNew autoResetViewNewScript = resetView.GetComponent<AutoResetViewNew>();
  25. autoResetViewNewScript.setPosLeft();
  26. autoResetViewNewScript.action_OnDestroy += () =>
  27. {
  28. //使用旧模式重置1p
  29. //AimHandler.ins?.DoIdentity();
  30. };
  31. }
  32. else if (SceneManager.GetActiveScene().name.StartsWith("Game"))
  33. {
  34. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  35. }
  36. else if (SceneManager.GetActiveScene().name.StartsWith("DuckHunter"))
  37. {
  38. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  39. }
  40. else if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
  41. {
  42. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  43. }
  44. else if (SceneManager.GetActiveScene().name.StartsWith("FruitMaster"))
  45. {
  46. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  47. }
  48. else if (SceneManager.GetActiveScene().name.StartsWith("Hyperspace")) {
  49. //Hyperspace01 Hyperspace02 Hyperspace03
  50. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  51. }
  52. else
  53. {
  54. Debug.LogWarning("没有重置函数!");
  55. }
  56. }
  57. /// <summary>
  58. /// 引导页面弹出校准
  59. /// </summary>
  60. public static void onInfraredGuiderAutoResetView() {
  61. CreateResetViewPath("Prefabs/Views/AutoResetView");
  62. }
  63. /// <summary>
  64. /// 带背景的校准
  65. /// </summary>
  66. public static void onInfraredGuiderAutoResetViewOrBg()
  67. {
  68. CreateResetViewPath("Prefabs/Views/AutoResetViewOrBg");
  69. }
  70. static void CreateResetViewPath(string path) {
  71. AutoResetView autoResetView = Instantiate(Resources.Load<GameObject>(path)).GetComponent<AutoResetView>();
  72. autoResetView.bInfraredGuider = true;
  73. autoResetView.infraredGuiderTime = GlobalData.MyDeviceMode == DeviceMode.Gun ? CommonConfig.calibrationTimeGun : CommonConfig.calibrationTimeArchery;
  74. }
  75. /// <summary>
  76. /// 是否是引导
  77. /// </summary>
  78. public bool bInfraredGuider = false;
  79. public float infraredGuiderTime = 10;
  80. void Awake() {
  81. if (ins) {
  82. Destroy(gameObject);
  83. return;
  84. }
  85. ins = this;
  86. }
  87. void Start() {
  88. //进入引导游戏场景时候,设置时间
  89. if (bInfraredGuider)
  90. {
  91. prepareTime = infraredGuiderTime;
  92. }
  93. else {
  94. prepareTime = UserSettings.ins.calibrationTime;
  95. }
  96. Debug.Log("弓箭重置时间:" + prepareTime);
  97. if (SceneManager.GetActiveScene().name == "Game") {
  98. (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
  99. }
  100. GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
  101. GetGuideTip().ApplyToText();
  102. ChallengeTargetForResetView.Show();
  103. onInstantiate?.Invoke();
  104. }
  105. public Action action_OnDestroy;
  106. void OnDestroy() {
  107. if (ins == this) ins = null;
  108. action_OnDestroy?.Invoke();
  109. }
  110. float prepareTime = 3;
  111. int showedPrepareTime;
  112. bool bEnd = false;
  113. void Update() {
  114. // 使用 unscaledDeltaTime 代替 deltaTime
  115. prepareTime -= Time.unscaledDeltaTime;//Time.deltaTime;
  116. if (prepareTime <= 0) {
  117. //防止多次调用
  118. if (bEnd) return;
  119. bEnd = true;
  120. try {
  121. if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
  122. {
  123. WildAttack.GameMananger.GetInstance().ResetAim();
  124. }
  125. else
  126. {
  127. //红外设备校准偏离点
  128. InfraredDemo._ins?.OnClick_SetAdjustPointsOffset();
  129. }
  130. }
  131. catch (Exception) {}
  132. //先隐藏子物体
  133. foreach (Transform child in transform)
  134. {
  135. child.gameObject.SetActive(false);
  136. }
  137. Destroy(gameObject,2.0f);
  138. } else {
  139. int curTime = Mathf.CeilToInt(prepareTime);
  140. if (showedPrepareTime != curTime) {
  141. showedPrepareTime = curTime;
  142. TextAutoLanguage2 gt = GetGuideTip();
  143. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  144. gt.ApplyToText();
  145. }
  146. }
  147. }
  148. TextAutoLanguage2 _guideTip;
  149. TextAutoLanguage2 GetGuideTip() {
  150. if (_guideTip == null) {
  151. if (GlobalData.MyDeviceMode == DeviceMode.Gun)
  152. {
  153. Transform textInfrared = transform.Find("FrameTip/Text-Infrared-Gun");
  154. textInfrared.gameObject.SetActive(true);
  155. _guideTip = textInfrared.GetComponentInChildren<TextAutoLanguage2>();
  156. }
  157. else
  158. {
  159. Transform textInfrared = transform.Find("FrameTip/Text-Infrared");
  160. textInfrared.gameObject.SetActive(true);
  161. _guideTip = textInfrared.GetComponentInChildren<TextAutoLanguage2>();
  162. }
  163. }
  164. return _guideTip;
  165. }
  166. }