コード例 #1
0
ファイル: NetworkSceneManager.cs プロジェクト: Lynx32/MLAPI
        private static void OnSceneUnload(AsyncOperation operation, Guid switchSceneGuid)
        {
            if (NetworkingManager.singleton.isServer)
            {
                SpawnManager.MarkSceneObjects();
                NetworkedObject[] networkedObjects = MonoBehaviour.FindObjectsOfType <NetworkedObject>();
                for (int i = 0; i < networkedObjects.Length; i++)
                {
                    if (!networkedObjects[i].isSpawned && networkedObjects[i].destroyWithScene == true)
                    {
                        networkedObjects[i].Spawn(null, true);
                    }
                }
            }
            else
            {
                SpawnManager.SpawnPendingObjectsForScene(CurrentActiveSceneIndex);

                NetworkedObject[] netObjects = MonoBehaviour.FindObjectsOfType <NetworkedObject>();
                for (int i = 0; i < netObjects.Length; i++)
                {
                    if (netObjects[i].destroyWithScene == null)
                    {
                        MonoBehaviour.Destroy(netObjects[i].gameObject);
                    }
                }
            }

            //Tell server that scene load is completed
            if (NetworkingManager.singleton.isHost)
            {
                OnClientSwitchSceneCompleted(NetworkingManager.singleton.LocalClientId, switchSceneGuid);
            }
            else if (NetworkingManager.singleton.isClient)
            {
                using (PooledBitStream stream = PooledBitStream.Get())
                {
                    using (PooledBitWriter writer = PooledBitWriter.Get(stream))
                    {
                        writer.WriteByteArray(switchSceneGuid.ToByteArray());
                        InternalMessageHandler.Send(NetworkingManager.singleton.ServerClientId, MLAPIConstants.MLAPI_CLIENT_SWITCH_SCENE_COMPLETED, "MLAPI_INTERNAL", stream, SecuritySendFlags.None);
                    }
                }
            }

            isSwitching = false;
        }
コード例 #2
0
        private static void OnSceneUnload(AsyncOperation operation)
        {
            isSwitching = false;
            if (NetworkingManager.singleton.isServer)
            {
                SpawnManager.MarkSceneObjects();

                NetworkedObject[] networkedObjects = MonoBehaviour.FindObjectsOfType <NetworkedObject>();
                for (int i = 0; i < networkedObjects.Length; i++)
                {
                    if (!networkedObjects[i].isSpawned && (networkedObjects[i].sceneObject == null || networkedObjects[i].sceneObject == true))
                    {
                        networkedObjects[i].Spawn();
                    }
                }

                //SpawnManager.FlushSceneObjects();
            }
            else
            {
                SpawnManager.DestroySceneObjects();
            }
        }