API

CBSMatchmakingModule.OnStatusChanged - Notifies about status change in Matchmaking

using CBS;
using CBS.Models;
using UnityEngine;

public class MatchmakingExample : MonoBehaviour
{
    private IMatchmaking Matchmaking { get; set; }

    private void Start()
    {
        Matchmaking = CBSModule.Get<CBSMatchmakingModule>();

        Matchmaking.OnStatusChanged += OnStatusChanged;
    }

    private void OnDestroy()
    {
        Matchmaking.OnStatusChanged -= OnStatusChanged;
    }

    private void OnStatusChanged(MatchmakingStatus status)
    {
        Debug.Log("Status of ticket was changed to " + status);
    }
}

CBSMatchmakingModule.OnMatchStart - Notifies about the successful completion of the search for opponents.

using CBS;
using CBS.Models;
using UnityEngine;

public class MatchmakingExample : MonoBehaviour
{
    private IMatchmaking Matchmaking { get; set; }

    private void Start()
    {
        Matchmaking = CBSModule.Get<CBSMatchmakingModule>();

        Matchmaking.OnMatchStart += OnMatchStart;
    }

    private void OnDestroy()
    {
        Matchmaking.OnMatchStart -= OnMatchStart;
    }

    private void OnMatchStart(CBSStartMatchResult result)
    {
        var players = result.Players;
        var queueName = result.QueueName;
        var ticketID = result.TicketID;
        var matchID = result.MatchID;
    }
}

CBSMatchmakingModule.GetMatchmakingQueuesList - Get a list of all Queues on the server

using CBS;
using CBS.Models;
using UnityEngine;

public class MatchmakingExample : MonoBehaviour
{
    private IMatchmaking Matchmaking { get; set; }

    private void Start()
    {
        Matchmaking = CBSModule.Get<CBSMatchmakingModule>();

        Matchmaking.GetMatchmakingQueuesList(OnGetQueueList);
    }

    private void OnGetQueueList(CBSGetMatchmakingListResult result)
    {
        if (result.IsSuccess)
        {
            var queueList = result.Queues;
            foreach (var queue in queueList)
            {
                var queueName = queue.QueueName;
                var playerCount = queue.PlayersCount;
                var queueMode = queue.Mode;
            }
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSMatchmakingModule.GetMatchmakingQueue - Get a detailed description of the queue by name.

using CBS;
using CBS.Models;
using UnityEngine;

public class MatchmakingExample : MonoBehaviour
{
    private IMatchmaking Matchmaking { get; set; }

    private void Start()
    {
        Matchmaking = CBSModule.Get<CBSMatchmakingModule>();

        var queueName = "Your queue name";

        Matchmaking.GetMatchmakingQueue(queueName, OnGetQueue);
    }

    private void OnGetQueue(CBSGetQueueResult result)
    {
        if (result.IsSuccess)
        {
            var queue = result.Queue;

            var queueName = queue.QueueName;
            var playerCount = queue.PlayersCount;
            var queueMode = queue.Mode;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSMatchmakingModule.FindMatch - Creates a ticket to find opponents. After a successful call, listen for a change in the status of the queue.

using CBS;
using CBS.Models;
using UnityEngine;

public class MatchmakingExample : MonoBehaviour
{
    private IMatchmaking Matchmaking { get; set; }

    private void Start()
    {
        Matchmaking = CBSModule.Get<CBSMatchmakingModule>();

        var queueName = "Your queue name";

        var findRequest = new CBSFindMatchRequest
        {
            QueueName = queueName
        };

        Matchmaking.FindMatch(findRequest, OnStartFindMatch);
    }

    private void OnStartFindMatch(CBSFindMatchResult result)
    {
        if (result.IsSuccess)
        {
            Debug.Log("Start search opponent with ticket id " + result.TicketID);
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSMatchmakingModule.CancelMatch - Cancels all search tickets for the current player.

using CBS;
using CBS.Models;
using UnityEngine;

public class MatchmakingExample : MonoBehaviour
{
    private IMatchmaking Matchmaking { get; set; }

    private void Start()
    {
        Matchmaking = CBSModule.Get<CBSMatchmakingModule>();

        var queueName = "Your queue name";

        Matchmaking.CancelMatch(queueName, OnCancelSearch);
    }

    private void OnCancelSearch(CBSBaseResult result)
    {
        if (result.IsSuccess)
        {
            Debug.Log("Cancel search opponent");
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

CBSMatchmakingModule.GetMatch - Get detail information about match

using CBS;
using CBS.Models;
using UnityEngine;

public class MatchmakingExample : MonoBehaviour
{
    private IMatchmaking Matchmaking { get; set; }

    private void Start()
    {
        Matchmaking = CBSModule.Get<CBSMatchmakingModule>();

        var queueName = "Your queue name";
        var matchID = "Your match id";

        Matchmaking.GetMatch(queueName, matchID, OnCancelSearch);
    }

    private void OnCancelSearch(CBSGetMatchResult result)
    {
        if (result.IsSuccess)
        {
            var arrangementString = result.ArrangementString;
            var matchID = result.MatchId;
            var members = result.Members;
            var regionPreferences = result.RegionPreferences;
            var serverDetails = result.ServerDetails;
        }
        else
        {
            Debug.Log(result.Error.Message);
        }
    }
}

Last updated