using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; namespace HyperspaceGame { public class UIManager : MonoBehaviour { public static UIManager _ins; /// /// ��¼һ���ܷ� /// public static int mHyperspaceScore { get; set; } = 0; [SerializeField] Button _btnQuit; [SerializeField] Button _btnReload; [SerializeField] Button _btnCrosshair; [SerializeField] Button _btnCalibrationOffset; [SerializeField] Material outlight; //׼�IJ��� private bool open = false; private bool visiable = false; private bool onlyShow = true; private Image image = null; private void Awake() { if (_ins != null && _ins != this) { //Destroy(this.gameObject); // ����Ѿ�����ʵ���������ٵ�ǰ���� return; } _ins = this; //DontDestroyOnLoad(this.gameObject); // ��֤�����ڳ����л�ʱ�������� //����ʱ���ʼ��һ��״̬ if (ShootCheck.ins) ShootCheck.ins.bluetoothDeviceStatus = SmartBowSDK.BluetoothDeviceStatus.MagazineLoading; } private void OnDestroy() { if (_ins == this) { _ins = null; // ������ʱ�ͷŵ��� } GlobalEventCenter.ins.onSimulateMouseAwakeChanged -= UpdateHideShow; } // Start is called before the first frame update void Start() { //�ر�ԭ��׼�� SimulateMouseController.ins?.RemoveOpenLocker("NotGame"); image = GeneratingTarget.gm.shootingEvent.GetComponent(); //b�˵��� if (CommonConfig.StandaloneModeOrPlatformB) { _btnCrosshair.gameObject.SetActive(false); _btnCalibrationOffset.gameObject.SetActive(false); } else { //��ȡ����ֵ��һ���洢ֵ bool onInitOpen = InfraredDemo._ins ? InfraredDemo._ins.bInitCrosshairShow() : true; Image crossHairImage = _btnCrosshair.GetComponentInChildren(); crossHairImage.material = onInitOpen ? outlight : null; _btnCrosshair.onClick.AddListener(delegate () { AudioMgr.ins.PlayBtn(); bool onlyShow = !GetOnlyShow(); SetOnlyShow(onlyShow); //��¼׼��ֵ if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow); if (onlyShow) { crossHairImage.material = outlight; } else { crossHairImage.material = null; } }); //У׼ _btnCalibrationOffset.onClick.AddListener(delegate () { AudioMgr.ins.PlayBtn(); AutoResetView.DoIdentity(); }); } _btnQuit.onClick.AddListener(OnShutDown); _btnReload.onClick.AddListener(Reload); SetOpen(UserSettings.ins.openCrossHair); visiable = open; OnValueChanged(visiable); UpdateHideShow(SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked); GlobalEventCenter.ins.onSimulateMouseAwakeChanged += UpdateHideShow; //CrossHairOutBoundChecker1 outBoundChecker = Instantiate(Resources.Load("Prefabs/CrossHairOutBoundChecker1")).GetComponent(); //outBoundChecker.crossHair = transform as RectTransform; //��ȡ׼��ֵ if (InfraredDemo._ins) SetOnlyShow(InfraredDemo._ins.getCrosshairValue() == 1); } void UpdateHideShow(bool mouseAwaked) { //transform.Find("Image").GetComponent().enabled = !mouseAwaked; SetOnlyShow(!mouseAwaked); } public void ShowQuit() { _btnQuit.gameObject.SetActive(true); } void OnShutDown() { //SceneManager.LoadScene("Home",LoadSceneMode.Single); GeneratingTarget.gm.onUploadScore(); //������Ϸҳ�� GeneratingTarget.gm.userGameAnalyse1.showResultView(() => { SceneManager.LoadScene("Home", LoadSceneMode.Single); }); } public void Reload() { GeneratingTarget.gm.OnSeparation(); GeneratingTarget.gm.OnLoading(); } public bool GetArrowBtnState() { if (open) return true; return false; } // Update is called once per frame void Update() { if (AutoResetView.ins != null) { //����У׼ʱ��һ����ʾ׼�� SetVisiable(true); } else { if (open) SetVisiable(onlyShow); else SetVisiable(false); } } void SetVisiable(bool value) { if (this.visiable == value) return; this.visiable = value; OnValueChanged(this.visiable); } void OnValueChanged(bool isOn) { var color = image.color; if (isOn) { color.a = 1; image.color = color; //_togImge.sprite = _togSprites[0]; } else { color.a = 0; image.color = color; //_togImge.sprite = _togSprites[1]; } } public void SetOpen(bool open) { this.open = open; if (!this.open) { SetVisiable(false); } } public bool GetOpen() { return this.open; } public void SetOnlyShow(bool onlyShow) { this.onlyShow = onlyShow; } public bool GetOnlyShow() { return this.onlyShow; } } }