当前位置: 首页>>代码示例>>C#>>正文


C# NetworkManager.StartHost方法代码示例

本文整理汇总了C#中NetworkManager.StartHost方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkManager.StartHost方法的具体用法?C# NetworkManager.StartHost怎么用?C# NetworkManager.StartHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkManager的用法示例。


在下文中一共展示了NetworkManager.StartHost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    void Start()
    {
        manager = GetComponent<NetworkManager>();
        manager.StartMatchMaker();
        matcher = manager.matchMaker;

        matcher.ListMatches(0, ListSize, "", (matches) => {
            if (matches.success) {
                if (matches.matches.Count > 0 && !OnlyHost) {
                    matcher.JoinMatch(matches.matches[0].networkId, "", (join) => {
                        if (join.success) {
                            Utility.SetAccessTokenForNetwork(join.networkId, new NetworkAccessToken(join.accessTokenString));
                            NetworkClient client = new NetworkClient();
                            client.RegisterHandler(MsgType.Connect, (connected) => {
                                Debug.Log("Connected");
                            });
                            client.Connect(new MatchInfo(join));
                            manager.StartClient();
                        } else {
                            Debug.LogError("Could not join match");
                        }
                    });
                } else {
                    matcher.CreateMatch(URandom.value.ToString(), PlayerCountPerRoom, Advertise, "", (created) => {
                        if (created.success) {
                            Debug.Log("Create match succeeded");
                            Utility.SetAccessTokenForNetwork(created.networkId, new NetworkAccessToken(created.accessTokenString));
                            NetworkServer.Listen(new MatchInfo(created), 9000);
                            manager.StartHost();
                            isHost = true;
                        } else {
                            Debug.LogError("Could not create match");
                        }
                    });
                }
            } else {
                Debug.LogError("Could not recieve list of matchces");
            }
        });
    }
开发者ID:stronklabs,项目名称:fastfast,代码行数:40,代码来源:Connector.cs

示例2: Start

    void Start()
    {
        // Find all UI Elements
        manager = GameObject.Find("Network Manager").GetComponent<NetworkManager>();
        hostGame = GameObject.Find("Host Game").GetComponent<Button>();
        joinGame = GameObject.Find("Join Game").GetComponent<Button>();
        exit = GameObject.Find("Exit").GetComponent<Button>();

        hostGame.onClick.AddListener(() =>
        {
            manager.StartHost();
        });

        joinGame.onClick.AddListener(() =>
        {
            manager.networkAddress = GameObject.Find("IP").GetComponent<InputField>().text;
            manager.StartClient();
        });

        exit.onClick.AddListener(() =>
        {
            Application.Quit();
        });
    }
开发者ID:BastiaanGrisel,项目名称:PrivacyAwarenessGame,代码行数:24,代码来源:LauncherGUI.cs

示例3: StartHost

 public void StartHost()
 {
     nm = NetworkManager.singleton;
     nm.StartHost();
     SendJoinMessage();
 }
开发者ID:Geor23,项目名称:Planets,代码行数:6,代码来源:StartSceneGUI.cs


注:本文中的NetworkManager.StartHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。