using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class OverallLogics : MonoBehaviour { [SerializeField] private Button _startGameBtn; [SerializeField] private GameObject GameOverPanel; [SerializeField] private GameObject Stains; [SerializeField] private TextMeshProUGUI Scores; [SerializeField] private Image Logo; [SerializeField] private Image MenuBackground; [SerializeField] private Button ShutdownBtn; [SerializeField] private Button ResetAimBtn; [SerializeField] private Button CrossHairBtn; [SerializeField] private Button CalibrationOffsetBtn; [SerializeField] Material outlight; private bool bPlayingGameOverAnim; private float TimeGameOverAnimPlayed = 0f; private readonly float[] StainEmergeTimes = new float[] { 0.2f, 0.5f, 1f }; private const float GameOverPanelEmergeTime = 1.5f; private const float GameOverFinishAnimTime = 2f; private void Awake() { Debug.Assert(_startGameBtn); Debug.Assert(GameOverPanel); Debug.Assert(Stains); Debug.Assert(Scores); Debug.Assert(Logo); Debug.Assert(MenuBackground); } // Start is called before the first frame update void Start() { // ShutdownBtn.onClick.AddListener(Shutdown); // 如果不是b端单机模式 if (!CommonConfig.StandaloneModeOrPlatformB) { if (GlobalData.MyDeviceMode == DeviceMode.Gun || BluetoothAim.ins && BluetoothAim.ins.isMainConnectToInfraredDevice()) { ResetAimBtn.gameObject.SetActive(false); //获取设置值和一个存储值 bool onInitOpen = InfraredDemo._ins ? InfraredDemo._ins.bInitCrosshairShow() : true; Debug.Log("onInitOpen:" + onInitOpen); Image crossHairImage = CrossHairBtn.transform.Find("Image").GetComponent(); crossHairImage.material = onInitOpen ? outlight : null; //StartGame 控制 AimingCross_img CrossHairBtn.onClick.AddListener(delegate () { bool onlyShow = !JCFruitMaster.ins.GetOnlyShow(); JCFruitMaster.ins.SetOnlyShow(onlyShow); //记录准心值 if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow); if (onlyShow) { crossHairImage.material = outlight; } else { crossHairImage.material = null; } }); //校准 CalibrationOffsetBtn.onClick.AddListener(delegate () { AudioMgr.ins.PlayBtn(); GetComponent().ResetAim(); //ResetAim(); }); } else { ResetAimBtn.onClick.AddListener(ResetAim); ResetAimBtn.gameObject.AddComponent().onLongPress += ResetAimLongPress; } } else { ResetAimBtn.gameObject.SetActive(false); } //GetComponent().OnConnectionLost += OnSmartBowConnectionLost; _startGameBtn.onClick.AddListener(StartGame); GetComponent().OnGameEnd += OnGameEnd; Screen.sleepTimeout = SleepTimeout.NeverSleep; _startGameBtn.gameObject.SetActive(true); Logo.gameObject.SetActive(true); GameOverPanel.SetActive(false); Stains.gameObject.SetActive(false); float screen_ratio = (float)Screen.width / (float)Screen.height; float background_ratio = 2300f / 1080f; float background_scale; if (screen_ratio > background_ratio) { background_scale = Screen.width / 2300f; } else { background_scale = Screen.height / 1080f; } MenuBackground.rectTransform.sizeDelta = new Vector2(background_scale * 2300f, background_scale * 1080f); } /// /// 根据GetOnlyShow 设置 outlight /// public void SetCrosshairOutLight() { if (AimHandler.ins&&AimHandler.ins.bRuning9Axis()) return; //关闭9轴按钮 ResetAimBtn.gameObject.SetActive(false); if (!CommonConfig.StandaloneModeOrPlatformB) { //显示准心控制 CrossHairBtn.gameObject.SetActive(true); CalibrationOffsetBtn.gameObject.SetActive(true); Image crossHairImage = CrossHairBtn.transform.Find("Image").GetComponent(); bool onlyShow = JCFruitMaster.ins.GetOnlyShow(); if (onlyShow) { crossHairImage.material = outlight; } else { crossHairImage.material = null; } } } // Update is called once per frame void Update() { if (bPlayingGameOverAnim) { if (TimeGameOverAnimPlayed >= GameOverFinishAnimTime) { GameOverPanel.transform.localPosition = new Vector3(0f, 0f, 0f); TimeGameOverAnimPlayed = 0f; bPlayingGameOverAnim = false; _startGameBtn.gameObject.SetActive(true); return; } TimeGameOverAnimPlayed += Time.deltaTime; if (TimeGameOverAnimPlayed < GameOverPanelEmergeTime) { GameObject stain_0 = Stains.transform.GetChild(0).gameObject; GameObject stain_1 = Stains.transform.GetChild(1).gameObject; GameObject stain_2 = Stains.transform.GetChild(2).gameObject; if (TimeGameOverAnimPlayed < StainEmergeTimes[0]) { // do nothing return; } else if (TimeGameOverAnimPlayed < StainEmergeTimes[1]) { if (stain_0.activeSelf == false) { stain_0.SetActive(true); GetComponent().GetAudioManager().InstantiateTemprorarySound(SoundCategory.FruitSmash, Vector3.zero, 2f); } } else if (TimeGameOverAnimPlayed < StainEmergeTimes[2]) { if (stain_1.activeSelf == false) { stain_1.SetActive(true); GetComponent().GetAudioManager().InstantiateTemprorarySound(SoundCategory.FruitSmash, Vector3.zero, 2f); } } else if (TimeGameOverAnimPlayed < GameOverPanelEmergeTime) { if (stain_2.activeSelf == false) { stain_2.SetActive(true); GetComponent().GetAudioManager().InstantiateTemprorarySound(SoundCategory.FruitSmash, Vector3.zero, 2f); } } } else { if (TimeGameOverAnimPlayed < GameOverFinishAnimTime) { float game_over_panel_y = Mathf.Lerp(1000f, 0f, (TimeGameOverAnimPlayed - GameOverPanelEmergeTime) / (GameOverFinishAnimTime - GameOverPanelEmergeTime)); GameOverPanel.transform.localPosition = new Vector3(0f, game_over_panel_y, 0f); } } } } public void StartGame() { GetComponent().StartGame(); _startGameBtn.gameObject.SetActive(false); Logo.gameObject.SetActive(false); MenuBackground.gameObject.SetActive(false); // Reset GameOver Effect Stains.gameObject.SetActive(false); GameOverPanel.SetActive(false); } private void OnGameEnd(EndGameReason reason, int scores) { Scores.text = "Scores " + scores; if (reason == EndGameReason.GameOver) { bPlayingGameOverAnim = true; Stains.gameObject.SetActive(true); Stains.transform.GetChild(0).gameObject.SetActive(false); Stains.transform.GetChild(1).gameObject.SetActive(false); Stains.transform.GetChild(2).gameObject.SetActive(false); GameOverPanel.SetActive(true); GameOverPanel.transform.localPosition = new Vector3(0f, 1000f, 0f); } else { GameOverPanel.SetActive(true); GameOverPanel.transform.localPosition = new Vector3(0f, 0f, 0f); _startGameBtn.gameObject.SetActive(true); Logo.gameObject.SetActive(false); Stains.gameObject.SetActive(false); } GameOverInterface.OnGameOver(GameMgr.gameType); } private void OnSmartBowConnectionLost() { gameObject.GetComponent().PauseGame(); } private void Shutdown() { // Implementation here Debug.Log("Shutdown"); UnityEngine.SceneManagement.SceneManager.LoadScene("Home", UnityEngine.SceneManagement.LoadSceneMode.Single); } private void ResetAim() { Debug.Log("Reset Aim"); if (ResetAimBtn.GetComponent().isLongPress) return; GetComponent().ResetAim(); } private void ResetAimLongPress() { if (SB_EventSystem.ins) SB_EventSystem.ins.AwakenSimulateMouse(); } }