「Unity/photon/punとpun2の違い」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→プレイヤー系) |
(→プレイヤー系) |
||
行32: | 行32: | ||
* PhotonNetwork.countOfPlayers → PhotonNetwork.CountOfPlayers | * PhotonNetwork.countOfPlayers → PhotonNetwork.CountOfPlayers | ||
* PhotonNetwork.playerList → PhotonNetwork.PlayerList | * PhotonNetwork.playerList → PhotonNetwork.PlayerList | ||
+ | * OnPhotonPlayerConnected(PhotonPlayer) → OnPlayerEnteredRoom(Player) | ||
===部屋系=== | ===部屋系=== |
2021年8月11日 (水) 19:12時点における版
目次
photonとphoton2の違い
参考:https://lifter-liberty.localinfo.jp/posts/5296583
実際に変更した作業
using
using Photon.Pun; using Photon.Realtime;
を追加
継承
- Photon.MonoBehaviour → MonoBehaviourPunへ
- Photon.MonoBehaviour → MonoBehaviourPunCallbacksへ(OnRoomListUpdateを使う場合はこちら)
接続系
PhotonNetwork.ConnectUsingSettings("v1.0");
↓
if (PhotonNetwork.IsConnected == false) { PhotonNetwork.GameVersion = "v1.0"; PhotonNetwork.ConnectUsingSettings(); }
プレイヤー系
- PhotonNetwork.playerName → PhotonNetwork.NickName
- PhotonNetwork.otherPlayers → PhotonNetwork.PlayerListOthers
- p.name → p.Nickname
- PhotonNetwork.countOfPlayers → PhotonNetwork.CountOfPlayers
- PhotonNetwork.playerList → PhotonNetwork.PlayerList
- OnPhotonPlayerConnected(PhotonPlayer) → OnPlayerEnteredRoom(Player)
部屋系
auto-lobbyのチェック
↓
pun2にはauto-lobbyがないので・・。
public override void OnConnectedToMaster() { Debug.Log("OnConnectedToMaster"); if (PhotonNetwork.IsConnected) { PhotonNetwork.JoinLobby(); } }
部屋系
- roomOptions.customRoomProperties → roomOptions.CustomRoomProperties
- roomOptions.customRoomPropertiesForLobby → roomOptions.CustomRoomPropertiesForLobby
- roomOptions.maxPlayers → roomOptions.MaxPlayers
- roomOptions.isOpen → roomOptions.IsOpen
- roomOptions.isVisible → roomOptions.IsVisible
部屋プロパティ
- room.name → room.Name
- room.customProperties → room.CustomProperties
- PhotonNetwork.room → PhotonNetwork.CurrentRoom
部屋一覧
pun1
void OnReceivedRoomListUpdate() { RoomInfo[] rooms = PhotonNetwork.GetRoomList(); // 注意:OnReceivedRoomListUpdate()が呼ばれた以後でしか取得できない if (rooms.Length == 0) { Debug.Log("ルームが一つもありません"); } else { foreach (RoomInfo room in rooms) { Debug.Log("RoomName:" + room.name); Debug.Log("userId:" + room.customProperties["userId"]); } } }
↓
pun2
using System.Linq; public override void OnRoomListUpdate(List<RoomInfo> roomList) { Debug.Log("OnRoomListUpdate"); List<RoomInfo> tmpRoomList = roomList.Where(s => s.IsOpen).ToList(); if (tmpRoomList.Count == 0) { Debug.Log("ルームが一つもありません"); } else { foreach (RoomInfo room in tmpRoomList) { Debug.Log("RoomName:" + room.Name); Debug.Log("userId:" + room.CustomProperties["userId"]); } } }
OnRoomListUpdateでエラーが出る場合は、以下置換。
MonoBehaviourPun → MonoBehaviourPunCallbacks
PhotonViewエラー
PhotonViewのあるところに以下追加
using Photon.Pun;
RPC系
PhotonTargets.All → RpcTarget.All
コールバック
- void OnJoinedLobby() → public override void OnJoinedLobby()
- void OnJoinedRoom() → public override void OnJoinedRoom()
- void OnPhotonRandomJoinFailed() → public override void OnJoinRandomFailed(short returnCode, string message)
chatのエラー
error CS1061: 'ServerSettings' does not contain a definition for 'ChatAppID' and no accessible extension method 'ChatAppID' accepting a first argument of type 'ServerSettings' could be found (are you missing a using directive or an assembly reference?)
ChatAppIDが設定に入ってないので、入れる。
PhotonNetwork.PhotonServerSettings.ChatAppID → PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat
参考
https://doc.photonengine.com/ja-jp/pun/current/getting-started/initial-setup
https://doc.photonengine.com/ja-jp/pun/current/getting-started/migration-notes