| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- /*
- 按下自动校准键出现倒计时3秒,同时伴有文字提示用户“三秒后即将开始校准,
- 请扶稳弓箭。”倒计时3秒后出现一个进度条也是三秒,用户在3秒内自己尽量扶稳弓即可,
- 进度条完成后,取一个平均值作为校准值。
- */
- public class AutoResetViewNew : MonoBehaviour
- {
- public Transform pos;
- public Transform iconHumanShoot;
- public Transform frameTip;
- public Transform leftPoint;
- public Transform rightPoint;
- void Awake() {
-
- }
- void Start() {
- //if (SceneManager.GetActiveScene().name == "Game") {
- // (iconHumanShoot as RectTransform).anchoredPosition = new Vector2(-193, -85);
- //}
- prepareTime = UserSettings.ins.calibrationTime;
- Debug.Log("弓箭重置时间:"+ prepareTime);
- GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
- GetGuideTip().ApplyToText();
- ChallengeTargetForResetView.Show();
- }
- //重新设置
- public void setTextKey(string value) {
- GetGuideTip().SetTextKey(value);
- }
- //public void setPosLeft() {
- // //Debug.Log(Screen.width + " == "+ Screen.height);
- // (pos as RectTransform).anchoredPosition = leftPoint.GetComponent<RectTransform>().anchoredPosition;
- //}
- //public void setPosRight()
- //{
- // (pos as RectTransform).anchoredPosition = rightPoint.GetComponent<RectTransform>().anchoredPosition;
- //}
- public void setPosLeft()
- {
- RectTransform rt = pos as RectTransform;
- RectTransform parent = rt.parent as RectTransform;
- float halfWidth = parent.rect.width / 4f; // 1280/4 = 320
- rt.anchorMin = new Vector2(0, 0.5f);
- rt.anchorMax = new Vector2(0, 0.5f);
- rt.pivot = new Vector2(0.5f, 0.5f);
- rt.anchoredPosition = new Vector2(halfWidth, 0);
- }
- public void setPosRight()
- {
- RectTransform rt = pos as RectTransform;
- RectTransform parent = rt.parent as RectTransform;
- float halfWidth = parent.rect.width / 4f; // 1280/4 = 320
- rt.anchorMin = new Vector2(1, 0.5f);
- rt.anchorMax = new Vector2(1, 0.5f);
- rt.pivot = new Vector2(0.5f, 0.5f);
- rt.anchoredPosition = new Vector2(-halfWidth, 0);
- }
- public Action action_OnDestroy;
- void OnDestroy() {
- }
- float prepareTime = 3;
- int showedPrepareTime;
- void Update() {
- prepareTime -= Time.unscaledDeltaTime;//Time.deltaTime;
- if (prepareTime <= 0) {
- action_OnDestroy?.Invoke();
- Destroy(gameObject);
- } else {
- int curTime = Mathf.CeilToInt(prepareTime);
- if (showedPrepareTime != curTime) {
- showedPrepareTime = curTime;
- TextAutoLanguage2 gt = GetGuideTip();
- gt.textFormatArgs[0] = Mathf.CeilToInt(prepareTime);
- gt.ApplyToText();
- }
- }
- }
- TextAutoLanguage2 _guideTip;
- TextAutoLanguage2 GetGuideTip() {
- if (_guideTip == null) _guideTip = frameTip.GetComponentInChildren<TextAutoLanguage2>();
- return _guideTip;
- }
- }
|