示例#1
0
        /// <summary>
        /// Start Matchmaking
        /// </summary>
        /// <param name="playerId">The id of the player</param>
        /// <param name="playerProps">Custom player properties relevant to the matchmaking function</param>
        /// <param name="groupProps">Custom group properties relevant to the matchmaking function</param>
        public void RequestMatch(string playerId, MatchmakingPlayerProperties playerProps, MatchmakingGroupProperties groupProps)
        {
            request = CreateMatchmakingRequest(playerId, playerProps, groupProps);

            matchmakingController = new MatchmakingController(Endpoint);

            matchmakingController.StartRequestMatch(request, GetAssignment, OnError);
            State = MatchmakingState.Requesting;
            Debug.Log(State);
        }
示例#2
0
        /// <summary>
        /// Generates a matchmaking request from the custom player and group properties provided.
        /// </summary>
        /// <param name="playerId">The id of the player</param>
        /// <param name="playerProps">Custom player properties relevant to the matchmaking function</param>
        /// <param name="groupProps">Custom group properties relevant to the matchmaking function</param>
        /// <returns></returns>
        public static MatchmakingRequest CreateMatchmakingRequest(string playerId, MatchmakingPlayerProperties playerProps, MatchmakingGroupProperties groupProps)
        {
            MatchmakingRequest request    = new MatchmakingRequest();
            MatchmakingPlayer  thisPlayer = new MatchmakingPlayer(playerId);

            thisPlayer.Properties = JsonUtility.ToJson(playerProps);

            request.Players.Add(thisPlayer);
            request.Properties = JsonUtility.ToJson(groupProps);

            return(request);
        }
示例#3
0
        /// <summary>
        /// Start matchmaking
        /// </summary>
        /// <param name="request">The matchmaking request</param>
        /// <param name="successCallback">If a match is found, this callback will provide the connection information</param>
        /// <param name="errorCallback">If matchmaking fails, this callback will provided some failure information</param>
        public void RequestMatch(MatchmakingRequest request, SuccessCallback successCallback,
                                 ErrorCallback errorCallback)
        {
            m_Success          = successCallback;
            m_Error            = errorCallback;
            MatchmakingRequest = request;

            matchmakingController = new MatchmakingController(Endpoint);

            matchmakingController.StartRequestMatch(request, GetAssignment, OnError);
            State = MatchmakingState.Requesting;
            Debug.Log(State);
        }
示例#4
0
        /// <summary>
        /// Start matchmaking for a provided request. This tells your matchmaking endpoint to add
        /// the players and group data in the request to the matchmaking pool for consideration
        /// </summary>
        /// <param name="request">The matchmaking request</param>
        /// <returns>An asynchronous operation that can be used in various async flow patterns.
        /// The webrequest inside will contain a json success object</returns>
        /// TODO: Strongly type expect contract return from successful call
        internal UnityWebRequestAsyncOperation RequestMatchAsync(MatchmakingRequest request)
        {
            string          url        = Url + k_CreateRequestEndpoint;
            UnityWebRequest webRequest = new UnityWebRequest(url, "POST");

            webRequest.SetRequestHeader("Content-Type", "application/json");
            string txtRec = JsonUtility.ToJson(request);

            byte[] jsonToSend = new UTF8Encoding().GetBytes(txtRec);
            webRequest.uploadHandler   = new UploadHandlerRaw(jsonToSend);
            webRequest.downloadHandler = new DownloadHandlerBuffer();
            Debug.Log("Calling... " + url + " " + txtRec);
            return(webRequest.SendWebRequest());
        }
示例#5
0
        /// <summary>
        /// Generates a matchmaking request from the custom player and group properties provided.
        /// </summary>
        /// <param name="playerId">The id of the player</param>
        /// <param name="playerProps">Custom player properties relevant to the matchmaking function</param>
        /// <param name="groupProps">Custom group properties relevant to the matchmaking function</param>
        /// <returns></returns>
        private static MatchmakingRequest CreateMatchmakingRequest(string playerId, MatchmakingPlayerProperties playerProps, MatchmakingGroupProperties groupProps)
        {
            // TODO: WORKAROUND: Currently matchmaker handles IDs as UUIDs, not player names, and will only ever generate 1 match assignment for each UUID
            //   Therefore, we'll append the current time in Ticks as an attempt at creating a UUID
            playerId = playerId + DateTime.UtcNow.Ticks.ToString();

            MatchmakingPlayer thisPlayer = new MatchmakingPlayer(playerId)
            {
                Properties = JsonUtility.ToJson(playerProps)
            };

            MatchmakingRequest request = new MatchmakingRequest()
            {
                Properties = JsonUtility.ToJson(groupProps)
            };


            request.Players.Add(thisPlayer);

            return(request);
        }
 /// <summary>
 /// Start a matchmaking request call on the controller
 /// </summary>
 internal void StartRequestMatch(MatchmakingRequest request, RequestMatchSuccess successCallback, RequestMatchError errorCallback)
 {
     m_RequestMatchOperation = m_Client.RequestMatchAsync(request);
     m_RequestMatchSuccess   = successCallback;
     m_RequestMatchError     = errorCallback;
 }