AutoResetViewNew.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 AutoResetViewNew : MonoBehaviour
  13. {
  14. public Transform pos;
  15. public Transform iconHumanShoot;
  16. public Transform frameTip;
  17. public Transform leftPoint;
  18. public Transform rightPoint;
  19. void Awake() {
  20. }
  21. void Start() {
  22. //if (SceneManager.GetActiveScene().name == "Game") {
  23. // (iconHumanShoot as RectTransform).anchoredPosition = new Vector2(-193, -85);
  24. //}
  25. GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
  26. GetGuideTip().ApplyToText();
  27. ChallengeTargetForResetView.Show();
  28. }
  29. public void setPosLeft() {
  30. //Debug.Log(Screen.width + " == "+ Screen.height);
  31. (pos as RectTransform).anchoredPosition = leftPoint.GetComponent<RectTransform>().anchoredPosition;
  32. }
  33. public void setPosRight()
  34. {
  35. (pos as RectTransform).anchoredPosition = rightPoint.GetComponent<RectTransform>().anchoredPosition;
  36. }
  37. public Action action_OnDestroy;
  38. void OnDestroy() {
  39. }
  40. float prepareTime = 3;
  41. int showedPrepareTime;
  42. void Update() {
  43. prepareTime -= Time.deltaTime;
  44. if (prepareTime <= 0) {
  45. action_OnDestroy?.Invoke();
  46. Destroy(gameObject);
  47. } else {
  48. int curTime = Mathf.CeilToInt(prepareTime);
  49. if (showedPrepareTime != curTime) {
  50. showedPrepareTime = curTime;
  51. TextAutoLanguage2 gt = GetGuideTip();
  52. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  53. gt.ApplyToText();
  54. }
  55. }
  56. }
  57. TextAutoLanguage2 _guideTip;
  58. TextAutoLanguage2 GetGuideTip() {
  59. if (_guideTip == null) _guideTip = frameTip.GetComponentInChildren<TextAutoLanguage2>();
  60. return _guideTip;
  61. }
  62. }