Custom NetworkManager that handles all facets of connecting and disconnecting to games
Inheritance: NetworkManager
コード例 #1
0
    public void Retry()
    {
        NetworkManager_Custom nw = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkManager_Custom>();

        nw.ServerChangeScene("Level" + (SceneManager.GetActiveScene().buildIndex));
        Time.timeScale = 1f;
    }
コード例 #2
0
    public void MainMenu()
    {
        GameObject networkManager = GameObject.FindGameObjectWithTag("NetworkManager");

        GameObject.Destroy(networkManager);
        NetworkManager_Custom.Shutdown();
        SceneManager.LoadScene(0);
    }
コード例 #3
0
    IEnumerator TryToConnectToPublicServer()
    {
        NetworkManager_Custom manager = this.GetComponent <NetworkManager_Custom>();

        manager.matchName = ""; // Making this string empty will be a joker for us to get all public matches
        manager.StartMatchMaker();

        //Try to find all public roomcodes and join the public one with the least amount of players
        float timer     = 0f;
        float intervals = 0.25f;

        manager.matchMaker.ListMatches(0, 20, manager.matchName, true, 0, 0, manager.OnMatchList);

        Debug.Log("Sent list request, about to wait now");
        while (timer < 5f && manager.matches == null)
        {
            timer += intervals;
            yield return(new WaitForSeconds(intervals));
        }

        if (manager.matches != null)
        {
            Debug.Log("Matches don't equal null");
            if (manager.matches.Count == 0)
            {
                Debug.Log("No matches fit description");
                StartPublicServer();
            }
            else
            {
                Debug.Log("Found a match matching the details! Going to join the first one.");
                int       smallestPlayerCount    = 999;
                string    smallestPlayerRoomcode = "";
                NetworkID smallestNetworkID      = NetworkID.Invalid;
                for (int i = 0; i < manager.matches.Count; i++)
                {
                    if (manager.matches[i].currentSize < smallestPlayerCount && manager.matches[i].currentSize < manager.matches[i].maxSize)
                    {
                        smallestPlayerCount    = manager.matches[i].currentSize;
                        smallestPlayerRoomcode = manager.matches[i].name;
                        smallestNetworkID      = manager.matches[i].networkId;
                    }
                }
                if (smallestPlayerCount == 999)
                {
                    StartPublicServer();
                }
                manager.matchName = smallestPlayerRoomcode;
                string password = "";
                manager.matchMaker.JoinMatch(smallestNetworkID, password, "", "", 0, 0, manager.OnMatchJoined);
            }
        }
        else
        {
            StartPublicServer();
        }
    }
コード例 #4
0
    public void nextLevel()
    {
        NetworkManager_Custom nw = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkManager_Custom>();

        nw.ServerChangeScene("Level" + (PlayerPrefs.GetInt("LevelReached")));
        Time.timeScale = 1f;
        if (player == null)
        {
            player = GameObject.FindGameObjectWithTag("Player");
        }
        player.GetComponent <PlayerController> ().paused = false;
    }
コード例 #5
0
    public void Retry()
    {
        NetworkManager_Custom nw = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkManager_Custom>();

        nw.ServerChangeScene("Level" + (SceneManager.GetActiveScene().buildIndex));
        Time.timeScale = 1f;
        if (player == null)
        {
            player = GameObject.FindGameObjectWithTag("Player");
        }
        player.GetComponent <PlayerController> ().paused = false;
        PauseMenu.GameIsPaused = false;
    }
コード例 #6
0
    void Start()
    {
        //NetworkManager_Custom取得
        manager_ = GetComponent<NetworkManager_Custom>();
        Debug.Log(manager_);

        //マッチメイクの準備
        Debug.Log("Start Match Maker");
        manager_.StartMatchMaker();
        manager_.matchName = matchName;
        manager_.matchSize = matchSize;
        match_ = manager_.matchMaker;
    }
