AutoResetViewNew.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. //重新设置
  32. public void setTextKey(string value) {
  33. GetGuideTip().SetTextKey(value);
  34. }
  35. //public void setPosLeft() {
  36. // //Debug.Log(Screen.width + " == "+ Screen.height);
  37. // (pos as RectTransform).anchoredPosition = leftPoint.GetComponent<RectTransform>().anchoredPosition;
  38. //}
  39. //public void setPosRight()
  40. //{
  41. // (pos as RectTransform).anchoredPosition = rightPoint.GetComponent<RectTransform>().anchoredPosition;
  42. //}
  43. public void setPosLeft()
  44. {
  45. RectTransform rt = pos as RectTransform;
  46. RectTransform parent = rt.parent as RectTransform;
  47. float halfWidth = parent.rect.width / 4f; // 1280/4 = 320
  48. rt.anchorMin = new Vector2(0, 0.5f);
  49. rt.anchorMax = new Vector2(0, 0.5f);
  50. rt.pivot = new Vector2(0.5f, 0.5f);
  51. rt.anchoredPosition = new Vector2(halfWidth, 0);
  52. }
  53. public void setPosRight()
  54. {
  55. RectTransform rt = pos as RectTransform;
  56. RectTransform parent = rt.parent as RectTransform;
  57. float halfWidth = parent.rect.width / 4f; // 1280/4 = 320
  58. rt.anchorMin = new Vector2(1, 0.5f);
  59. rt.anchorMax = new Vector2(1, 0.5f);
  60. rt.pivot = new Vector2(0.5f, 0.5f);
  61. rt.anchoredPosition = new Vector2(-halfWidth, 0);
  62. }
  63. public Action action_OnDestroy;
  64. void OnDestroy() {
  65. }
  66. float prepareTime = 3;
  67. int showedPrepareTime;
  68. void Update() {
  69. prepareTime -= Time.unscaledDeltaTime;//Time.deltaTime;
  70. if (prepareTime <= 0) {
  71. action_OnDestroy?.Invoke();
  72. Destroy(gameObject);
  73. } else {
  74. int curTime = Mathf.CeilToInt(prepareTime);
  75. if (showedPrepareTime != curTime) {
  76. showedPrepareTime = curTime;
  77. TextAutoLanguage2 gt = GetGuideTip();
  78. gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
  79. gt.ApplyToText();
  80. }
  81. }
  82. }
  83. TextAutoLanguage2 _guideTip;
  84. TextAutoLanguage2 GetGuideTip() {
  85. if (_guideTip == null) _guideTip = frameTip.GetComponentInChildren<TextAutoLanguage2>();
  86. return _guideTip;
  87. }
  88. }