本文介绍了Unity Networking-UNet中的附加场景加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短说明:我正在主场景中加载一个 Additive场景,它的加载方式很好,但是Additive场景的GameObject(包含 Network Identity 组件)被禁用.

Short Description: I am loading an Additive Scene in my Main scene, its loading fine but Additive scene's GameObject (that contain Network Identity Component) are becoming disable.

详细信息:我正在通过此代码加载加性场景,以便将加性场景加载到我的服务器和所有工作正常的客户端中:

Details:I am loading an additive scene through this code so that an additive scene become load into my server and all clients which working fine:

  [ClientRpc]
    public void RpcLoadLevelAcrossNetwork() {
        SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
    }

尽管它已将场景加载到客户端/服务器中,但是具有网络的对象身份被禁用(这是我检查Unity UNetSceneObjects 时的默认行为 strong> 其中指出:

Although it has loaded my scene into clients/server but the object that are with network identity are disable (It is default behavior as I checked Unity UNetSceneObjects which states that:

作为文档说明,它将自动激活网络标识对象,但在我的上下文中未发生.我的场景加载很好,但是其网络标识对象未处于活动状态.

As documentation state that it will automatically activate the Network Identity objects but it did not happen in my context. My scene loading is fine but its network identity objects are not active.

我做错了什么?

我还尝试通过调用 NetworkServer来激活自己的对象.SpawnObjects() 在我新加载的场景中,但是它只在服务器端生成对象,而在客户端显示错误

I also tried to activate the object my self through calling NetworkServer.SpawnObjects() in my new loaded scene but it only spawning the object on server side while showing the error at client

任何Unet冠军都能帮助我吗?

Can any Unet Champion help me?

编辑/更新方法:

我已经根据 社区论坛讨论 进行附加场景加载,其将我的附加场景加载到服务器上时出现错误(如下所示),仍然是我客户端的场景网络身份对象被禁用:

I have changed my code according to the unity forum discussion for additive scene loading, its loading my additive scene on server with error (given below) and still my client side's scene network identity objects are disabled:

错误:

另一个代码尝试:

 #region AdditiveSceneLoadingSetup

    [Command]//calling this for additive scene load- its start
    public void CmdLoadAdditiveSceneMainCall() {

        RpcLoadAdditiveScene();
        StartCoroutine(LoadAdditiveSceneAtServer());

    }

    [ClientRpc]
    public void RpcLoadAdditiveScene() {
        Debug.Log("RpcLoadAdditiveScene");
        StartCoroutine(LoadAdditiveSceneAtClient());
    }

    public IEnumerator LoadAdditiveSceneAtClient() {
        Debug.Log("LoadAdditiveSceneAtClient");
        yield return SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
        List<NetworkConnection> networkConnectionList = FindObjectOfType<MyNetworkManagerWithVR>().networkConnectionList;
        for (int i = 0; i < networkConnectionList.Count; i++)
        {
            ClientScene.Ready(networkConnectionList[i]);
        }
        //ClientScene.Ready(this.connectionToServer);//connectionToServer
    }

    public IEnumerator LoadAdditiveSceneAtServer() {
        Debug.Log("LoadAdditiveSceneAtServer");
        NetworkServer.SetAllClientsNotReady();
        yield return SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
        NetworkServer.SpawnObjects();
    }


    #endregion AdditiveSceneLoadingSetup

推荐答案

在这里晚了聚会,但是我也遇到了这个问题,并在这里提出了自己的解决方案:

Late to the party here, but I ran into this as well and came up with my own solution here:

https://gist.github.com/kristianpd/485fd7d78512a22a80117a2d22664185

问题的核心是SceneId在NetworkIdentity上重新使用,当您加载另一个场景时,它将与当前NetworkIdentity.sceneId冲突.

The core of the problem is that the SceneId's are re-used on NetworkIdentitys and when you load another scene, it will conflict with current NetworkIdentity.sceneIds.

有关该解决方案的更多背景信息,在此论坛帖子中,我将介绍在尝试此解决方案之前的几种不同尝试.

For a little more context on the solution, this forum post is where I walk through a few different attempts before coming to this solution.

https://forum.unity.com/threads/additive-scene-loading-with-unet-conflicting-sceneids-on-scene-objects.525410/#post-3545410

这篇关于Unity Networking-UNet中的附加场景加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 22:13