コード例 #7
0
    public void ConnectPlayerToRoomcode(bool retryMultipleTimes = false)
    {
        NetworkManager_Custom manager = this.GetComponent <NetworkManager_Custom>();

        manager.StartMatchMaker();

        int retries = 0;

        if (retryMultipleTimes)
        {
            retries = 10;
        }
        StartCoroutine(ConnectToRoomWhenLoaded(manager, false, retries));
    }
コード例 #8
0
    void Start()
    {
        // assign starthost and joingame their onclicks
        // This is done programmically so we are able to assign a new networkmanager as onclick
        NetworkManager_Custom nw = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkManager_Custom>();

        NetworkManager.singleton.StartMatchMaker();
        Debug.Log(nw.ToString());
        if (startHost && joinGame)
        {
            //startHost.onClick.AddListener(delegate { nw.CreateInternetMatch(); });
            startHost.onClick.AddListener(delegate { nw.FindOrStartInternetMatch(); });
            //joinGame.onClick.AddListener(delegate { nw.FindInternetMatch(); });
        }
    }
コード例 #9
0
    public void StartPublicServer()
    {
        foreach (TextMeshProUGUI textObj in LoadingPanel.GetComponentsInChildren <TextMeshProUGUI>())
        {
            if (textObj.name == "EditableText")
            {
                textObj.text = "Creating public match...";
                break;
            }
        }
        Debug.Log("Starting public server since no public room is available");
        NetworkManager_Custom manager = this.GetComponent <NetworkManager_Custom>();

        manager.matchName = GenerateMatchName();
        manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", "", "", 0, 0, manager.OnMatchCreate);
    }
コード例 #10
0
    void Start()
    {
        if (custom_singleton == null)
        {
            custom_singleton = this;
        }
        else if (custom_singleton != this)
        {
            Destroy(gameObject);
        }

        if (NetworkManager.singleton.matchMaker == null)
        {
            NetworkManager.singleton.StartMatchMaker();
        }
    }
コード例 #11
0
    //When Level won, transition PlayerPrefs to next level...
    //Levels get unlock according. Level is automatically faded to new Level.
    public void WinLevel()
    {
        int currentLevel = SceneManager.GetActiveScene().buildIndex;

        PlayerPrefs.SetInt("LevelReached", currentLevel + 1);
        Debug.Log(PlayerPrefs.GetInt("LevelReached"));
        NetworkManager_Custom nw = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkManager_Custom>();

        if (currentLevel <= 3)
        {
            //nw.ServerChangeScene ("Level" + (currentLevel + 1));
            Time.timeScale = 0f;
        }
        else
        {
            SceneManager.LoadScene(0);
        }
    }
コード例 #12
0
        void Start()
        {
            hClntSock = RealTimeConnect.instance.GetSocket();

            SceneMoveComplete();

            #region LoadManagers

            cm          = GameObject.Find("ChatterManager").GetComponent <ChatterManager>();
            crClm       = GameObject.Find("CRClientListManager").GetComponent <CRClientListManager>();
            csm         = GameObject.Find("ClientStateManager").GetComponent <ClientStateManager>();
            nmc         = GameObject.Find("NetworkManager").GetComponent <NetworkManager_Custom>();
            mm          = GameObject.Find("MapManager").GetComponent <MapManager>();
            failMessage = GameObject.Find("Error").transform.GetChild(0).gameObject;
            leaveButton = GameObject.Find("Leave").GetComponent <Button>();
            leaveButton.onClick.AddListener(() => ClientLeaveRequest());
            #endregion
        }
コード例 #13
0
    //Function is called when a player tries to start a new private match
    public void ButtonStartServer(string roomCodeKnown = "")
    {
        NetworkManager_Custom manager = this.GetComponent <NetworkManager_Custom>();

        if (LoadingPanel == null)
        {
            LoadingPanel = FindInActiveObjectByName("EndLoadingPanel");
        }
        if (LoadingPanel != null)
        {
            LoadingPanel.SetActive(true);
        }
        manager.StartMatchMaker();
        if (roomCodeKnown != "")
        {
            manager.matchName = roomCodeKnown;
        }
        else
        {
            manager.matchName = GenerateMatchName();
        }
        Debug.Log("Manager match name - " + manager.matchName);
        StartCoroutine(startServerAfterStuff(manager, roomCodeKnown));
    }
