From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/LoadingScreen.cs | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 GameCode/LoadingScreen.cs (limited to 'GameCode/LoadingScreen.cs') diff --git a/GameCode/LoadingScreen.cs b/GameCode/LoadingScreen.cs new file mode 100644 index 0000000..72d65fd --- /dev/null +++ b/GameCode/LoadingScreen.cs @@ -0,0 +1,81 @@ +using System.Collections; +using SoundImplementation; +using TMPro; +using UnityEngine; + +public class LoadingScreen : MonoBehaviour +{ + private const string SEARCHING_TEXT = "SEARCHING"; + + private const string SEARCHING_PRIVATE_TEXT = "WAITING FOR FRIEND"; + + [SerializeField] + private TextMeshProUGUI m_SearchingText; + + public GameObject gameMode; + + public GeneralParticleSystem searchingSystem; + + public GeneralParticleSystem matchFoundSystem; + + public GeneralParticleSystem[] playerNamesSystem; + + public float matchFoundTime = 0.5f; + + public float playerNameTime = 2f; + + public static LoadingScreen instance; + + private void Awake() + { + instance = this; + } + + public void StartLoading(bool privateGame = false) + { + StopAllCoroutines(); + matchFoundSystem.Stop(); + for (int i = 0; i < playerNamesSystem.Length; i++) + { + playerNamesSystem[i].Stop(); + } + searchingSystem.Play(); + m_SearchingText.text = GetSearchingString(privateGame); + } + + private string GetSearchingString(bool privGame) + { + if (privGame) + { + return "WAITING FOR FRIEND"; + } + return "SEARCHING"; + } + + private IEnumerator IDoLoading() + { + SoundPlayerStatic.Instance.PlayMatchFound(); + matchFoundSystem.Play(); + yield return new WaitForSeconds(matchFoundTime); + matchFoundSystem.Stop(); + GetComponentInChildren().ShowNames(); + for (int i = 0; i < playerNamesSystem.Length; i++) + { + playerNamesSystem[i].Play(); + } + yield return new WaitForSeconds(playerNameTime); + for (int j = 0; j < playerNamesSystem.Length; j++) + { + playerNamesSystem[j].Stop(); + playerNamesSystem[j].GetComponentInParent().text = ""; + } + gameMode.SetActive(value: true); + } + + public void StopLoading() + { + StopAllCoroutines(); + searchingSystem.Stop(); + StartCoroutine(IDoLoading()); + } +} -- cgit v1.1-26-g67d0