예제 #1
0
    public void OnDestroy()
    {
        if (playerIndex == 0)
        {
            local.Cancel();
        }
        if (networkManager.localPlayer == this)
        {
            local.Cancel();
            DebugGUI.ShowGUI = true;

            // Remove all the players for local player
            GameObject PContainer = GameObject.Find("PlayerContainer");
            if (PContainer != null && PContainer.transform.childCount > 1)
            {
                for (int i = 0; i < PContainer.transform.childCount; i++)
                {
                    Destroy(PContainer.transform.GetChild(i).gameObject);
                }
            }

            // Change Net State to Default
            GameListener.networkState = GameListener.NetworkState.Offline;

            // Remove Game Session
            Destroy(GameObject.Find("GameSession(Clone)"));

            // Reset Server and Client settings
            //Server.ResetServer = true;
            Client.ResetClient = true;
        }

        OnClientExitLobby();
        // If this is a client player on the server then OnClientExitLobby will not be called.
        // Call it here instead.

        //if (networkManager.IsHost() && networkManager.localPlayer != this)
        //{
        //    OnClientExitLobby();
        //}
    }
예제 #2
0
    public void Awake()
    {
        if (GameObject.Find("btnCancel"))
        {
            btnCancel = GameObject.Find("btnCancel").GetComponent <Button>();
            btnCancel.onClick.AddListener(() =>
            {
                local.Cancel();
                ShowGUI = true;
            });
            btnCancel.gameObject.SetActive(false);
        }

        if (GameObject.Find("btnHost") && GameObject.Find("btnJoin"))
        {
            btnHost = GameObject.Find("btnHost").GetComponent <Button>();
            btnHost.onClick.AddListener(() =>
            {
                local.StartHosting();
                ShowGUI = false;
            });

            btnJoin = GameObject.Find("btnJoin").GetComponent <Button>();
            btnJoin.onClick.AddListener(() =>
            {
                local.StartJoining();
                ShowGUI = false;
            });

            btnHost.gameObject.SetActive(false);
        }


        local          = FindObjectOfType(typeof(LocalMultiplayer)) as LocalMultiplayer;
        networkManager = GetComponent <LocalNetworkManager>();
    }