| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- 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;
- [SerializeField] Material myOutlightMaterial;
- 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<Image>();
- //crossHairImage.material = onInitOpen ? outlight : null;
- if (onInitOpen)
- {
- crossHairImage.material = Instantiate(myOutlightMaterial); // 防止共享材质修改
- crossHairImage.material.SetTexture("_MainTex", crossHairImage.mainTexture); // 确保传入
- }
- else
- {
- crossHairImage.material = new Material(Shader.Find("UI/Default"));
- }
- //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;
- crossHairImage.material = Instantiate(myOutlightMaterial); // 防止共享材质修改
- crossHairImage.material.SetTexture("_MainTex", crossHairImage.mainTexture); // 确保传入
- }
- else
- {
- crossHairImage.material = new Material(Shader.Find("UI/Default"));
- }
- });
- //校准
- CalibrationOffsetBtn.onClick.AddListener(delegate ()
- {
- AudioMgr.ins.PlayBtn();
- GetComponent<SmartBowManager>().ResetAim();
- //ResetAim();
- });
- }
- else
- {
- ResetAimBtn.onClick.AddListener(ResetAim);
- ResetAimBtn.gameObject.AddComponent<LongPressMonitor>().onLongPress += ResetAimLongPress;
- }
- }
- else
- {
- ResetAimBtn.gameObject.SetActive(false);
- }
- //GetComponent<SmartBowManager>().OnConnectionLost += OnSmartBowConnectionLost;
- _startGameBtn.onClick.AddListener(StartGame);
- GetComponent<GamingManager>().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);
- }
- /// <summary>
- /// 根据GetOnlyShow 设置 outlight
- /// </summary>
- public void SetCrosshairOutLight()
- {
- //关闭9轴按钮
- ResetAimBtn.gameObject.SetActive(false);
- if (!CommonConfig.StandaloneModeOrPlatformB)
- {
- CalibrationOffsetBtn.gameObject.SetActive(true);
- if (GlobalData.MyDeviceMode == DeviceMode.Gun || BluetoothAim.ins && BluetoothAim.ins.isMainConnectToInfraredDevice())
- {
- //显示准心控制
- CrossHairBtn.gameObject.SetActive(true);
- Image crossHairImage = CrossHairBtn.transform.Find("Image").GetComponent<Image>();
- bool onlyShow = JCFruitMaster.ins.GetOnlyShow();
- if (onlyShow)
- {
- //crossHairImage.material = outlight;
- crossHairImage.material = Instantiate(myOutlightMaterial); // 防止共享材质修改
- crossHairImage.material.SetTexture("_MainTex", crossHairImage.mainTexture); // 确保传入
- }
- else
- {
- crossHairImage.material = new Material(Shader.Find("UI/Default"));
- }
- }
- }
- }
- // 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<GamingManager>().GetAudioManager().InstantiateTemprorarySound(SoundCategory.FruitSmash, Vector3.zero, 2f);
- }
- }
- else if (TimeGameOverAnimPlayed < StainEmergeTimes[2])
- {
- if (stain_1.activeSelf == false)
- {
- stain_1.SetActive(true);
- GetComponent<GamingManager>().GetAudioManager().InstantiateTemprorarySound(SoundCategory.FruitSmash, Vector3.zero, 2f);
- }
- }
- else if (TimeGameOverAnimPlayed < GameOverPanelEmergeTime)
- {
- if (stain_2.activeSelf == false)
- {
- stain_2.SetActive(true);
- GetComponent<GamingManager>().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<GamingManager>().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<GamingManager>().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<LongPressMonitor>().isLongPress) return;
- GetComponent<SmartBowManager>().ResetAim();
- }
- private void ResetAimLongPress()
- {
- if (SB_EventSystem.ins) SB_EventSystem.ins.AwakenSimulateMouse();
- }
- }
|