AutoResetView.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("Game")) {
  18. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  19. } else if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("DuckHunter")) {
  20. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  21. } else {
  22. SmartBowSDK.SmartBowHelper.GetInstance().ResetAim();
  23. }
  24. }
  25. void Awake() {
  26. if (ins) {
  27. Destroy(gameObject);
  28. return;
  29. }
  30. ins = this;
  31. }
  32. void Start() {
  33. if (SceneManager.GetActiveScene().name == "Game") {
  34. (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
  35. }
  36. SetText();
  37. // ChallengeTargetForResetView.Show();
  38. onInstantiate?.Invoke();
  39. }
  40. public Action action_OnDestroy;
  41. void OnDestroy() {
  42. if (ins == this) ins = null;
  43. action_OnDestroy?.Invoke();
  44. }
  45. float prepareTime = 3;
  46. int showedPrepareTime;
  47. void Update() {
  48. prepareTime -= Time.deltaTime;
  49. if (prepareTime <= 0) {
  50. try {
  51. SmartBowSDK.SmartBowHelper.GetInstance().ResetAim();
  52. Destroy(gameObject);
  53. }
  54. catch (System.Exception) {}
  55. Destroy(gameObject);
  56. } else {
  57. int curTime = Mathf.CeilToInt(prepareTime);
  58. if (showedPrepareTime != curTime) {
  59. showedPrepareTime = curTime;
  60. SetText();
  61. }
  62. }
  63. }
  64. void SetText()
  65. {
  66. transform.Find("FrameTip").GetComponentInChildren<Text>().text =
  67. string.Format(
  68. "请参考图中姿势,立即瞄准靶心,\n<size=40><color=#FFA500>{0}</color></size>秒后完成视角归位。",
  69. Mathf.CeilToInt(prepareTime));
  70. }
  71. }