本文整理汇总了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");
}
});
}
示例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();
});
}
示例3: StartHost
public void StartHost()
{
nm = NetworkManager.singleton;
nm.StartHost();
SendJoinMessage();
}