using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class LoadingScreen : MonoBehaviour { public static LoadingScreen instance; CanvasGroup canvasGroup; public Slider loadingProgress; public TMPro.TMP_Text loadingProgressTxt; private static bool loading; public static bool Loading => loading; void Awake(){ instance =this; } void Start() { DontDestroyOnLoad(gameObject); canvasGroup = GetComponent(); } public void LoadLevel(string levelName){ if(loading){return;}loading=true; StartCoroutine(loadlLevel(levelName)); } IEnumerator loadlLevel(string levelName){ AudioManager.instnace.SetMusic(-1); TutorialManager.instance=null; loading=true; canvasGroup.alpha=0; canvasGroup.blocksRaycasts=true; SetProgress(0); while(canvasGroup.alpha< 1f){ canvasGroup.alpha+=0.03f; yield return new WaitForFixedUpdate(); } while(RegionManager.selectedServer == null && levelName.Contains("Minigame")){ loadingProgressTxt.text = "Preparing"; yield return new WaitForSeconds(0.5f); } AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(levelName); // asyncOperation.allowSceneActivation = false; while (!asyncOperation.isDone) { //Output the current progress // m_Text.text = "Loading progress: " + (asyncOperation.progress * 100) + "%"; // Check if the load has finished SetProgress(asyncOperation.progress); yield return null; } yield return new WaitForSeconds(0.2f); canvasGroup.blocksRaycasts=false; while(canvasGroup.alpha> 0){ canvasGroup.alpha-=0.03f; yield return new WaitForFixedUpdate(); } loading=false; } void SetProgress(float value){ loadingProgress.value = value; loadingProgressTxt.text = (int)(value*100) + "%"; } public void DeleteRankedRooms(int port){ StartCoroutine(CloseRoomClient(port)); } IEnumerator CloseRoomClient(int port){ Debug.Log("Clearing rooms for port " + port); WWWForm form = new WWWForm(); form.AddField("port", port); WWW req = new WWW(DBmanager.phpRoot+"clear_ranked_room.php",form); yield return req; Debug.Log(req.text); } }