void Awake()
    {
        DontDestroyOnLoad(this);

        natCapable = Network.TestConnection();

        if (Network.HavePublicAddress())
        {
            Debug.Log("This machine has a PUBLIC IP Address");
        }
        else
        {
            Debug.Log("This machine has a PRIVATE IP address");
        }

        gamemenustate = menustate.networklobby;
    }
Beispiel #2
0
        /// <summary>
        /// 根据软件状态更改菜单栏各项属性
        /// </summary>
        /// <param name="state"></param>
        private void menustatechange(menustate state)
        {
            switch (state)
            {
                case menustate.no_open_file:

                    break;
                case menustate.edit_file:

                    break;
                case menustate.start_demo:

                    break;
                default:

                    break;
            }
        }
Beispiel #3
0
    void Awake()
    {
        DontDestroyOnLoad(this);

        // Start connection test
        natCapable = Network.TestConnection();

        // What kind of IP does this machine have? TestConnection also indicates
        // this in the test results
        //if (Network.HavePublicAddress())
        //	Debug.Log("This machine has a public IP address");
        //else
        //	Debug.Log("This machine has a private IP address");

        // The game can have several menus and states, so I like to use
        // an enum to keep track of what state we’re in.  In this case we’re
        // in the MGS lobby
        gamemenustate = menustate.networklobby;
    }
    void ShowGUI()
    {
        if (gamemenustate == menustate.ingame)
        {
            if (GUI.Button(new Rect(10, 10, 90, 30), "Disconnect"))
            {
                Network.Disconnect();
                MasterServer.UnregisterHost();
                gamemenustate = menustate.networklobby;

                Application.LoadLevel("MasterGameServerLobby");
            }
        }
        else
        {
            if (gamemenustate == menustate.networklobby)
            {
                if (Network.peerType == NetworkPeerType.Disconnected)
                {
                    format.fontSize = 28;

                    GUI.Label(new Rect(((Screen.width / 2) - 80) * 0.2f, (Screen.height / 2) - 200, 400, 50), "Your game title here", format);
                    gameName = GUI.TextField(new Rect((((Screen.width / 2)) * 0.2f) + 200, (Screen.height / 2) - 100, 200, 30), gameName);

                    if (GUI.Button(new Rect(((Screen.width / 2) - 100) * 0.2f, (Screen.height / 2) - 100, 200, 30), "Start Server"))
                    {
                        if (doneTesting)
                        {
                            Network.InitializeServer(32, serverPort, useNat);
                        }
                        else
                        {
                            Network.InitializeServer(32, serverPort, !Network.HavePublicAddress());
                            MasterServer.updateRate = 3;
                            MasterServer.RegisterHost(gameType, gameName, "This is early network testing for my game");
                        }

                        HostData[] data = MasterServer.PollHostList();
                        int        _cnt = 0;

                        foreach (HostData gs in data)
                        {
                            if (!(filterNATHosts && gs.useNat))
                            {
                                string name = gs.gameName + " " + gs.comment + "(" + gs.connectedPlayers + "/" + gs.playerLimit + ")";

                                if (GUI.Button(new Rect(((Screen.width / 2) - 100) * 0.2f, (Screen.height / 2) + (50 * _cnt), 600, 30), name))
                                {
                                    useNat = gs.useNat;

                                    if (useNat)
                                    {
                                        print("Using NAT punchthrough to connect");
                                        Network.Connect(gs.guid);
                                    }
                                    else
                                    {
                                        print("Connecting directly to host");
                                        Network.Connect(gs.ip, gs.port);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #5
0
    void Awake()
    {
        DontDestroyOnLoad(this);

        // Start connection test
        natCapable = Network.TestConnection();

        // What kind of IP does this machine have? TestConnection also indicates
        // this in the test results
        //if (Network.HavePublicAddress())
        //	Debug.Log("This machine has a public IP address");
        //else
        //	Debug.Log("This machine has a private IP address");

           // The game can have several menus and states, so I like to use
           // an enum to keep track of what state we’re in.  In this case we’re
           // in the MGS lobby
        gamemenustate = menustate.networklobby;
    }
Beispiel #6
0
    // Here we paint the menu screen so the player can choose to join a game or start a new game
    void ShowGUI()
    {
        // in the AWAKE method we used: DontDestroyOnLoad(this);
        // so when we load our game level this ShowGUI is still running
        // so here we can see what menu we should be showing and display the appropriate menu

        // When we're ingame we want to show a Disconnect button to quit the game and return to the lobby
        if ( gamemenustate == menustate.ingame )
        {
                if (GUI.Button (new Rect(10,10,90,30),"Disconnect"))
                {
                    Network.Disconnect(); // Tell all the other clients you're disconnecting
                    MasterServer.UnregisterHost();
                    gamemenustate = menustate.networklobby;
                    // Return to the Master Game Server Lobby because we pressed disconnect
                    Debug.Log("Disconnecting...");
                    Application.LoadLevel("MasterGameServerLobby");
                }
        }
        else if ( gamemenustate == menustate.networklobby ) // ensure we're in the lobby, and not off somewhere unexpected
        {

            if (Network.peerType == NetworkPeerType.Disconnected)
            {
                format.fontSize = 28;
                GUI.Label(new Rect(((Screen.width/2)-80) * 0.2f,(Screen.height/2)-200,400,50),"VRChatroom", format);

                gameName = GUI.TextField(new Rect((((Screen.width/2)) * 0.2f)+200,
                                         (Screen.height/2)-100,
                                        200,
                                        30),
                                        gameName);
                // Start a new server
                if (GUI.Button(new Rect(((Screen.width/2)-100) * 0.2f,
                                         (Screen.height/2)-100,
                                        200,
                                        30),
                                        "Start Server"))
                {
                    // If start server is chosen then we want to initialize ourselves as a server
                    // and then register with the master server so other players will see us
                    // as a choice in the list of game servers

                    // We'll use Network.InitializeServer to enable our Game Server (GS) functionality
                    // but first we need to determine if we'll require clients to connect to us directly
                    // or by using NPT.

                    // The first two parameters to InitializeServer are how many clients can connect and the port to use
                    // The port needs to be unique, but on desktop/laptop pc's it's not usually an issue as there aren't a
                    // lot of network listeners running to contend
                    // Once the game starts you can consider using Network.maxConnections to stop any new players
                    // from connecting

                    if ( doneTesting ) // If done testing use the more thourough results of the testing to setup the server
                        Network.InitializeServer(32, serverPort, useNat );
                    else // otherwise setup the server and specific NPT based on public/private IP
                         // this is not as accurate as the full test, but is sufficient for most needs
                        Network.InitializeServer(32, serverPort, !Network.HavePublicAddress());
                    MasterServer.updateRate = 3;
                    MasterServer.RegisterHost(gameType, gameName, "This is early network testing for my game");
        //					MasterServer.dedicatedServer = true; <- I placed this here b/c when I uncommented it up top it didn't seem to work. Uncomment if you want a dedicated server.
                }

                gMyUsername = GUI.TextField(new Rect((((Screen.width/2)) * 0.2f)+200,
                                         (Screen.height/2) - 50,
                                        200,
                                        30),
                                        gMyUsername);

                HostData[] data = MasterServer.PollHostList();	// Extract the list of available GS's into a local variable array for processing
                int _cnt = 0;

                // Loop through all the available GS's provided by the MGS and display each one so we can choose one to joing
                foreach (HostData gs in data)
                {
                    _cnt++;
                    // Do not display NAT enabled games if we cannot do NAT punchthrough
                    if ( !(filterNATHosts && gs.useNat) )
                    {
                        // Build a name string to use for displaying the GS in the list
                        string name = gs.gameName + "-" + gs.comment  + " (" + gs.connectedPlayers + " / " + gs.playerLimit +")";

                        if (GUI.Button(new Rect(((Screen.width/2)-100) * 0.2f,
                                         (Screen.height/2)+(50*_cnt),
                                        600,
                                        30),
                                        name ))
                        {
                            Debug.Log("Username: "******"Using Nat punchthrough to connect");
                                Network.Connect(gs.guid);
                            }
                            else
                            {
                                print("Connecting directly to host");
                                Network.Connect(gs.ip, gs.port);
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #7
0
    // Here we paint the menu screen so the player can choose to join a game or start a new game
    void ShowGUI()
    {
        // in the AWAKE method we used: DontDestroyOnLoad(this);
        // so when we load our game level this ShowGUI is still running
        // so here we can see what menu we should be showing and display the appropriate menu

        // When we're ingame we want to show a Disconnect button to quit the game and return to the lobby
        if (gamemenustate == menustate.ingame)
        {
            if (GUI.Button(new Rect(10, 10, 90, 30), "Disconnect"))
            {
                Network.Disconnect();                         // Tell all the other clients you're disconnecting
                MasterServer.UnregisterHost();
                gamemenustate = menustate.networklobby;
                // Return to the Master Game Server Lobby because we pressed disconnect
                Debug.Log("Disconnecting...");
                Application.LoadLevel("MasterGameServerLobby");
            }
        }
        else if (gamemenustate == menustate.networklobby)           // ensure we're in the lobby, and not off somewhere unexpected
        {
            if (Network.peerType == NetworkPeerType.Disconnected)
            {
                format.fontSize = 28;
                GUI.Label(new Rect(((Screen.width / 2) - 80) * 0.2f, (Screen.height / 2) - 200, 400, 50), "VRChatroom", format);

                gameName = GUI.TextField(new Rect((((Screen.width / 2)) * 0.2f) + 200,
                                                  (Screen.height / 2) - 100,
                                                  200,
                                                  30),
                                         gameName);
                // Start a new server
                if (GUI.Button(new Rect(((Screen.width / 2) - 100) * 0.2f,
                                        (Screen.height / 2) - 100,
                                        200,
                                        30),
                               "Start Server"))
                {
                    // If start server is chosen then we want to initialize ourselves as a server
                    // and then register with the master server so other players will see us
                    // as a choice in the list of game servers

                    // We'll use Network.InitializeServer to enable our Game Server (GS) functionality
                    // but first we need to determine if we'll require clients to connect to us directly
                    // or by using NPT.

                    // The first two parameters to InitializeServer are how many clients can connect and the port to use
                    // The port needs to be unique, but on desktop/laptop pc's it's not usually an issue as there aren't a
                    // lot of network listeners running to contend
                    // Once the game starts you can consider using Network.maxConnections to stop any new players
                    // from connecting

                    if (doneTesting)                       // If done testing use the more thourough results of the testing to setup the server
                    {
                        Network.InitializeServer(32, serverPort, useNat);
                    }
                    else                     // otherwise setup the server and specific NPT based on public/private IP
                    // this is not as accurate as the full test, but is sufficient for most needs
                    {
                        Network.InitializeServer(32, serverPort, !Network.HavePublicAddress());
                    }
                    MasterServer.updateRate = 3;
                    MasterServer.RegisterHost(gameType, gameName, "This is early network testing for my game");
//					MasterServer.dedicatedServer = true; <- I placed this here b/c when I uncommented it up top it didn't seem to work. Uncomment if you want a dedicated server.
                }


                gMyUsername = GUI.TextField(new Rect((((Screen.width / 2)) * 0.2f) + 200,
                                                     (Screen.height / 2) - 50,
                                                     200,
                                                     30),
                                            gMyUsername);

                HostData[] data = MasterServer.PollHostList();                  // Extract the list of available GS's into a local variable array for processing
                int        _cnt = 0;

                // Loop through all the available GS's provided by the MGS and display each one so we can choose one to joing
                foreach (HostData gs in data)
                {
                    _cnt++;
                    // Do not display NAT enabled games if we cannot do NAT punchthrough
                    if (!(filterNATHosts && gs.useNat))
                    {
                        // Build a name string to use for displaying the GS in the list
                        string name = gs.gameName + "-" + gs.comment + " (" + gs.connectedPlayers + " / " + gs.playerLimit + ")";

                        if (GUI.Button(new Rect(((Screen.width / 2) - 100) * 0.2f,
                                                (Screen.height / 2) + (50 * _cnt),
                                                600,
                                                30),
                                       name))
                        {
                            Debug.Log("Username: "******"Using Nat punchthrough to connect");
                                Network.Connect(gs.guid);
                            }
                            else
                            {
                                print("Connecting directly to host");
                                Network.Connect(gs.ip, gs.port);
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #8
0
 public void dc()
 {
     gamemenustate = menustate.networklobby;
 }