AutoResetViewNew.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. prepareTime = UserSettings.ins.calibrationTime;
  26. Debug.Log("弓箭重置时间:"+ prepareTime);
  27. GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
  28. GetGuideTip().ApplyToText();
  29. ChallengeTargetForResetView.Show();
  30. }
  31. public void setPosLeft() {
  32. //Debug.Log(Screen.width + " == "+ Screen.height);
  33. (pos as RectTransform).anchoredPosition = leftPoint.GetComponent<RectTransform>().anchoredPosition;
  34. }
  35. public void setPosRight()
  36. {
  37. (pos as RectTransform).anchoredPosition = rightPoint.GetComponent<RectTransform>().anchoredPosition;
  38. }
  39. public Action action_OnDestroy;
  40. void OnDestroy() {
  41. }
  42. float prepareTime = 3;
  43. int showedPrepareTime;
  44. void Update() {
  45. prepareTime -= Time.unscaledDeltaTime;//Time.deltaTime;
  46. if (prepareTime <= 0) {
  47. action_OnDestroy?.Invoke();
  48. Destroy(gameObject);
  49. } else {
  50. int curTime = Mathf.CeilToInt(prepareTime);
  51. if (showedPrepareTime != curTime) {
  52. showedPrepareTime = curTime;
  53. TextAutoLanguage2 gt = GetGuideTip();
  54. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  55. gt.ApplyToText();
  56. }
  57. }
  58. }
  59. TextAutoLanguage2 _guideTip;
  60. TextAutoLanguage2 GetGuideTip() {
  61. if (_guideTip == null) _guideTip = frameTip.GetComponentInChildren<TextAutoLanguage2>();
  62. return _guideTip;
  63. }
  64. }