PUN 2 菜鸟养成记 2主服务
生活随笔
收集整理的這篇文章主要介紹了
PUN 2 菜鸟养成记 2主服务
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
緊接上篇?PUN 2 菜鳥養(yǎng)成記 1連接上主服務? ? ??https://mp.csdn.net/postedit/88073999
我們來看一下創(chuàng)建房間的方法
RoomOptions options = new RoomOptions {MaxPlayers = 2};PhotonNetwork.CreateRoom("room name", options, null);嗯 .. 也是兩行 現(xiàn)在就不進去深挖了 我們來看回調(diào)
public override void OnJoinedRoom();恭喜你 你已經(jīng)開好房了 這個時候你就可以拉取這個房間內(nèi)玩家列表,查看每個人的屬性狀態(tài)了
foreach (Player p in PhotonNetwork.PlayerList) {Debug.log(p.NickName)object isPlayerReady;if (p.CustomProperties.TryGetValue(AsteroidsGame.PLAYER_READY, out isPlayerReady)){Debug.log((bool) isPlayerReady));} }房開好之后我們應該干嘛?當然是加入房間呀!
當然 加入房間之前我們得進前臺(大廳)吧
if (!PhotonNetwork.InLobby) {PhotonNetwork.JoinLobby(); }成功進入大廳后回調(diào)這個方法
public override void OnRoomListUpdate(List<RoomInfo> roomList);房間目錄有了我們就可以為所欲為 想去哪個房就去哪個房了
if (PhotonNetwork.InLobby) {PhotonNetwork.LeaveLobby(); } PhotonNetwork.JoinRoom("Room name");你也可以閉著眼睛隨便進,每間房都好玩(如果房間列表為空,那么會跟你創(chuàng)建一個房間并進入)
PhotonNetwork.JoinRandomRoom();?
進入房間后我自己和房間內(nèi)的人反應(回調(diào))是不一樣的
我是 : 哈哈哈 大爺我進來了
public override void OnJoinedRoom();房間內(nèi)其他人是 : 有客官進來一起玩了
public override void OnPlayerEnteredRoom(Player newPlayer);進入房間之后 會自動通知所有人房間內(nèi)其他人的準備情況
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps) {object isPlayerReady;if (changedProps.TryGetValue(AsteroidsGame.PLAYER_READY, out isPlayerReady)){Debug.log((bool) isPlayerReady);} }大家快點準備 ,游戲馬上就要開始啦
Hashtable props = new Hashtable() {{AsteroidsGame.PLAYER_READY, true}}; PhotonNetwork.LocalPlayer.SetCustomProperties(props);房主檢查大家的準備情況
private bool CheckPlayersReady() {if (!PhotonNetwork.IsMasterClient){return false;}foreach (Player p in PhotonNetwork.PlayerList){object isPlayerReady;if (p.CustomProperties.TryGetValue(AsteroidsGame.PLAYER_READY, out isPlayerReady)){if (!(bool) isPlayerReady){return false;}}else{return false;}}return true; }準備好了之后我們關閉這間房的大門
PhotonNetwork.CurrentRoom.IsOpen = false; PhotonNetwork.CurrentRoom.IsVisible = false;一起沉浸游戲的海洋吧
?
?
?
?
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的PUN 2 菜鸟养成记 2主服务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ARP协议(2)ARP协议格式详解
- 下一篇: kaminari