/// <summary> /// Finds lobbies based on given parameters using Epic Online Services. /// <para>You can get the found lobbies by subscribing to the <see cref="FindLobbiesSucceeded"/> event which gives you a list of <see cref="LobbyDetails"/>.</para> /// <para>This process may throw errors. You can get errors by subscribing to the <see cref="FindLobbiesFailed"/> event.</para> /// </summary> /// <param name="maxResults">The maximum amount of results to return.</param> /// <param name="lobbySearchSetParameterOptions">The parameters to search by. If left empty, then the search will use the default attribute attached to all the lobbies.</param> public virtual void FindLobbies(uint maxResults = 100, LobbySearchSetParameterOptions[] lobbySearchSetParameterOptions = null) { //create search handle and list of lobby details LobbySearch search = new LobbySearch(); //set the search handle EOSSDKComponent.GetLobbyInterface().CreateLobbySearch(new CreateLobbySearchOptions { MaxResults = maxResults }, out search); //set search parameters if (lobbySearchSetParameterOptions != null) { foreach (LobbySearchSetParameterOptions searchOption in lobbySearchSetParameterOptions) { search.SetParameter(searchOption); } } else { search.SetParameter(new LobbySearchSetParameterOptions { ComparisonOp = ComparisonOp.Equal, Parameter = new AttributeData { Key = DefaultAttributeKey, Value = DefaultAttributeKey } }); } //find lobbies search.Find(new LobbySearchFindOptions { LocalUserId = EOSSDKComponent.LocalUserProductId }, null, (LobbySearchFindCallbackInfo callback) => { //if the search was unsuccessful, invoke an error event and return if (callback.ResultCode != Result.Success) { FindLobbiesFailed?.Invoke("There was an error while finding lobbies. Error: " + callback.ResultCode); return; } foundLobbies.Clear(); //for each lobby found, add data to details for (int i = 0; i < search.GetSearchResultCount(new LobbySearchGetSearchResultCountOptions { }); i++) { LobbyDetails lobbyInformation; search.CopySearchResultByIndex(new LobbySearchCopySearchResultByIndexOptions { LobbyIndex = (uint)i }, out lobbyInformation); foundLobbies.Add(lobbyInformation); } //invoke event FindLobbiesSucceeded?.Invoke(foundLobbies); }); }
/// <summary> /// Short GetSearchResultCount /// </summary> /// <param name="search">LobbySearch</param> /// <param name="localUserId">Login user id</param> public static LobbyDetails CopySearchResultByIndex(this LobbySearch search, uint lobbyIndex) { var resOp = new LobbySearchCopySearchResultByIndexOptions { LobbyIndex = lobbyIndex }; var result = search.CopySearchResultByIndex(resOp, out LobbyDetails detail); if (result == Result.Success) { return(detail); } Debug.LogError($"error {DebugTools.GetClassMethodName()}:{result}"); return(null); }