| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- /*
- 按下自动校准键出现倒计时3秒,同时伴有文字提示用户“三秒后即将开始校准,
- 请扶稳弓箭。”倒计时3秒后出现一个进度条也是三秒,用户在3秒内自己尽量扶稳弓即可,
- 进度条完成后,取一个平均值作为校准值。
- */
- public class AutoResetView : MonoBehaviour
- {
- public static AutoResetView ins;
- public static Action onInstantiate;
- public int playerIndex;
- public static void DoIdentityFromPlayerIndex(int _playerIndex)
- {
- if (SceneManager.GetActiveScene().name.StartsWith("Game"))
- {
- GameObject resetView = Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView2"));
- resetView.GetComponent<AutoResetView>().playerIndex = _playerIndex;
- Canvas canvas = resetView.GetComponent<Canvas>();
- if (_playerIndex == 0)
- {
- //canvas.renderMode = RenderMode.WorldSpace;
- //canvas.worldCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
- // canvas.worldCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
- }
- else {
- // canvas.worldCamera = GameObject.Find("Second Camera").GetComponent<Camera>();
- //resetView.transform.localPosition = new Vector3(Screen.width * 0.5f, 0, 0);
- }
- }
- }
- public static void DoIdentity() {
- if (SceneManager.GetActiveScene().name.StartsWith("Game")) {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else if (SceneManager.GetActiveScene().name.StartsWith("DuckHunter")) {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else if (SceneManager.GetActiveScene().name.StartsWith("WildAttack"))
- {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else if (SceneManager.GetActiveScene().name.StartsWith("FruitMaster"))
- {
- Instantiate(Resources.Load<GameObject>("Prefabs/Views/AutoResetView"));
- }
- else {
- AimHandler.ins.DoIdentity();
- }
- }
- void Awake() {
- if (ins) {
- Destroy(gameObject);
- return;
- }
- ins = this;
- }
- void Start() {
- if (SceneManager.GetActiveScene().name == "Game") {
- (transform.Find("IconHumanShoot") as RectTransform).anchoredPosition = new Vector2(-193, -85);
- }
- GetGuideTip().textFormatArgs = new object[]{showedPrepareTime = Mathf.CeilToInt(prepareTime)};
- GetGuideTip().ApplyToText();
- ChallengeTargetForResetView.Show();
- onInstantiate?.Invoke();
- }
- public Action action_OnDestroy;
- void OnDestroy() {
- if (ins == this) ins = null;
- action_OnDestroy?.Invoke();
- }
- float prepareTime = 3;
- int showedPrepareTime;
- void Update() {
- prepareTime -= Time.deltaTime;
- if (prepareTime <= 0) {
- try {
- if (SceneManager.GetActiveScene().name.StartsWith("WildAttack")){
- //WildAttack.GameMananger.GetInstance().ResetAim();
- }
- else
- {
- AimHandler.ins.DoIdentity();
- }
- }
- catch (Exception) {}
- 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 = transform.Find("FrameTip").GetComponentInChildren<TextAutoLanguage2>();
- return _guideTip;
- }
- }
|