コード例 #14
0
    /// <summary>
    /// Quit the game
    /// </summary>
    public void QuitGame()
    {
        //Application.Quit();

        NetworkManager_Custom network = (NetworkManager_Custom)FindObjectOfType(typeof(NetworkManager_Custom));

        if (network.isServer)
        {
            network.StopClient();
            network.StopHost();
            network.StopServer();
            Destroy(network.gameObject);
            NetworkManager_Custom.Shutdown();
        }
        else
        {
            network.StopClient();
            Destroy(network.gameObject);
            NetworkManager_Custom.Shutdown();
        }

        //SceneManager.LoadScene("PrincipalMain");
        Debug.Log("Quitting game...");
    }
コード例 #15
0
 //This is the Coroutine that effectively creates a new private server on player's machine
 IEnumerator startServerAfterStuff(NetworkManager_Custom manager, string roomCodeKnown = "")
 {
     Debug.Log("Start server after stuff is being called!");
     roomPassword = manager.matchName;
     manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, roomPassword, "", "", 0, 0, manager.OnMatchCreate);//Setting the room password as the room name, so random players won't be able to join
 }
コード例 #16
0
 void Start()
 {
     nw = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkManager_Custom>();
 }
コード例 #17
0
 public void testEnemy()
 {
     NetworkManager_Custom.StartSinglePlayer();
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 4);
     Time.timeScale = 1f;
 }
コード例 #18
0
    //This is the coroutine that searches for a specific room in the list of existing rooms
    //If it finds the room we're looking for, it will try to join it
    IEnumerator ConnectToRoomWhenLoaded(NetworkManager_Custom manager, bool hidePrivateMatches = true, int retryCounter = 0)
    {
        if (retryCounter > 0)
        {
            Debug.Log("Retrying! " + retryCounter + " tries left before final.");
        }
        else
        {
            Debug.Log("No more retries left");
        }
        float timer     = 0f;
        float intervals = 0.25f;

        manager.matchMaker.ListMatches(0, 20, manager.matchName, hidePrivateMatches, 0, 0, manager.OnMatchList);

        Debug.Log("Sent list request, about to wait now");
        while (timer < 5f && manager.matches == null)
        {
            timer += intervals;
            yield return(new WaitForSeconds(intervals));
        }
        Debug.Log("Got to end of waiting period");

        if (manager.matches != null)
        {
            Debug.Log("Matches don't equal null");
            if (manager.matches.Count == 0)
            {
                Debug.Log("No matches fit description");
                if (retryCounter > 0)
                {
                    Debug.Log("Going to retry now because there are no matches fitting desc");
                    StartCoroutine(ConnectToRoomWhenLoaded(manager, hidePrivateMatches, retryCounter - 1));
                }
                else
                {
                    Debug.Log("Done retrying - no match fitting desc.");
                    DoButton.transform.parent.GetComponent <Button>().interactable = true;
                    TimedOutConnecting("<b>Error</b> - Room not found.");
                }
            }
            else
            {
                Debug.Log("Found a match matching the details! Going to join the first one.");
                manager.matchName = manager.matches[0].name;

                manager.matchSize = (uint)manager.matches[0].maxSize;

                string password = "";
                if (!hidePrivateMatches)//If we're connecting to a private match, set the password as the room name.
                {
                    password = manager.matchName;
                }
                manager.matchMaker.JoinMatch(manager.matches[0].networkId, password, "", "", 0, 0, manager.OnMatchJoined);
            }
        }
        else
        {
            if (retryCounter > 0)
            {
                StartCoroutine(ConnectToRoomWhenLoaded(manager, hidePrivateMatches, retryCounter - 1));
            }
            else
            {
                DoButton.transform.parent.GetComponent <Button>().interactable = true;
                TimedOutConnecting("<b>Error</b> - Room not found.");
            }
        }
    }