我们正在使用光子引擎制作随机配对游戏。我们希望在一定时间内将玩家与不同的用户进行匹配。如果PlayerA与PlayerB一起玩,则他们不能再播放30分钟。做这种系统的最佳方法是什么?
我们尝试了一些算法,但是不太适合。
public override void OnJoinedRoom()
{
if(PhotonNetwork.isMasterClient)
StartCoroutine("StartWaiting");
theSameGame = false;
var photonPlayer = PhotonNetwork.Instantiate("PhotonPlayerKO", Vector3.zero, Quaternion.identity, 0) as GameObject;
photonPlayer.name = "Local Player";
if(PhotonNetwork.playerList.Count() > 1 && !PhotonNetwork.isMasterClient)
photonViewOfManager.RPC("MyNameIs", PhotonTargets.Others, PlayerInfos.thePlayersName);
//Sending player name to other player to check whether this name is playable or not ?
if(!PhotonNetwork.isMasterClient)
StartCoroutine("CheckError");
}
它可以工作,但是有一些缺点,例如比较耗时。是否有更好解决方案的想法?
最佳答案
解决方案可以在这里找到:documentation
您需要使用SQL大厅类型:
创建房间:
RoomOptions roomOptions = new RoomOptions();
roomOptions.MaxPlayers = expectedMaxPlayers;
// in this example, C0 might be 0 or 1 for the two (fictional) game modes
roomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "C0", 1 } };
roomOptions.customRoomPropertiesForLobby = new string[] { "C0" }; // this makes "C0" available in the lobby
// let's create this room in SqlLobby "myLobby" explicitly
TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby);
lbClient.OpCreateRoom(roomName, roomOptions, sqlLobby);
入室:
TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby); // same as above
string sqlLobbyFilter = "C0 = 0"; // find a game with mode 0
lbClient.OpJoinRandomRoom(null, expectedMaxPlayers, matchmakingMode, sqlLobby, sqlLobbyFilter);
// more filter variations:
// "C0 = 1 AND C2 > 50"
// "C5 = \"Map2\" AND C2 > 10 AND C2 < 20"
在您的情况下,您只需要用被阻止的玩家列表替换C0,并在每次新用户玩游戏时更新此列表,并在30分钟后将其从列表中删除。
如果您还会遇到其他问题,请告诉我们。