Пример #1
0
    void ConnectedWindow(int windowID)
    {
        if (Network.isServer)
        {
            GUILayout.Label("You are host.");

            GUILayout.Space(5);

            int numPlayers = Network.connections.Length + 1;
            GUILayout.Label("Players Connected: " + numPlayers);

            GUILayout.Space(5);

            if (GUILayout.Button("Close Server", GUILayout.Height(60)))
            {
                CloseServer();
                guiMode = GUIDrawMode.MainMenu;
            }
        }
        else
        {
            //GUILayout.Label ("Connected to server at " + Network.connections [0].ipAddress + ":" + Network.connections [0].port.ToString ());
            GUILayout.Label("Blah " + Network.connections.Length);

            GUILayout.Space(5);

            if (GUILayout.Button("Leave Server", GUILayout.Height(60)))
            {
                QuitServer();
                guiMode = GUIDrawMode.MainMenu;
            }
        }
    }
    void ConnectedWindow(int windowID)
    {
        if (Network.isServer) {
            GUILayout.Label ("You are host.");

            GUILayout.Space (5);

            int numPlayers = Network.connections.Length + 1;
            GUILayout.Label ("Players Connected: " + numPlayers);

            GUILayout.Space (5);

            if (GUILayout.Button ("Close Server", GUILayout.Height (60))) {
                CloseServer ();
                guiMode = GUIDrawMode.MainMenu;
            }
        } else {
            //GUILayout.Label ("Connected to server at " + Network.connections [0].ipAddress + ":" + Network.connections [0].port.ToString ());
            GUILayout.Label("Blah " + Network.connections.Length);

            GUILayout.Space (5);

            if (GUILayout.Button ("Leave Server", GUILayout.Height (60))) {
                QuitServer ();
                guiMode = GUIDrawMode.MainMenu;
            }
        }
    }
    void ConnectionErrorWindow(int windowID)
    {
        GUILayout.Label ("Error: " + connectionErrorMsg);

        if (GUILayout.Button ("Back to Menu", GUILayout.Height (60))) {
            guiMode = GUIDrawMode.MainMenu;
        }
    }
Пример #4
0
    void ConnectionErrorWindow(int windowID)
    {
        GUILayout.Label("Error: " + connectionErrorMsg);

        if (GUILayout.Button("Back to Menu", GUILayout.Height(60)))
        {
            guiMode = GUIDrawMode.MainMenu;
        }
    }
Пример #5
0
    void OnFailedToConnect(NetworkConnectionError error)
    {
        Debug.Log("OnFailedToConnect " + error);

        connectionError    = error;
        connectionErrorMsg = error.ToString();
        guiMode            = GUIDrawMode.ConnectionError;

        connecting = false;
    }
Пример #6
0
    // Network messages

    void OnServerInitialized()
    {
        if (m_serverDedicated)
        {
            guiMode = GUIDrawMode.DedicatedServer;
        }
        else
        {
            guiMode = GUIDrawMode.Connected;
        }

        connecting = false;
    }
Пример #7
0
    void OnDisconnectedFromServer(NetworkDisconnection info)
    {
        Debug.Log("OnDisconnectedFromServer " + info);

        if (info == NetworkDisconnection.LostConnection)
        {
            connectionErrorMsg = "Lost connection with server";
            guiMode            = GUIDrawMode.ConnectionError;
        }
        else if (info == NetworkDisconnection.Disconnected)
        {
            connectionErrorMsg = "Server has closed connection";
            guiMode            = GUIDrawMode.ConnectionError;
        }
    }
Пример #8
0
    void DedicatedServerWindow(int windowID)
    {
        GUILayout.Label("Dedicated Server Controls");

        GUILayout.Space(5);

        GUILayout.Label("Players Connected: " + Network.connections.Length.ToString());

        GUILayout.Space(5);

        if (GUILayout.Button("Close Server", GUILayout.Height(60)))
        {
            CloseServer();
            guiMode = GUIDrawMode.MainMenu;
        }
    }
Пример #9
0
    void MainMenuWindow(int windowID)
    {
        if (connecting)
        {
            GUI.enabled = false;
        }

        guiMainMode = GUILayout.Toolbar(guiMainMode, guiMainCategories);

        GUILayout.Space(15);

        switch (guiMainMode)
        {
        case 0:
            GUILayout.Label("Enter your player name");
            m_playerName = GUILayout.TextField(m_playerName);

            if (Application.isWebPlayer == false && Application.isEditor == false)
            {
                GUILayout.Space(5);

                if (GUILayout.Button("Exit Game", GUILayout.Height(60)))
                {
                    Application.Quit();
                }
            }
            break;

        case 1:
            GUILayout.Label("Enter a name for your server");
            m_serverName = GUILayout.TextField(m_serverName);

            GUILayout.Space(5);

            GUILayout.Label("Server Port");
            m_serverPort = int.Parse(GUILayout.TextField(m_serverPort.ToString()));

            GUILayout.Space(5);

            GUILayout.Label("Max Players");
            m_serverPlayerLimit = int.Parse(GUILayout.TextField(m_serverPlayerLimit.ToString()));

            GUILayout.Space(5);

            GUILayout.Label("Put in a password for your server (optional)");
            m_serverPassword = GUILayout.TextField(m_serverPassword);

            GUILayout.Space(5);

            m_serverDedicated = GUILayout.Toggle(m_serverDedicated, "Dedicated Server?");

            GUILayout.Space(10);

            if (GUILayout.Button("Start my server", GUILayout.Height(25)))
            {
                connecting = true;

                connectionError = StartServer();

                switch (connectionError)
                {
                case NetworkConnectionError.NoError:
                    break;

                default:
                    connectionErrorMsg = connectionError.ToString();
                    guiMode            = GUIDrawMode.ConnectionError;
                    break;
                }
            }
            break;

        case 2:
            GUILayout.Label("Type in Server IP");
            m_joinServerIP = GUILayout.TextField(m_joinServerIP);

            GUILayout.Space(5);

            GUILayout.Label("Server Port");
            m_joinServerPort = int.Parse(GUILayout.TextField(m_joinServerPort.ToString()));

            GUILayout.Space(5);

            GUILayout.Label("Server Password");
            m_joinServerPassword = GUILayout.TextField(m_joinServerPassword);

            GUILayout.Space(10);

            if (GUILayout.Button("Connect", GUILayout.Height(25)))
            {
                connecting = true;

                connectionError = JoinServerByIP();

                Debug.Log(connectionError);

                switch (connectionError)
                {
                case NetworkConnectionError.NoError:
                    break;

                default:
                    connectionErrorMsg = connectionError.ToString();
                    guiMode            = GUIDrawMode.ConnectionError;
                    break;
                }
            }
            break;

        default:
            break;
        }

        if (connecting)
        {
            GUI.enabled = true;
        }
    }
