Exemple #1
0
    /// <summary>
    /// Creates a matchmaking request given a player ID and serializable classes containing player properties and group properties.
    /// </summary>
    /// <param name="playerId">Unique ID of the player</param>
    /// <param name="playerProps">Class containing player properties; must be serializable to JSON</param>
    /// <param name="groupProps">Class containing group (non-player) properties; must be serializable to JSON</param>
    /// /// <returns>A properly-formed matchmaking request object that can be used in calls to the matchmaking API</returns>
    public static MatchmakingRequest CreateMatchmakingRequest(string playerId, PlayerProperties playerProps, GroupProperties groupProps)
    {
        if (string.IsNullOrEmpty(playerId))
        {
            throw new ArgumentException($"{nameof(playerId)} must be a non-null, non-0-length string", nameof(playerId));
        }

        if (playerProps == null || !playerProps.GetType().IsSerializable)
        {
            throw new ArgumentException($"{nameof(playerProps)} must be a non-null, serializable class or struct", nameof(playerProps));
        }

        if (groupProps == null || !groupProps.GetType().IsSerializable)
        {
            throw new ArgumentException($"{nameof(groupProps)} must be a non-null, serializable class or struct", nameof(groupProps));
        }

        var playerProperties = JsonUtility.ToJson(playerProps);
        var groupProperties  = JsonUtility.ToJson(groupProps);

        return(CreateMatchmakingRequest(playerId, playerProperties, groupProperties));
    }