AutoResetView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 int playerIndex;
  17. public static void DoIdentityFromPlayerIndex(int _playerIndex)
  18. {
  19. if (SceneManager.GetActiveScene().name.StartsWith("Game"))
  20. {
  21. GameObject resetView = Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView2"));
  22. resetView.GetComponent<AutoResetView>().playerIndex = _playerIndex;
  23. Canvas canvas = resetView.GetComponent<Canvas>();
  24. if (_playerIndex == 0)
  25. {
  26. //canvas.renderMode = RenderMode.WorldSpace;
  27. //canvas.worldCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
  28. // canvas.worldCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
  29. }
  30. else {
  31. // canvas.worldCamera = GameObject.Find("Second Camera").GetComponent<Camera>();
  32. //resetView.transform.localPosition = new Vector3(Screen.width * 0.5f, 0, 0);
  33. }
  34. }
  35. }
  36. public static void DoIdentity() {
  37. if (SceneManager.GetActiveScene().name.StartsWith("Game")) {
  38. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  39. }
  40. else if (SceneManager.GetActiveScene().name.StartsWith("DuckHunter")) {
  41. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  42. }
  43. else if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
  44. {
  45. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  46. }
  47. else if (SceneManager.GetActiveScene().name.StartsWith("FruitMaster"))
  48. {
  49. Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
  50. }
  51. else {
  52. AimHandler.ins.DoIdentity();
  53. }
  54. }
  55. void Awake() {
  56. if (ins) {
  57. Destroy(gameObject);
  58. return;
  59. }
  60. ins = this;
  61. }
  62. void Start() {
  63. if (SceneManager.GetActiveScene().name == "Game") {
  64. (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
  65. }
  66. GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
  67. GetGuideTip().ApplyToText();
  68. ChallengeTargetForResetView.Show();
  69. onInstantiate?.Invoke();
  70. }
  71. public Action action_OnDestroy;
  72. void OnDestroy() {
  73. if (ins == this) ins = null;
  74. action_OnDestroy?.Invoke();
  75. }
  76. float prepareTime = 3;
  77. int showedPrepareTime;
  78. void Update() {
  79. prepareTime -= Time.deltaTime;
  80. if (prepareTime <= 0) {
  81. try {
  82. if (SceneManager.GetActiveScene().name.StartsWith("WildAttack")){
  83. //WildAttack.GameMananger.GetInstance().ResetAim();
  84. }
  85. else
  86. {
  87. AimHandler.ins.DoIdentity();
  88. }
  89. }
  90. catch (Exception) {}
  91. Destroy(gameObject);
  92. } else {
  93. int curTime = Mathf.CeilToInt(prepareTime);
  94. if (showedPrepareTime != curTime) {
  95. showedPrepareTime = curTime;
  96. TextAutoLanguage2 gt = GetGuideTip();
  97. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  98. gt.ApplyToText();
  99. }
  100. }
  101. }
  102. TextAutoLanguage2 _guideTip;
  103. TextAutoLanguage2 GetGuideTip() {
  104. if (_guideTip == null) _guideTip = transform.Find("FrameTip").GetComponentInChildren<TextAutoLanguage2>();
  105. return _guideTip;
  106. }
  107. }