2017-01-28 20 views
12

簡述:我在我的主場景加載添加劑的場景,它的加載罰款,但添加劑場景的遊戲對象(包含網絡身份分量)成爲禁用添加劑場景加載在統一網絡-UNET

詳情: 我加載添加劑的場景,通過這個代碼,這樣的添加劑的場景成爲加載到我的服務器和所有客戶端,其做工精細:

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

雖然已經載入我的場景到客戶這與network identity是禁用/服務器,但對象(這是默認的行爲,我檢查統一UNetSceneObjects其中指出:

All objects in the scene with a NetworkIdentity component will be disabled when the scene is loaded; on both the client and the server. Then, when the scene is fully loaded, NetworkServer.SpawnObjects() is called to activate these networked scene objects. This will be done automatically by the NetworkManager when the server scene finishes loading - or can be called directly by user code.

由於文檔狀態,它會自動激活網絡身份對象,但它沒有發生在我的上下文中。我的場景加載沒問題,但其網絡標識對象不活動。

我做錯了什麼?

我也試圖通過調用我的新加載的場景NetworkServer.SpawnObjects()激活對象我的自我,但只產卵對象在服務器端,同時顯示在客戶

Spawn scene object not found for 1 Spawn scene object not found for 2 Spawn scene object not found for 3..... . . .

可以在任何UNET冠軍幫助錯誤我?

編輯/更新方法:

我已經根據unity forum discussion的添加劑場景加載改變了我的代碼,它裝載我添加劑的場景在服務器錯誤(如下),而我的客戶端的現場網絡身份對象已被禁用:

錯誤:

Ready() called with invalid connection object: conn=null

另一個代碼嘗試:

#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 
+0

我不知道unity3d或其他你正在使用的東西,但'SceneManager.LoadSceneAsync'看起來對我來說很可疑。你不應該以某種方式使用返回的'AsyncOperation'來確定加載結果嗎? – grek40

+0

@ grek40我想這條線沒有問題,它完美地加載了場景。 –

+0

不夠公平,所以包含在你的問題中的唯一代碼就是3線程,你可以確信它不是問題。如上所述,我不能評論技術細節,只能確保基本沒有錯。那麼你如何將'AsyncOperation'存儲在某個地方,以確保它的'isDone'屬性是在你認爲是的時候真正設置的。 – grek40

回答

0

你有沒有解決過這個問題?

我的猜測是,您需要等待所有的客戶端在調用SpawnObjects之前準備好(場景加載完成)。

+0

謝謝你commens,但這不是正確的地方:)。我還沒有解決這個問題。仍然願意其解決方案。是的,我試過這個,你檢查我的代碼嗎? –