ios - iOS 原生构建的 Unity Unet 多人游戏问题

标签 ios xcode unity-game-engine unity3d-unet

我创建了我的如何统一匹配类(class)。这一切在电脑上运行良好,我可以轻松地创建一场比赛,没有任何问题。当我尝试为 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

关于ios - iOS 原生构建的 Unity Unet 多人游戏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38008415/

相关文章:

c# - Unity 中初始跳转后 "isGrounded"变量不会更改为 false

ios - iOS 设备可以与 BT 设备通信吗?

ios - 尽管受到限制,为什么导航栏顶部和安全区域顶部之间仍然存在空间?

iphone - UICollectionView 的补充 View 或装饰 View 的索引路径是什么?

c++ - 为 Arduino 开发的 Xcode

xcode - 当您有多个目标时,如何将文件添加到 Xcode 中的所有目标?

iphone - 如何使 UIViewController 背景看起来像分组 UITableView 的背景?

ios - 只有 10 个 CustomViewCells 是正确的

javascript - 我一直收到 array.Select 的错误

ios - 在 C 包装器中获取 Objective-C 值(Unity 插件)