Пример #10
0
 void OnConnectedToServer()
 {
     guiMode    = GUIDrawMode.Connected;
     connecting = false;
 }
    void MainMenuWindow(int windowID)
    {
        if (connecting) GUI.enabled = false;

        guiMainMode = GUILayout.Toolbar (guiMainMode, guiMainCategories);

        GUILayout.Space (15);

        switch (guiMainMode) {
        case 0:
            GUILayout.Label ("Enter your player name");
            m_playerName = GUILayout.TextField (m_playerName);

            if (Application.isWebPlayer == false && Application.isEditor == false) {
                GUILayout.Space (5);

                if (GUILayout.Button ("Exit Game", GUILayout.Height (60))) {
                    Application.Quit ();
                }
            }
            break;

        case 1:
            GUILayout.Label ("Enter a name for your server");
            m_serverName = GUILayout.TextField (m_serverName);

            GUILayout.Space (5);

            GUILayout.Label ("Server Port");
            m_serverPort = int.Parse (GUILayout.TextField (m_serverPort.ToString ()));

            GUILayout.Space (5);

            GUILayout.Label ("Max Players");
            m_serverPlayerLimit = int.Parse (GUILayout.TextField (m_serverPlayerLimit.ToString ()));

            GUILayout.Space (5);

            GUILayout.Label ("Put in a password for your server (optional)");
            m_serverPassword = GUILayout.TextField (m_serverPassword);

            GUILayout.Space (5);

            m_serverDedicated = GUILayout.Toggle (m_serverDedicated, "Dedicated Server?");

            GUILayout.Space (10);

            if (GUILayout.Button ("Start my server", GUILayout.Height (25))) {
                connecting = true;

                connectionError = StartServer ();

                switch (connectionError) {
                case NetworkConnectionError.NoError:
                    break;

                default:
                    connectionErrorMsg = connectionError.ToString();
                    guiMode = GUIDrawMode.ConnectionError;
                    break;
                }
            }
            break;

        case 2:
            GUILayout.Label ("Type in Server IP");
            m_joinServerIP = GUILayout.TextField (m_joinServerIP);

            GUILayout.Space (5);

            GUILayout.Label ("Server Port");
            m_joinServerPort = int.Parse (GUILayout.TextField (m_joinServerPort.ToString ()));

            GUILayout.Space (5);

            GUILayout.Label("Server Password");
            m_joinServerPassword = GUILayout.TextField (m_joinServerPassword);

            GUILayout.Space (10);

            if (GUILayout.Button ("Connect", GUILayout.Height (25))) {
                connecting = true;

                connectionError = JoinServerByIP ();

                Debug.Log(connectionError);

                switch (connectionError) {
                case NetworkConnectionError.NoError:
                    break;

                default:
                    connectionErrorMsg = connectionError.ToString();
                    guiMode = GUIDrawMode.ConnectionError;
                    break;
                }
            }
            break;

        default:
            break;
        }

        if (connecting) GUI.enabled = true;
    }
    void DedicatedServerWindow(int windowID)
    {
        GUILayout.Label ("Dedicated Server Controls");

        GUILayout.Space (5);

        GUILayout.Label ("Players Connected: " + Network.connections.Length.ToString ());

        GUILayout.Space (5);

        if (GUILayout.Button ("Close Server", GUILayout.Height (60))) {
            CloseServer ();
            guiMode = GUIDrawMode.MainMenu;
        }
    }
    // Network messages
    void OnServerInitialized()
    {
        if (m_serverDedicated) {
            guiMode = GUIDrawMode.DedicatedServer;
        } else {
            guiMode = GUIDrawMode.Connected;
        }

        connecting = false;
    }
    void OnFailedToConnect(NetworkConnectionError error)
    {
        Debug.Log("OnFailedToConnect " + error);

        connectionError = error;
        connectionErrorMsg = error.ToString();
        guiMode = GUIDrawMode.ConnectionError;

        connecting = false;
    }
    void OnDisconnectedFromServer(NetworkDisconnection info)
    {
        Debug.Log("OnDisconnectedFromServer " + info);

        if (info == NetworkDisconnection.LostConnection) {
            connectionErrorMsg = "Lost connection with server";
            guiMode = GUIDrawMode.ConnectionError;
        } else if (info == NetworkDisconnection.Disconnected) {
            connectionErrorMsg = "Server has closed connection";
            guiMode = GUIDrawMode.ConnectionError;
        }
    }
 void OnConnectedToServer()
 {
     guiMode = GUIDrawMode.Connected;
     connecting = false;
 }