GameType: Billiards (1 vs 1)
The Prototype Starts with the Menu Scene (Channel: 1 All Players AutoJoin here),
- If you press find then Match Making triggers...
- RFC is sent to all player in MM, the rating logic would be Applied to find the appropriate Player
- Then the 2 players would start a game channel to play the session
I wanted to ask if this right approach for matchmaking?
This is just so that i can setup a small base on matchmaking,
Please suggest, Thank you!
public void MatchMake()
{
StartCoroutine(MatchMaking());
matchMakebutton.SetActive(false);
matchMakingAnimate.SetActive(true);
}
void StopMatchMaking()
{
matchMakingAnimate.SetActive(false);
matchMakebutton.SetActive(true);
StopAllCoroutines();
}
IEnumerator MatchMaking()
{
Vector3 info;
info.x = TNManager.playerID;
info.y = 200;
info.z = 0;
tno.Send("RFC_MatchMake", Target.Others, info);
yield return new WaitForSeconds
(0
.5f
); StartCoroutine(MatchMaking());
}
/// <summary>
/// X is Player ID
/// Y is Rating
/// Z is Something..
/// </summary>
/// <param name="_MMR"></param>
[RFC]
void RFC_MatchMake(Vector3 _MMR)
{
if(matchMakingAnimate.activeInHierarchy)
{
matchedOpponent = _MMR;
if (matchedOpponent.y == 200) //Match Making Logic!
{
Debug.Log("Match Found!");
if (TNManager.playerID < matchedOpponent.x) //if My Player id is Less than the opponents ID.
{
StopAllCoroutines(); // Stop Match Making
HostGame(); //I will be the host!
}
}
}
}
public void HostGame()
{
TNManager.GetChannelList(_CallOnChannelList);
}
/// <summary>
/// Channels list
/// </summary>
void _CallOnChannelList(List<Channel.Info> chList)
{
int lastChannelID = chList[chList.size - 1].id + 1;
Vector3 info;
info.x = matchedOpponent.x;
info.y = lastChannelID;
info.z = 0;
tno.Send("RFC_JoinGame", Target.Others, info);
JoinChannel(lastChannelID);
}
void JoinChannel(int _channelID)
{
if(TNManager.GetChannel(_channelID).players.Count < 2)
{
TNManager.JoinChannel(_channelID, sceneName, true, 2, null);
}
else
{
Debug.LogError("Game has already Started");
}
}
/// <summary>
/// X is Player ID
/// Y is Channel ID
/// Z is Something
/// </summary>
/// <param name="_joinData"></param>
[RFC]
void RFC_JoinGame(Vector3 _joinData)
{
if(TNManager.playerID == (int)_joinData.x)
{
JoinChannel((int)_joinData.y);
}
}