网络大厅管理器



我正在使用unity3D开发一个多人在线应用程序,并且正在使用networkLobbyManager,我设法创建了一个比赛并允许玩家通过运行matchMaker.JoinMatch加入比赛,所以我在"大厅场景">中拥有所有玩家,但我不明白我们如何在"播放场景"中加入他们。(我发现只有当所有玩家都准备好时,我们才能移动到游戏场景,但我不明白我怎么能让他们都准备好(。我的代码 :

public InputField impF;
public InputField impF1;
public Dropdown d;
List<MatchInfoSnapshot> m;
MatchInfoSnapshot ma;
public int n = 1;
// Use this for initialization
public void enableMatch()
{
    Debug.Log("@ MMStart ");
    this.StartMatchMaker();
}
public override void OnStartHost()
{
    base.OnStartHost();
    Debug.Log("the game has created");
}
public void crereMatch()
{
    string nom = impF.text;
    Debug.Log(nom);
    MMCreateMateches(nom);
    n = 2;
}
public void findMtches()
{
    MMListMateches();
}
public void joinMatch()
{
    Debug.Log(d.options[d.value].text);
    foreach (var match in this.matches)
    {
        Debug.Log("dans la boucle des matches");
        Debug.Log(match.name);
        if ((d.options[d.value].text).Equals(match.name))
        {
            //on récupere 
            ma = match;
            Debug.Log("dans le if " + ma.name);
            break;
        }
    }
    // this.f
    m = this.matches;
    ma = m.Find(x => (x.name).Equals(ma.name));
    Debug.Log("apres recuperation de la liste" + ma.name);
    MMjoinMateches(ma);
}
void MMListMateches()
{
    Debug.Log("@ MMListMateches ");
    this.matchMaker.ListMatches(0, 20, "", true, 0, 0, OnMatchList);
}
public override void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList)
{
    Debug.Log("@ OnMatchList ");
    base.OnMatchList(success, extendedInfo, matchList);
    if (!success)
    {
        Debug.Log("liste failed " + extendedInfo);
    }
    else
    {
        if (matches.Count > 0)
        {  //les matches en cours > 0 ms on doit le joiner 
            Debug.Log("succesfully listed match 1 er match :" + matchList[0]);
            Debug.Log(matchList[0].name);
            foreach (var match in this.matches)
            {
                Debug.Log("dans la boucle");
                Debug.Log(match.name);
                Debug.Log(" wééééééééééééééééééé ");
            }
            d.ClearOptions();
            foreach (var match in this.matches)
            {
                Debug.Log(match.name);
                // impF1.text = match.name;
                List<string> m_DropOptions = new List<string> { match.name };
                d.AddOptions(m_DropOptions);
            }
            //   MMjoinMateches(matchList[0]);
        }
        else
        {
            Debug.Log("no mateches");
            // MMCreateMateches();
        }
    }
}
void MMjoinMateches(MatchInfoSnapshot firstMatch)
{
    Debug.Log("@ MMjoinMateches ");
    this.matchMaker.JoinMatch(firstMatch.networkId, "", "", "", 0, 0, OnMatchJoined);
}
public override void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfo)
{
    Debug.Log("@ OnMatchJoined ");
    base.OnMatchJoined(success, extendedInfo, matchInfo);
    if (!success)
    {
        Debug.Log("failed to join match " + extendedInfo);
        impF1.text = "failed";
    }
    else
    {
        Debug.Log("succesfuly joined match " + matchInfo.networkId);
        impF1.text = "succes";
        this.StartClient(matchInfo);
    }
}
void MMCreateMateches(string nom)
{
    Debug.Log("@ MMCreateMateches ");
    Debug.Log(nom);
    this.matchMaker.CreateMatch(nom, 15, true, "", "", "", 0, 0, OnMatchCreate);
}
public override void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
{
    Debug.Log("@ OnMatchCreate ");
    base.OnMatchCreate(success, extendedInfo, matchInfo);
    if (!success)
    {
        Debug.Log("failed to create match " + extendedInfo);
    }
    else
    {
        Debug.Log("succesfuly created match " + matchInfo.networkId);
        OnStartHost();
    }
}
public override void OnLobbyServerPlayersReady()
{
    base.OnLobbyServerPlayersReady();
}

观看 Holistic 3D 的本教程,了解如何设置 Unity Network Lobb y(在资源商店中免费(。 https://www.youtube.com/watch?v=jklWlm5v21k

在设置中,您可以确定进入房间所需的Max Players。您可以将其设置为"1",以便任何人都可以随时输入。

将最大玩家数从 4 更改为 1 请参阅链接

最新更新