ランクマッチ
using
SoftGear.Strix.Client.Core.Model.Manager.Filter;
using SoftGear.Strix.Unity.Runtime;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class RankMatch : MonoBehaviour
{
// ルームに参加可能な最大人数
public int Capacity = 4;
// ルーム名
public string RoomName = "New Room";
// サーバーに接続
public void EnterRoom()
{
SearchJoinableRoom();
}
/// <summary>
/// 参加可能ルーム検索処理
/// </summary>
public void SearchJoinableRoom()
{
// 参加可能なルームを検索する
StrixNetwork.instance.SearchJoinableRoom(
// レベルが24以上28以下のルームを探す
new And(
new List<ICondition>()
{
new GreaterThanEquals(new Field("key1"),new Value((double)24)) ,
new LessThanEquals(new Field("key1"), new Value((double)28))
}
),
// レベルが低い順に並び変える
new Order("key1", OrderType.Ascending) { }
, 10, 0,
//検索に成功
args =>
{
// 条件に当てはまるルームが0件
if (args.roomInfoCollection.Count == 0)
{
// 新規でルームを作成する
CreateRoom();
}
// 条件に当てはまった場合
else
{
// 一番最初に当てはまるルームを取得する
RoomInfo room = args.roomInfoCollection.FirstOrDefault();
// 取得したルームに参加する
JoinRoom(room);
}
},
//
検索に失敗
args =>
{
Debug.Log($"ルームの検索に失敗しました。: {args.cause}");
// 新規でルームを作成する
CreateRoom();
});
}
/// <summary>
/// ルームへ参加
/// </summary>
/// <param name="info"></param>
private void JoinRoom(RoomInfo info)
{
// メンバープロパティを作成
RoomMemberProperties
roomMemberProperties = new RoomMemberProperties()
{
name = "PlayerName",
};
// ルーム参加情報
RoomJoinArgs
roomJoinArgs = new RoomJoinArgs()
{
host = info.host,
port = info.port,
protocol = info.protocol,
roomId = info.roomId,
memberProperties = roomMemberProperties,
};
StrixNetwork.instance.JoinRoom(roomJoinArgs,
args =>
{
Debug.Log("ルームに参加しました。");
},
failueArgs =>
{
Debug.Log($"ルームへの参加に失敗しました。 :{failueArgs.cause}");
});
}
/// <summary>
/// ルーム作成処理
/// </summary>
private void CreateRoom()
{
// ルームを作成
RoomProperties
roomProperties = new RoomProperties()
{
name = RoomName,
capacity = Capacity,
key1 = 25,
};
// メンバープロパティを作成
RoomMemberProperties
roomMemberProperties = new RoomMemberProperties()
{
name = "PlayerName",
};
// ルームへの入室処理
StrixNetwork.instance.CreateRoom(roomProperties,
roomMemberProperties,
args =>
{
Debug.Log("ルームを作成しました。");
},
args =>
{
Debug.Log($"ルームの作成に失敗しました。: {args.cause}");
});
}
}
上記のスクリプトを作った後 「StrixConnectUI」の中の「StrixConnectPanel」のInspectorの
StrixConnectGUIのOn Connectを上記のスクリプトのEnterRoomにします

これでランクマッチが可能です
戻
る