summaryrefslogtreecommitdiff
path: root/GameCode/LoadingScreen.cs
blob: 72d65fda22debb1c03311c503d6cbce8ce905a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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());
	}
}