Skip to content
Snippets Groups Projects
WaitingForLocalMMT.cs 1.88 KiB
Newer Older
  • Learn to ignore specific revisions
  • using UnityEngine;
    
    MaZiFAU's avatar
    MaZiFAU committed
    using UnityEngine.SceneManagement;
    
    using static CommunicationEvents;
    
    
    public class WaitingForLocalMMT : MonoBehaviour
    {
    
        private void OnEnable()
        {
            StartCoroutine(ServerRoutine());
        }
    
        private void OnDisable()
        {
            StopCoroutine(ServerRoutine());
        }
    
        void PrepareGame()
        {
    
            //This condition should always be true if PrepareGame gets called, but it never hurts to make sure.
            if (CommunicationEvents.ServerRunning)
    
                CommunicationEvents.ServerAdress = "http://" + CommunicationEvents.ServerAddressLocal; //ServerAddress needs the "http://"
    
    Stefan Richter's avatar
    Stefan Richter committed
                //UnityEngine.Debug.Log("StartMainMenu");
                SceneManager.LoadScene("MainMenu");
    
                yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false);
    
                // The address of the localServer currently cannot change, so it is never empty/illegal
                // If this can happen in the future, this condition may not suffice
                if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.online)
    
                    CommunicationEvents.ServerRunning = true;
    
                    PrepareGame();
                }
    
                //Wait for 2 seconds
                yield return new WaitForSecondsRealtime(2f);
    
    
        public UnityWebRequest pingL()
        {
            //UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
            //using UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list");
    
            UnityWebRequest request = UnityWebRequest.Get("http://" + CommunicationEvents.ServerAddressLocal + "/fact/list");