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 static void DoIdentity() { //if (InfraredDemo.running) return; if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked) return; if (SceneManager.GetActiveScene().name.StartsWith("GameDouble")) { if (GameObject.Find("AutoResetViewNewLeft")) return; GameObject resetView = Instantiate(Resources.Load("AutoResetViewNew")); resetView.name = "AutoResetViewNewLeft"; AutoResetViewNew autoResetViewNewScript = resetView.GetComponent(); autoResetViewNewScript.setPosLeft(); autoResetViewNewScript.action_OnDestroy += () => { //使用旧模式重置1p AimHandler.ins?.DoIdentity(); }; } else if (SceneManager.GetActiveScene().name.StartsWith("Game")) { Instantiate(Resources.Load("Prefabs/Views/AutoResetView")); } else if (SceneManager.GetActiveScene().name.StartsWith("DuckHunter")) { Instantiate(Resources.Load("Prefabs/Views/AutoResetView")); } else if (SceneManager.GetActiveScene().name.StartsWith("WildAttack")) { Instantiate(Resources.Load("Prefabs/Views/AutoResetView")); } else if (SceneManager.GetActiveScene().name.StartsWith("FruitMaster")) { Instantiate(Resources.Load("Prefabs/Views/AutoResetView")); } else if (SceneManager.GetActiveScene().name.StartsWith("Hyperspace")) { //Hyperspace01 Hyperspace02 Hyperspace03 Instantiate(Resources.Load("Prefabs/Views/AutoResetView")); } else { AimHandler.ins.DoIdentity(); } } /// /// 引导页面弹出校准 /// public static void onInfraredGuiderAutoResetView() { CreateResetViewPath("Prefabs/Views/AutoResetView"); } /// /// 带背景的校准 /// public static void onInfraredGuiderAutoResetViewOrBg() { CreateResetViewPath("Prefabs/Views/AutoResetViewOrBg"); } static void CreateResetViewPath(string path) { AutoResetView autoResetView = Instantiate(Resources.Load(path)).GetComponent(); autoResetView.bInfraredGuider = true; autoResetView.infraredGuiderTime = GlobalData.MyDeviceMode == DeviceMode.Gun ? CommonConfig.calibrationTimeGun : CommonConfig.calibrationTimeArchery; } /// /// 是否是引导 /// public bool bInfraredGuider = false; public float infraredGuiderTime = 10; void Awake() { if (ins) { Destroy(gameObject); return; } ins = this; } void Start() { //进入引导游戏场景时候,设置时间 if (bInfraredGuider) { prepareTime = infraredGuiderTime; } else { prepareTime = UserSettings.ins.calibrationTime; } Debug.Log("弓箭重置时间:" + prepareTime); 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; bool bEnd = false; void Update() { // 使用 unscaledDeltaTime 代替 deltaTime prepareTime -= Time.unscaledDeltaTime;//Time.deltaTime; if (prepareTime <= 0) { //防止多次调用 if (bEnd) return; bEnd = true; try { if (SceneManager.GetActiveScene().name.StartsWith("WildAttack")) { WildAttack.GameMananger.GetInstance().ResetAim(); } else { if (AimHandler.ins.bRuning9Axis()) { AimHandler.ins.DoIdentity(); } else { //红外设备校准偏离点 InfraredDemo._ins?.OnClick_SetAdjustPointsOffset(); } } } catch (Exception) {} //先隐藏子物体 foreach (Transform child in transform) { child.gameObject.SetActive(false); } Destroy(gameObject,2.0f); } 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) { if (AimHandler.ins.bRuning9Axis()) { Transform text = transform.Find("FrameTip/Text"); text.gameObject.SetActive(true); _guideTip = text.GetComponentInChildren(); } else { if (GlobalData.MyDeviceMode == DeviceMode.Gun) { Transform textInfrared = transform.Find("FrameTip/Text-Infrared-Gun"); textInfrared.gameObject.SetActive(true); _guideTip = textInfrared.GetComponentInChildren(); } else { Transform textInfrared = transform.Find("FrameTip/Text-Infrared"); textInfrared.gameObject.SetActive(true); _guideTip = textInfrared.GetComponentInChildren(); } } } return _guideTip; } }