facebook twitter hatena line email

「Unity/photon/punとpun2の違い」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(その4)
(Admin がページ「Unity/photon/photon2違い」を「Unity/photon/punとpun2の違い」に、リダイレクトを残さずに移動しました)
 
(同じ利用者による、間の43版が非表示)
行1: 行1:
==photonとphoton2の違い==
+
==punとpun2の違い==
  
 
参考:https://lifter-liberty.localinfo.jp/posts/5296583
 
参考:https://lifter-liberty.localinfo.jp/posts/5296583
  
 
==実際に変更した作業==
 
==実際に変更した作業==
===その1===
+
===using===
 
<pre>
 
<pre>
 
using Photon.Pun;
 
using Photon.Pun;
行10: 行10:
 
</pre>
 
</pre>
 
を追加
 
を追加
 +
===部屋系===
 +
pun2には初期でのauto-lobbyのonが無いので、
 +
pun1で、auto-lobbyのチェックしていれば、pun2では、以下が必要。
  
===その2===
+
<pre>
Photon.MonoBehaviour → MonoBehaviourPunへ
+
public override void OnConnectedToMaster()
 +
{
 +
Debug.Log("OnConnectedToMaster");
 +
if (PhotonNetwork.IsConnected)
 +
{
 +
PhotonNetwork.JoinLobby();
 +
}
 +
}
 +
</pre>
 +
 
 +
===継承===
 +
*Photon.MonoBehaviour → MonoBehaviourPunへ
 +
*Photon.MonoBehaviour → MonoBehaviourPunCallbacksへ(OnRoomListUpdateを使う場合はこちら)
 +
 
 +
===接続系===
 +
pun1
 +
PhotonNetwork.ConnectUsingSettings("v1.0");
 +
 +
 
 +
pun2
 +
<pre>
 +
if (PhotonNetwork.IsConnected == false)
 +
{
 +
        PhotonNetwork.GameVersion = "v1.0";
 +
        PhotonNetwork.ConnectUsingSettings();
 +
}
 +
</pre>
 +
 
 +
PhotonNetwork.isMasterClient → PhotonNetwork.IsMasterClient
 +
 
 +
===プレイヤー系===
 +
* PhotonNetwork.playerName → PhotonNetwork.NickName
 +
* PhotonNetwork.otherPlayers → PhotonNetwork.PlayerListOthers
 +
* p.name → p.Nickname
 +
* PhotonNetwork.countOfPlayers → PhotonNetwork.CountOfPlayers
 +
* PhotonNetwork.playerList → PhotonNetwork.PlayerList
 +
* public void OnPhotonPlayerConnected(PhotonPlayer) → public override void OnPlayerEnteredRoom(Player)
 +
* public void OnPhotonPlayerDisconnected(PhotonPlayer) →  public override void OnPlayerLeftRoom(Player)
 +
* PhotonNetwork.offlineMode →  PhotonNetwork.OfflineMode
 +
 
 +
===部屋系===
 +
*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.name →  room.Name
 +
*room.customProperties → room.CustomProperties
 +
*PhotonNetwork.room → PhotonNetwork.CurrentRoom
 +
 
 +
===部屋一覧===
 +
pun1
 +
<pre>
 +
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"]);
 +
}
 +
}
 +
}
 +
</pre>
 +
 +
 
 +
pun2
 +
<pre>
 +
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"]);
 +
}
 +
}
 +
}
 +
</pre>
 +
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)
 +
 
 +
pun1
 +
