Unity5.1 new network engine unet (vi) unet multiplayer Lobby

Source: Internet
Author: User

??

Sun Guangdong 2015.7.12

Multiplayer Lobby multi-player Hall


A lot of multiplayer games have a staging area (staging area): The actual game waits for all players to join the place, in which areas-often referred to as "lobby", the player may be able to select options that can set themselves up to be ready after the game starts.


Networklobbymanager is a dedicated NetworkManager network manager that can provide unity multiplayer gaming halls (Unity multiplayer lobby). It includes:

? Limit the number of players that can be added
? Each client supports multiple players, so limit the number of players per client
? Prevent players from playing in-progress when adding
? Each player is ready, so all players are ready when the game starts
? Each player configuration data
? Rejoin the hall when the game is over.
? virtual function, which allows custom logic to lobby events


Guilobbymanager is for lobby special lobby management, which provides the UI. It can be used as an asset pack (asset package) that can be imported into Unity project to easily add a lobby to multiplayer game. Scripts and UI presets can be customized in packages to make the look and feel different.



There are two player objects-each prefabricated slot in the Networklobbymanager (prefab slot):


Lobbyplayer Object


? Each player
? Created when you create a client connection or when you add a player
? persists until client disconnects
? Flag is prepared for the player in the lobby
? Handle orders in the lobby.
? Add user scripts to prefab to save game-specific player data


Gameplayer Object
? Each player
? Created when you start a game scene
? Was destroyed when he re-entered the hall.
? Handling commands in the game

The Networklobbyplayer component is used for Lobbyplayer objects. It provides some virtual function callbacks that can be used to customize the lobby behavior

    public virtual void Oncliententerlobby ()    {    } public    virtual void Onclientexitlobby ()    {    }    public virtual void Onclientready (bool readyState)    {    }



Add Lobby to a Game:


The process of adding networklobby to a multiplayer game (without using the multiplayer lobby asset pack):
? Create a new lobbyscene lobby scene
? Scene added to build settings, as the first scene
? Create a new game object in a new scene and rename it to Lobbymanager
? Add the Networklobbymanager component to the Lobbymanager object
? Add the Networkmanagerhud component to the Lobbymanager object
? Open the Networklobbymanager Assembly on the Inspector panel
? Set Lobbyscene to the current scene
? Set Playscene as the main game-playing scene
? Create a new Game object and rename it to Lobbyplayer
? Add the Networklobbyplayer component to the Lobbyplayer
? Create a preset for Lobbyplayer to remove this instance from the field
? Set the Lobbyplayerprefab slot to the Lobbyplayer pre-built body
? The player's Gameplayerprefab slot in the main game is set to this prefab
? Save the scene.
? Run the game


This version of Networklobbymanager uses the Ongui user interface, like Networkmanagerhud. For a better user interface please use the multi-player lobby asset pack (Multiplayer-lobby asset package.
)。

Networklobbymanager has a number of virtual function callbacks that can be used to customize lobby behavior. The most important thing is that Onlobbyserversceneloadedforplayer is called by each player on the server because they are transitioning from the lobby to the main game. This is the ideal place to apply settings, from the lobby to the player's game object.

    For users to apply settings from their lobby player object to their In-game player object public    override bool Onlo Bbyserversceneloadedforplayer (Gameobject lobbyplayer, Gameobject gameplayer)    {        var cc = Lobbyplayer.getcomponent<colorcontrol> ();        var player = gameplayer.getcomponent<player> ();        Player.mycolor = Cc.mycolor;        return true;    }



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Unity5.1 new network engine unet (vi) unet multiplayer Lobby

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.