StrixNetworkSearchRoom Method (ICondition, Order, Int32, Int32, RoomSearchEventHandler, FailureEventHandler, RequestConfig) |
Starts an asynchronous ordered search for match rooms that meet the given criteria.
After search is complete handler callback is invoked with a list of found rooms.
Namespace:
SoftGear.Strix.Unity.Runtime
Assembly:
StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
Syntax public void SearchRoom(
ICondition condition,
Order order,
int limit,
int offset,
RoomSearchEventHandler handler,
FailureEventHandler failureHandler,
RequestConfig config = null
)
Parameters
- condition
- Type: SoftGear.Strix.Client.Core.Model.Manager.FilterICondition
Search request criteria. See ICondition. - order
- Type: SoftGear.Strix.Client.Core.Model.Manager.FilterOrder
Allows you to sort the search results in ascending or descending order. The ordering is applied before limit and offset. - limit
- Type: SystemInt32
Limits the number of search results. This value must be greater than 0. - offset
- Type: SystemInt32
The starting offset in the search results, e.g. if limit is set to 10, and offset is set to 15, the search will result in rooms 15 to 25. - handler
- Type: SoftGear.Strix.Unity.Runtime.EventRoomSearchEventHandler
This callback is invoked when the room search completes. - failureHandler
- Type: SoftGear.Strix.Unity.Runtime.EventFailureEventHandler
This callback is invoked in case of a failure. - config (Optional)
- Type: SoftGear.Strix.Client.Core.RequestRequestConfig
If not null, used to configure the request timeout. Default timeout is 30 seconds. See RequestConfig for more details.
Exceptions Remarks
To use this method you have to connect to the master server at least once.
If disconnected, calling this method will reconnect to the master server with the last used host and port parameters.
Possible exception types in FailureEventArgs's cause:Examples Note: Make sure to change the placeholder values of
applicationId and
host to the real ones that can be found on the
Strix Cloud application information tab.
using SoftGear.Strix.Client.Core.Model.Manager.Filter.Builder;
using SoftGear.Strix.Unity.Runtime;
using UnityEngine;
public class StrixSearchRoomExample : MonoBehaviour
{
void Start()
{
var strixNetwork = StrixNetwork.instance;
strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
strixNetwork.ConnectMasterServer(
host: "0123456789abcdef01234567.game.strixcloud.net",
connectEventHandler: _ => {
Debug.Log("Connection established.");
strixNetwork.CreateRoom(
new RoomProperties { name = "My Game Room" },
new RoomMemberProperties { name = "My Player Name" },
handler: __ => {
Debug.Log("Room created.");
strixNetwork.SearchRoom(
condition: ConditionBuilder.Builder().Field("name").EqualTo("My Game Room").Build(),
order: new Order("memberCount", OrderType.Ascending),
limit: 10,
offset: 0,
handler: searchResults => {
Debug.Log(searchResults.roomInfoCollection.Count + " rooms found.");
foreach (var roomInfo in searchResults.roomInfoCollection)
Debug.Log("Room ID: " + roomInfo.id
+ "\nHost: " + roomInfo.host
+ "\nMember count: " + roomInfo.memberCount
+ "\nCapacity: " + roomInfo.capacity
);
},
failureHandler: searchError => Debug.LogError("Search failed. Reason: " + searchError.cause)
);
},
failureHandler: createRoomError => Debug.LogError("Could not create room. Reason: " + createRoomError.cause)
);
},
errorEventHandler: connectError => Debug.LogError("Connection failed. Reason: " + connectError.cause)
);
}
}
See Also