-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoadingManager.cs
More file actions
62 lines (46 loc) · 1.55 KB
/
LoadingManager.cs
File metadata and controls
62 lines (46 loc) · 1.55 KB
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
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using Photon.Pun;
using System.Collections;
using TMPro;
public class LoadingManager : MonoBehaviourPunCallbacks
{
public Slider loadingBar;
public TMP_Text statusText;
private string homeSceneName = "HomeScene";
void Start()
{
StartCoroutine(LoadHomeScene());
}
IEnumerator LoadHomeScene()
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(homeSceneName);
asyncLoad.allowSceneActivation = false;
if (!PhotonNetwork.IsConnected)
{
PhotonNetwork.ConnectUsingSettings();
}
while (!asyncLoad.isDone)
{
float progress = Mathf.Clamp01(asyncLoad.progress / 0.9f);
loadingBar.value = progress;
statusText.text = $"Loading... {Mathf.RoundToInt(progress * 100)}%";
if (progress >= 1f && PhotonNetwork.IsConnectedAndReady)
{
statusText.text = "Connected! Entering the world...";
yield return new WaitForSeconds(1f);
asyncLoad.allowSceneActivation = true;
}
yield return null;
}
}
public override void OnConnectedToMaster()
{
}
public override void OnDisconnected(Photon.Realtime.DisconnectCause cause)
{
statusText.text = "Connection failed. Retrying...";
PhotonNetwork.ConnectUsingSettings();
}
}