MatchMaker mm =newMatchMaker();// MatchMaker will use the profiles in the order of the list until it finds results.List<string> profileIDs =newList<string>();profileIDs.Add(mm.MatchmakingProfileID);// Search condition propertiesDictionary<string,uint> props =newDictionary<string,uint>();props.Add("lvl", (uint)10);props.Add("league", (uint)2);// If autoJoin is true, you will automatically join one of the matched matchmakings immediately.bool autoJoin =true;// Number of match results you ask for.ushort resultNum =10;byte[] joinedMessage =Encoding.UTF8.GetBytes("This message will be sent to the other matched user clients.");// Start the searchmm.Search(profileIDs, props, autoJoin, resultNum, joinedMessage);
検索のレスポンスを受け取る
mm.OnJoinResponse+= (bool success,string[] memberIDs,byte[] payload) =>{ // success will be true, if the search and auto-join was successful. // memberIDs contains the list of matched and joined user client IDs that you just joined.};
他のユーザーがマッチした際にサーバからの通知を受け取る
mm.OnMemberJoin+= (byte[] joinMessage) => {};
マッチメイキングを検索して結果一覧を受け取り、手動で参加する
検索したマッチメイキングの結果をサーバから取得して任意のものに手動で参加することも可能です。
MatchMaker mm =newMatchMaker();// MatchMaker will use the profiles in the order of the list until it finds results.List<string> profileIDs =newList<string>();profileIDs.Add(mm.MatchmakingProfileID);// Search condition propertiesDictionary<string,uint> props =newDictionary<string,uint>();props.Add("lvl", (uint)10);props.Add("league", (uint)2);bool autoJoin =false;ushort resultNum =10;byte[] joinedMessage =Encoding.UTF8.GetBytes("This message will be sent to the other matched user clients.");// Start the searchmm.Search(profileIDs, props, autoJoin, resultNum, joinedMessage);
検索結果を取得して、手動でマッチメイキングに参加する
mm.OnResults+= (bool success,MatchMaker.ResultItem[] results,byte[] payload) =>{ // success will be true, if the search was successful. // Results contain the list of matched matchmaking results.if (results.Length==0) { // no matchmakings foundreturn; }byte[] joinedMessage =Encoding.UTF8.GetBytes("This message will be sent to the other matched user clients."); // For this example, we will chose the first result item and try to join itmm.JoinMatchmakingFromResult(results[0], joinMessage);};
参加処理のレスポンスを受け取る
mm.OnJoinResponse+= (bool success,string[] memberIDs,byte[] payload) =>{ // success will be true, if the search and auto-join was successful. // memberIDs contains the list of matched and joined user client IDs that you just joined.};
他のユーザーが参加した際に通知をつけとる
mm.OnMemberJoin+= (byte[] joinMessage) => {};
参加しているマッチメイキングから離脱する
byte[] leaveMessage =Encoding.UTF8.GetBytes("This message will be send to other matched user clients.");mm.LeaveMatchmaking(leaveMessage);
離脱処理のレスポンスを受け取る
mm.OnLeaveResponse+= (bool success,byte[] payload) =>{ // If success is true, you have successfully left the current matchmaking.};
mm.OnDisbandMatchmaking+= (byte[] message) =>{ // message is a custom message byte array that the host decides to send when disbanding the matchmaking.};
mm.OnP2PAddressSync+= (byte) => { // The list of all matched and joined user clients' client addresses. // The format of the address string is "0.0.0.0:8888".};