void OnPhotonJoinRoomFailed(object[]) {
 +
    Debug.Log("PhotonManager OnPhotonJoinRoomFailed " + codeAndMsg[0] + " " + codeAndMsg[1]);
 +
 +
 
 +
pun2
 +
public override void OnJoinRoomFailed(short returnCode, string message) {
 +
    Debug.Log("PhotonManager OnJoinRoomFailed " + returnCode + " " + 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
 +
 
 +
===GetRegions failedが起こった場合===
 +
以下エラーが起こったとき
 +
GetRegions failed. AppId is unknown on the (cloud) server. ApplicationNotFound
 +
AppIdが正しくないので、もう一度コピペする
 +
 
 +
===LeaveRoomはIsConnectで囲む===
 +
PhotonNetwork.LeaveRoom();
 +
 +
<pre>
 +
if (PhotonNetwork.IsConnected) {
 +
    PhotonNetwork.LeaveRoom();
 +
}
 +
</pre>
 +
 
 +
==参考==
 +
https://gamefbb.com/%E3%80%90unity%E3%80%91photon%E3%81%AB%E6%8E%A5%E7%B6%9A%E3%81%97%E3%81%A6%E3%83%AD%E3%83%93%E3%83%BC%E3%81%AB%E5%85%A5%E3%82%8B%E3%80%90pun2%E3%80%91/
  
===その3===
+
https://doc.photonengine.com/ja-jp/pun/current/getting-started/initial-setup
roomOptions.customRoomProperties → roomOptions.CustomRoomProperties
+
roomOptions.customRoomPropertiesForLobby → roomOptions.CustomRoomPropertiesForLobby
+
roomOptions.maxPlayers → roomOptions.MaxPlayers
+
roomOptions.isOpen → roomOptions.IsOpen
+
roomOptions.isVisible → roomOptions.IsVisible
+
  
===その4===
+
https://doc.photonengine.com/ja-jp/pun/current/getting-started/migration-notes
room.name →  room.Name
+
room.customProperties → room.CustomProperties
+

2022年12月28日 (水) 16:18時点における最新版

punとpun2の違い

参考:https://lifter-liberty.localinfo.jp/posts/5296583

実際に変更した作業

using

using Photon.Pun;
using Photon.Realtime;

を追加

部屋系

pun2には初期でのauto-lobbyのonが無いので、 pun1で、auto-lobbyのチェックしていれば、pun2では、以下が必要。

public override void OnConnectedToMaster()
{
	Debug.Log("OnConnectedToMaster");
	if (PhotonNetwork.IsConnected)
	{
		PhotonNetwork.JoinLobby();
	}
}

継承

  • Photon.MonoBehaviour → MonoBehaviourPunへ
  • Photon.MonoBehaviour → MonoBehaviourPunCallbacksへ(OnRoomListUpdateを使う場合はこちら)

接続系

pun1

PhotonNetwork.ConnectUsingSettings("v1.0");

pun2

if (PhotonNetwork.IsConnected == false)
{
        PhotonNetwork.GameVersion = "v1.0";
        PhotonNetwork.ConnectUsingSettings();
}

PhotonNetwork.isMasterClient → PhotonNetwork.IsMasterClient

プレイヤー系

  • PhotonNetwork.playerName → PhotonNetwork.NickName
  • PhotonNetwork.otherPlayers → PhotonNetwork.PlayerListOthers
  • p.name → p.Nickname
  • PhotonNetwork.countOfPlayers → PhotonNetwork.CountOfPlayers
  • PhotonNetwork.playerList → PhotonNetwork.PlayerList
  • public void OnPhotonPlayerConnected(PhotonPlayer) → public override void OnPlayerEnteredRoom(Player)
  • public void OnPhotonPlayerDisconnected(PhotonPlayer) → public override void OnPlayerLeftRoom(Player)
  • PhotonNetwork.offlineMode → PhotonNetwork.OfflineMode

部屋系

  • 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.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)

pun1

void OnPhotonJoinRoomFailed(object[]) {
    Debug.Log("PhotonManager OnPhotonJoinRoomFailed " + codeAndMsg[0] + " " + codeAndMsg[1]);

pun2

public override void OnJoinRoomFailed(short returnCode, string message) {
    Debug.Log("PhotonManager OnJoinRoomFailed " + returnCode + " " + 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

GetRegions failedが起こった場合

以下エラーが起こったとき

GetRegions failed. AppId is unknown on the (cloud) server. ApplicationNotFound

AppIdが正しくないので、もう一度コピペする

LeaveRoomはIsConnectで囲む

PhotonNetwork.LeaveRoom();

if (PhotonNetwork.IsConnected) {
    PhotonNetwork.LeaveRoom();
}

参考

https://gamefbb.com/%E3%80%90unity%E3%80%91photon%E3%81%AB%E6%8E%A5%E7%B6%9A%E3%81%97%E3%81%A6%E3%83%AD%E3%83%93%E3%83%BC%E3%81%AB%E5%85%A5%E3%82%8B%E3%80%90pun2%E3%80%91/

https://doc.photonengine.com/ja-jp/pun/current/getting-started/initial-setup

https://doc.photonengine.com/ja-jp/pun/current/getting-started/migration-notes