facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
行4: 行4:
  
 
==実際に変更した作業==
 
==実際に変更した作業==
===その1===
+
===using===
 
<pre>
 
<pre>
 
using Photon.Pun;
 
using Photon.Pun;
行11: 行11:
 
を追加
 
を追加
  
===その2===
+
===継承===
 
Photon.MonoBehaviour → MonoBehaviourPunへ
 
Photon.MonoBehaviour → MonoBehaviourPunへ
  
===その3===
+
===接続系===
 +
PhotonNetwork.ConnectUsingSettings("v1.0");
 +
 +
<pre>
 +
if (PhotonNetwork.IsConnected == false)
 +
{
 +
        PhotonNetwork.GameVersion = "v1.0";
 +
        PhotonNetwork.ConnectUsingSettings();
 +
}
 +
</pre>
 +
 
 +
===部屋系===
 
*roomOptions.customRoomProperties → roomOptions.CustomRoomProperties
 
*roomOptions.customRoomProperties → roomOptions.CustomRoomProperties
 
*roomOptions.customRoomPropertiesForLobby → roomOptions.CustomRoomPropertiesForLobby
 
*roomOptions.customRoomPropertiesForLobby → roomOptions.CustomRoomPropertiesForLobby
行21: 行32:
 
*roomOptions.isVisible → roomOptions.IsVisible
 
*roomOptions.isVisible → roomOptions.IsVisible
  
===その4===
+
===部屋プロパティ===
 
*room.name →  room.Name
 
*room.name →  room.Name
 
*room.customProperties → room.CustomProperties
 
*room.customProperties → room.CustomProperties
 
+
*PhotonNetwork.room → PhotonNetwork.CurrentRoom
===その5===
+
*PhotonNetwork.room → PhotonNetwork.CurrentRoom;
+
  
 
===部屋一覧===
 
===部屋一覧===
行78: 行87:
 
PhotonViewのあるところに以下追加
 
PhotonViewのあるところに以下追加
 
  using Photon.Pun;
 
  using Photon.Pun;
 +
 +
===RPC系===
 +
PhotonTargets.All → RpcTarget.All

2021年8月11日 (水) 04:08時点における版

photonとphoton2の違い

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

実際に変更した作業

using

using Photon.Pun;
using Photon.Realtime;

を追加

継承

Photon.MonoBehaviour → MonoBehaviourPunへ

接続系

PhotonNetwork.ConnectUsingSettings("v1.0");

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

部屋系

  • 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