summaryrefslogtreecommitdiff
path: root/GameCode/LoadingScreen.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/LoadingScreen.cs
+ init
Diffstat (limited to 'GameCode/LoadingScreen.cs')
-rw-r--r--GameCode/LoadingScreen.cs81
1 files changed, 81 insertions, 0 deletions
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<DisplayMatchPlayerNames>().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<TextMeshProUGUI>().text = "";
+ }
+ gameMode.SetActive(value: true);
+ }
+
+ public void StopLoading()
+ {
+ StopAllCoroutines();
+ searchingSystem.Stop();
+ StartCoroutine(IDoLoading());
+ }
+}