iOS 本机构建的 Unity Unet 多人游戏问题
Unity Unet Multiplayer issue with iOS native build
我创造了我如何团结一致的配对class。这一切在 PC 上都运行良好,并且可以轻松地创建匹配项而不会出现任何问题。当我尝试为 iOS.
创建匹配项时出现问题
当我尝试创建新匹配时,我在 Xcode 上遇到了这个错误:
ArgumentNullException: Argument cannot be null.
Parameter name: baseUri
at System.Uri.Merge (System.Uri baseUri, System.String relativeUri) [0x00000] in <filename unknown>:0
at UnityEngine.Networking.Match.NetworkMatch.ListMatches (UnityEngine.Networking.Match.ListMatchRequest req, UnityEngine.Networking.Match.ResponseDelegate`1 callback) [0x00000] in <filename unknown>:0
(Filename: currently not available on il2cpp Line: -1)
这是用于创建匹配的代码:
void Start()
{
networkMatch = gameObject.AddComponent<NetworkMatch>();
}
private void OnMatchCreate(CreateMatchResponse matchResponse)
{
if (matchResponse.success)
{
NetworkServer.ClearLocalObjects ();
NetworkServer.ClearSpawners ();
NetworkServer.SetAllClientsNotReady ();
Debug.Log("Create match succeeded");
matchCreated = true;
Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
NetworkServer.Listen(new MatchInfo(matchResponse), 9000);
UnityEngine.Networking.NetworkManager.singleton.StartServer(new MatchInfo(matchResponse));
}
else
{
Debug.LogError ("Create match failed");
}
}
这里有什么问题?
经过一番调查,我找到了解决这个问题的方法:
- 确保网络初始化发生在 Start 方法中
- 设置用于匹配的 mach URI。
最终代码:
void Start()
{
networkMatch = gameObject.AddComponent<NetworkMatch>();
networkMatch.baseUri = new System.Uri("https://mm.unet.unity3d.com/");
}
URL是Unity默认提供的URL
我创造了我如何团结一致的配对class。这一切在 PC 上都运行良好,并且可以轻松地创建匹配项而不会出现任何问题。当我尝试为 iOS.
创建匹配项时出现问题当我尝试创建新匹配时,我在 Xcode 上遇到了这个错误:
ArgumentNullException: Argument cannot be null.
Parameter name: baseUri
at System.Uri.Merge (System.Uri baseUri, System.String relativeUri) [0x00000] in <filename unknown>:0
at UnityEngine.Networking.Match.NetworkMatch.ListMatches (UnityEngine.Networking.Match.ListMatchRequest req, UnityEngine.Networking.Match.ResponseDelegate`1 callback) [0x00000] in <filename unknown>:0
(Filename: currently not available on il2cpp Line: -1)
这是用于创建匹配的代码:
void Start()
{
networkMatch = gameObject.AddComponent<NetworkMatch>();
}
private void OnMatchCreate(CreateMatchResponse matchResponse)
{
if (matchResponse.success)
{
NetworkServer.ClearLocalObjects ();
NetworkServer.ClearSpawners ();
NetworkServer.SetAllClientsNotReady ();
Debug.Log("Create match succeeded");
matchCreated = true;
Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
NetworkServer.Listen(new MatchInfo(matchResponse), 9000);
UnityEngine.Networking.NetworkManager.singleton.StartServer(new MatchInfo(matchResponse));
}
else
{
Debug.LogError ("Create match failed");
}
}
这里有什么问题?
经过一番调查,我找到了解决这个问题的方法:
- 确保网络初始化发生在 Start 方法中
- 设置用于匹配的 mach URI。
最终代码:
void Start()
{
networkMatch = gameObject.AddComponent<NetworkMatch>();
networkMatch.baseUri = new System.Uri("https://mm.unet.unity3d.com/");
}
URL是Unity默认提供的URL