unity lobbymanager怎么让lobbyplayer多个

Unity网络教程翻译(三)多人游戏大厅_词汇网
Unity网络教程翻译(三)多人游戏大厅
责任编辑:词汇网 发表时间: 14:12:05
Multiplayer Lobby多人游戏大厅Many multiplayergames have a staging area for players to join before playing the actual game.In this area - often called the “lobby”, players may be able to pick optionsand be able to set themselves as ready for the game to start.大部分多人在线游戏都会有一个让玩家在加入正式游戏前的临时中转区。在这个区域里 C 通常我们管它叫做“大厅”,玩家可以进行选项的设置,进行游戏开始前的各种准备。TheNetworkLobbyManager is a specialized&NetworkManager&thatprovides a lobby for Unity Multiplayer games. It includes:NetworkLobbyManager(联网大厅管理器)是一个专门为unity在线游戏提供一个大厅的NetworkManager(联网管理器)。它包含以下内容:Limit on numberof players that can joinSupport formultiple players per client with a limit on number of players per clientPrevent playersfrom joining game in-progressPer-player readystate, so that game starts when all players are readyPer-playerconfiguration dataRe-joining thelobby when the game is finishedVirtual functionsthat allow custom logic for lobby eventsA simple userinterface for interacting with the lobby为每个客户端上的每个玩家提供有限的其他其他玩家防止玩家在游戏进行中的时候加入每个玩家的准备状态,游戏将会在所有玩家都准备好的情况下开始每个玩家的设置数据当游戏完成的时候重新加入大厅提供大厅事件的虚函数供开发人员进行自定义逻辑的开发提供简单的用户界面给大厅做交互TheGuiLobbyManager is a special lobby manager that provides a user-interface forthe lobby. It is available as an asset package and can be imported into Unityprojects to easily add a lobby to multiplayer games. The scripts and UI prefabsin the package can be customized to make the look and feel of the lobby uniquefor any game.GuiLobbyManager(大厅界面管理器)是一个为大厅提供用户界面的特殊的大厅管理器。它可以被打包成一个资源包,便于导入到一个Unity多人在线项目来添加一个大厅。Below are the NetworkLobbyManagervirtual functions called on the server:以下是NetworkLobbyManager(网络大厅管理器)在服务器上被调用的虚函数:OnLobbyStartHost// 开启一个大厅主机时OnLobbyStopHost// 停止一个大厅主机时OnLobbyStartServer// 开启一个大厅服务器时OnLobbyServerConnect// 连接一个大厅服务器时OnLobbyServerDisconnect// 大厅服务器关闭时OnLobbyServerSceneChanged// 大厅服务器切换场景时OnLobbyServerCreateLobbyPlayer// 大厅服务器创建了一个大厅玩家OnLobbyServerCreateGamePlayer// 大厅服务器创建了一个游戏玩家OnLobbyServerPlayerRemoved// 大厅服务器玩家被移除OnLobbyServerSceneLoadedForPlayer// 玩家加载大厅服务器场景时OnLobbyServerPlayersReady// 大厅玩家准备时All of the aboveserver functions have empty default implementations, except forOnLobbyServerPlayersReady, which calls ServerChangeScene with the PlayScene.以上所有服务器方法除了OnLobbyServerPlayersReady(为PlayScene调用ServerChangeScene)都有默认空的实现, Below are theNetworkLobbyManager virtual functions called on the client:以下NetworkLobbyManager(联网大厅管理器)虚函数在客户端调用OnLobbyClientEnter// 大厅客户端进入OnLobbyClientExit// 大厅客户端退出OnLobbyClientConnect// 大厅客户端连接OnLobbyClientDisconnect// 大厅客户端断开连接OnLobbyStartClient// 大厅开始客户端OnLobbyStopClient// 大厅停止客户端OnLobbyClientSceneChanged// 大厅客户端场景切换OnLobbyClientAddPlayerFailed// 大厅客户端添加玩家失败All of the aboveclient functions have empty default implementations.以上所有客户端函数都有默认空的实现。Lobby Player Objects大厅玩家对象There are twokinds of player objects - each which has a prefab slot in theNetworkLobbyManager. The slots can be seen in this screenshot:有两种类型的玩家对象 C NetworkLobbyManager(网络大厅管理器)中这两种预制的槽都有。可以在下面截图中看到:650) this.width=650;" src="/wyfs02/M02/7F/A8/wKioL1coPfvjPn2CAACP5IncrqU561.png" title="1.png" alt="wKioL1coPfvjPn2CAACP5IncrqU561.png" />The LobbyPlayeris created from the LobbyPlayerPrefab when a player joins the lobby:当一个玩家加入大厅时会由LobbyPlayerPrefab(大厅玩家预制)创建LobbyPlayer(大厅玩家):One LobbyPlayerfor each playerCreated whenclient connects, or player is addedExists untilclient disconnectsHolds the readyflag for this player for the lobbyHandles commandswhile in the lobbyAdd user scriptsto this prefab to hold game-specific player dataThis prefab musthave a&NetworkLobbyPlayer&component每个玩家都会有一个大厅玩家客户端连接或者玩家加入时创建直到客户端断开连接否则会一直存在为玩家保存大厅的准备状态在大厅中时,处理在大厅中的命令在这个预制上添加用户自定义脚本来保存玩家特有的游戏数据这个预制必须有一个NetworkLobbyPlayer组件Minimum Players最少玩家下限The “MinimumPlayers” field represents the minimum number of “Ready” players in the Lobby tostart the Match with. If the number of connected clients is more than the“Minimum Players” value, then waiting for all connected clients to become“Ready” will start the Match.“Minimum Players”(最少玩家下限)代表大厅开启一个游戏需要最少进行了”准备“的玩家的数量。如果连接的客户端的数量超过了最少玩家下限,当所有连接的客户端都变成”准备“后,游戏将会开始。For example if“Minimum Players” is set to 2:例如” Minimum Players“(最少玩家下限)设置为2:Start oneinstance of the game and start Host. Then in game Lobby UI press “Start” foryour player. You will still be in Lobby mode because minimum number of Readyplayers to start game is 2.Start two moreinstances of the game and start Clients there. It doesn’t matter that “MinimumPlayers” set to 2. Wait for all - 3 in this case - connected players to becomeReady.Press “Start” inLobby UI for one player. Two players are Ready, but still in Lobby mode. Press“Start” in the Lobby UI for the last player and now all players moved to Gamemode.开启一个游戏主机,然后在大厅UI上点击”Start“,你将会还在大厅中,因为至少需要2个玩家进入准备状态才能开始游戏。再运行2个游戏客户端,” Minimum Players “设置为2是没关系的。等所有的三个玩家都变成准备状态,一个玩家在在大厅UI上点击”开始“。两个玩家准备,此时仍然在大厅模式下。最后一个玩家点击”开始“,现在所有玩家进入游戏模式。GamePlayer游戏玩家The GamePlayer iscreated from the GamePlayerPrefab when the game starts:在游戏开始的时候会根据GamePlayerPrefab(游戏玩家预制)创建GamePlayer(游戏玩家):One GamePlayerfor each playerCreated when gamescene is startedDestroyed whenre-entering lobbyHandles commandswhile in the gameThis prefab musthave a&NetworkIdentity&component每个玩家都有一个GamePlayer(游戏玩家)在游戏场景开始的时候创建返回大厅的时候销毁在游戏进行过程中控制命令这个预制必须有一个NetworkIdentify(联网身份证)组件The&NetworkLobbyPlayer&componentis used for LobbyPlayer objects. It supplies some virtual function callbacksthat can be used for custom lobby behaviorNetowrkLobbyPlayer(联网大厅玩家)组件是用于LobbyPlayer(大厅玩家)对象上的。它提供了一些虚函数回调来用于自定义大厅行为。&&& public virtual void OnClientEnterLobby();// 客户端进入大厅&&& public virtual void OnClientExitLobby(); //客户端退出大厅&&& public virtual void OnClientReady(boolreadyState); // 客户端准备(是否准备)The function&OnClientEnterLobby&iscalled on the client when the game enters the lobby. This happens when thelobby scene starts for the first time, and also when returning to the lobbyfrom the game-play scene.当进入大厅时,OnClientEnterLobby回调会在客户端被调用。这个事件会在大厅场景第一次运行和从游戏运行场景返回大厅时发生。The function&OnClientExitLobby&iscalled on the client when the game exists the lobby. This happens whenswitching to the game-play scene.当退出大厅的时候,将会在客户端调用OnClientExitLobby回调。这个事件发生在切换到游戏场景中。The function&OnClientReady&iscalled on the client when the ready state of that player changes.当玩家改变准备状态的时候,OnClientReady会在客户端被回调。Adding the Lobby to a Game为游戏添加一个大厅Process foradding a NetworkLobby to a multiplayer game (without using themultiplayer-lobby asset package):为一个联网游戏添加NetworkLobby(联网大厅)的过程(在没有使用multplayer-lobby资源包的情况下):Create a newlobby sceneAdd the scene tothe build settings, as the first sceneCreate a new gameobject in the new scene, rename it to LobbyManagerAdd theNetworkLobbyManager component to the LobbyManager objectAdd theNetworkManagerHUD component to the LobbyManager objectOpen theinspector for the NetworkLobbyManager componentSet theLobbyScene slot of the NetworkLobbyManger to the scene that contains theLobbyManager objectSet the PlaySceneslot of the NetworkLobbyManager to the main game-play scene for the gameCreate a newgameObject and rename it to LobbyPlayerAdd theNetworkLobbyPlayer component to the LobbyPlayerCreate a prefabfor the LobbyPlayer and delete the instance from the sceneSet theLobbyPlayerPrefab slot to the LobbyPlayer prefabSet theGamePlayerPrefab slot to the prefab for the player in the main gameSave the scene.Run the game创建一个新的大厅窗井将这个场景添加到Build Setting(打包设置)的场景列表中,并且将其顺序改为1(拖拽到最上方)在大厅场景中创建一个新游戏对象,重命名为LobbyManager(大厅管理器)在LobbyManager(大厅管理器)对象上添加NetworkLobbyManager(联网大厅管理器)组件在LobbyManager(大厅管理器)对象上添加NetworkManagerHUD(联网管理器导航)组件在inspector(审查)视图中打开NetworkLobbyManager(联网大厅管理器)组件将带有LobbyManager(大厅管理器)对象的大厅场景设置到LobbyScene(大厅场景)槽当中将游戏主逻辑的游戏场景设置到NetworkLobbyManager的PlayScene(游戏场景)槽中创建一个新的游戏对象并且将其重命名为LobbyPlayer(大厅玩家)为其添加NetworkLobbyPlayer组件将LobbyPlayer制作成一个预制,并且删除掉场景中的LobbyPlayer对象将刚才生成的大厅玩家预制拖到NetworkLobbyManager的LobbyPlayerPrefab槽上将游戏中的玩家预制设置到NetorkLobbyManager的GamePlayerPrefab槽上保存场景运行游戏This version ofthe NetworkLobbyManager uses the OnGUI user interface like the&NetworkManagerHUD.For a better user interface use the multiplayer-lobby asset package.NetworkLobbyManager版的用户界面是使用类似NetworkManagerHUD(联网导航)的OnGUI的界面。想要使用更好的用户界面请使用multiplayer-lobby资源包。TheNetworkLobbyManager has many virtual function callbacks that can be used forcustom lobby behaviour. Most important is&OnLobbyServerSceneLoadedForPlayerwhichis called on the server for each player as they transition from the lobby tothe main game. This is the ideal place to apply settings from the lobby to theplayer’s game-play object.NetworkLobbyManager有很多回调虚函数可以用来自定义大厅行为。其中最重要的是当每个玩家从大厅切换到游戏时调用的OnLobbyServerSceneLoadedForPlayer函数。这里是将大厅的配置提交到游戏对象中最理想的位置。//&for&users&to&apply&settings&from&their&lobby&player&object&totheir&in-game&player&object//&将大厅玩家的配置提交给游戏玩家&&&&public&override&boolOnLobbyServerSceneLoadedForPlayer(GameObject&lobbyPlayer,&GameObject&gamePlayer)&&&&{&&&&&&&&var&cc&=lobbyPlayer.GetComponent();&&&&&&&&var&player&=gamePlayer.GetComponent();&&&&&&&&player.myColor&=&cc.myC&&&&&&&&return&&&&&}Sample Project示例项目There is a sampleproject on the Unity asset store that uses the NetworkLobbyManager and providesa GUI for the lobby. This can be used as a starting point for making amultiplayer game with a lobby.Lobby SampleProject这里是Unity资源商店中一个使用了NetworkLobbyManager并且提供了GUI的简单示例。这个可以作为一个在线多人游戏大厅的入门。简单大厅项目 词汇网声明本文技术文章来自:51cto
上一集:没有了 下一集:
相关文章:&&&&&&&&&&&&
最新添加资讯
24小时热门资讯
附近好友搜索}

我要回帖

更多关于 unitywebplayer怎么用 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信