Exemplo n.º 1
0
        void LoadConfigScene()
        {
            // TODO: Emscripten seems to have problems loading statics so reading
            // from ConfigurationScene.Guid will pretty reliably come back as all zeros
            var configGuid = new Hash128("46b433b264c69cbd39f04ad2e5d12be8"); // ConfigurationScene.Guid;

            m_ConfigScene = m_SceneSystem.LoadSceneAsync(configGuid, new SceneSystem.LoadParameters()
            {
                AutoLoad = true, Flags = SceneLoadFlags.LoadAdditive
            });
            m_CatalogOp = IOService.RequestAsyncRead(SceneSystem.GetSceneInfoPath());
        }
Exemplo n.º 2
0
        private UnityInstance()
        {
            m_World = DefaultWorldInitialization.Initialize("Default World");

            m_BootPhase     = BootPhase.Booting;
            m_RunState      = RunState.Resuming;
            m_EntityManager = m_World.EntityManager;

            m_StartTimeInSeconds           = 0;
            m_ElapsedTimeInSeconds         = 0;
            m_PreviousElapsedTimeInSeconds = 0;

            m_SceneSystemGroup = m_World.GetOrCreateSystem <SceneSystemGroup>();
            m_SceneSystem      = m_World.GetOrCreateSystem <SceneSystem>();

            m_TimeData = (TimeData *)UnsafeUtility.Malloc(
                UnsafeUtility.SizeOf <TimeData>(),
                0,
                Collections.Allocator.Persistent);
        }
Exemplo n.º 3
0
        private UnityInstance()
        {
            m_World = DefaultWorldInitialization.Initialize("Default World");

            m_BootPhase     = BootPhase.Booting;
            m_RunState      = RunState.Resuming;
            m_EntityManager = m_World.EntityManager;

            m_StartTimeInSeconds           = 0;
            m_ElapsedTimeInSeconds         = 0;
            m_PreviousElapsedTimeInSeconds = 0;

            // try to find SceneSystemGroup in worlds
            foreach (var w in World.All)
            {
                m_SceneSystemGroup = w.GetExistingSystem <SceneSystemGroup>();
                m_SceneSystem      = w.GetExistingSystem <SceneSystem>();

                if (m_SceneSystemGroup != null)
                {
                    break;
                }
            }

            // if cannot find - create in the default world
            if (m_SceneSystemGroup == null)
            {
                m_SceneSystemGroup = m_World.GetOrCreateSystem <SceneSystemGroup>();
                m_SceneSystem      = m_World.GetOrCreateSystem <SceneSystem>();
            }

            m_TimeData = (TimeData *)UnsafeUtility.Malloc(
                UnsafeUtility.SizeOf <TimeData>(),
                0,
                Collections.Allocator.Persistent);
        }
Exemplo n.º 4
0
        protected override void OnCreate()
        {
#if UNITY_ANDROID
            var uwrFile = new UnityWebRequest(SceneSystem.GetBootStrapPath());
            uwrFile.SendWebRequest();
            while (!uwrFile.isDone)
            {
            }

            if (uwrFile.isNetworkError || uwrFile.isHttpError)
            {
                Enabled = false;
            }
            else
            {
                Enabled = true;
            }
#else
            var bootstrapFilePath = GetBootStrapPath();
            Enabled = File.Exists(bootstrapFilePath);
#endif
            if (Enabled)
            {
                if (!UnityEngine.Networking.PlayerConnection.PlayerConnection.instance.isConnected)
                {
                    Debug.LogError("Failed to connect to the Editor.\nAn Editor connection is required for LiveLink to work.");
                }

                using (var rdr = File.OpenText(bootstrapFilePath))
                {
                    var buildConfigurationGUID = new Hash128(rdr.ReadLine());
                    LiveLinkSessionId = long.Parse(rdr.ReadLine() ?? throw new Exception("Expected line in bootstrap containing session id!"));
                    World.GetOrCreateSystem <SceneSystem>().BuildConfigurationGUID = buildConfigurationGUID;
                }
            }
        }
Exemplo n.º 5
0
        private unsafe bool LoadStartupScenes()
        {
            if (m_StartupScenes.IsCreated)
            {
                return(true);
            }

            var status = m_CatalogOp.GetStatus();

            if (status <= AsyncOp.Status.InProgress)
            {
                return(false);
            }

            if (status == AsyncOp.Status.Failure)
            {
                var failureStatus = m_CatalogOp.GetErrorStatus();
                if (failureStatus == AsyncOp.ErrorStatus.FileNotFound)
                {
                    UnityEngine.Debug.LogWarning("Missing catalog file from '" + SceneSystem.GetSceneInfoPath() + "'");
                }
                else
                {
                    throw new ArgumentException("Failed to load catalog from '" + SceneSystem.GetSceneInfoPath() + "'. status=" + status + ", errorStatus=" + failureStatus);
                }

                // a missing catalog file is not fatal, as some runtimes don't use scene data
                return(true);
            }
            Assert.IsTrue(status == AsyncOp.Status.Success);

            m_CatalogOp.GetData(out var data, out var dataLen);

            if (!BlobAssetReference <ResourceCatalogData> .TryRead(data, ResourceCatalogData.CurrentFileFormatVersion, out var catalogData))
            {
                throw new ArgumentException("Unable to parse catalog data from " + SceneSystem.GetSceneInfoPath());
            }

            m_SceneSystem.SetCatalogData(catalogData);
            m_CatalogOp.Dispose();

            //if running in LiveLink mode, the initial scenes list is sent from the editor.  otherwise use the flags in the scene data.
            //if (!LiveLinkUtility.LiveLinkEnabled)
            {
                m_StartupScenes = new NativeList <Entity>(catalogData.Value.resources.Length, Allocator.Persistent);
                for (int i = 0; i < catalogData.Value.resources.Length; i++)
                {
                    if (catalogData.Value.resources[i].ResourceType == ResourceMetaData.Type.Scene &&
                        (catalogData.Value.resources[i].ResourceFlags & ResourceMetaData.Flags.AutoLoad) == ResourceMetaData.Flags.AutoLoad)
                    {
                        var sceneGuid = catalogData.Value.resources[i].ResourceId;
                        m_SceneSystem.LoadSceneAsync(sceneGuid, new SceneSystem.LoadParameters()
                        {
                            Flags = SceneLoadFlags.LoadAdditive
                        });
                        m_StartupScenes.Add(m_SceneSystem.GetSceneEntity(sceneGuid));
                    }
                }
            }

            return(true);
        }
Exemplo n.º 6
0
 protected override void OnCreate()
 {
     Enabled = File.Exists(SceneSystem.GetBootStrapPath());
 }
Exemplo n.º 7
0
        internal static void UnloadGameObjectScene(SceneSystem sys, Entity sceneEntity, SceneSystem.UnloadParameters unloadParams)
        {
            bool removeRequest                = (unloadParams & SceneSystem.UnloadParameters.DontRemoveRequestSceneLoaded) == 0;
            bool destroySceneProxyEntity      = (unloadParams & SceneSystem.UnloadParameters.DestroySceneProxyEntity) != 0;
            bool destroySectionProxyEntities  = (unloadParams & SceneSystem.UnloadParameters.DestroySectionProxyEntities) != 0;
            bool destroySubSceneProxyEntities = (unloadParams & SceneSystem.UnloadParameters.DestroySubSceneProxyEntities) != 0;

            if (destroySceneProxyEntity && !destroySectionProxyEntities)
            {
                throw new ArgumentException("When unloading a scene it's not possible to destroy the scene entity without also destroying the section entities. Please also add the UnloadParameters.DestroySectionProxyEntities flag");
            }

            if (sys.EntityManager.HasComponent <GameObjectSceneDependency>(sceneEntity))
            {
                var dependency = sys.EntityManager.GetComponentData <GameObjectSceneDependency>(sceneEntity);
                sys.EntityManager.DestroyEntity(dependency.Value);
                sys.EntityManager.RemoveComponent <GameObjectSceneDependency>(sceneEntity);
            }

            if (removeRequest)
            {
                sys.EntityManager.RemoveComponent <RequestGameObjectSceneLoaded>(sceneEntity);
                sys.EntityManager.RemoveComponent <RequestSceneLoaded>(sceneEntity);
            }

            if (sys.EntityManager.HasComponent <GameObjectSceneSubScene>(sceneEntity))
            {
                var gameObjectSceneSubScenes = sys.EntityManager.GetBuffer <GameObjectSceneSubScene>(sceneEntity).ToNativeArray(Allocator.Temp);
                for (int i = gameObjectSceneSubScenes.Length - 1; i >= 0; i--)
                {
                    var subScene = gameObjectSceneSubScenes[i];

                    // Prune destroy Scene Entities
                    if (!sys.EntityManager.Exists(subScene.SceneEntity))
                    {
                        var buf = sys.EntityManager.GetBuffer <GameObjectSceneSubScene>(sceneEntity);
                        buf.RemoveAt(i);
                        continue;
                    }

                    var subSceneUnloadParams = unloadParams;

                    if (destroySubSceneProxyEntities)
                    {
                        subSceneUnloadParams |= SceneSystem.UnloadParameters.DestroySceneProxyEntity;
                    }

                    sys.UnloadScene(subScene.SceneEntity, subSceneUnloadParams);
                }
                gameObjectSceneSubScenes.Dispose();

                if (destroySubSceneProxyEntities)
                {
                    sys.EntityManager.RemoveComponent <GameObjectSceneSubScene>(sceneEntity);
                }
            }

            sys.EntityManager.RemoveComponent <GameObjectSceneData>(sceneEntity);

            if (destroySceneProxyEntity)
            {
                sys.EntityManager.DestroyEntity(sceneEntity);
            }
        }
Exemplo n.º 8
0
        internal static void FinalizeGameObjectSceneEntity(EntityManager entityManager, Entity sceneEntity, Scene gameObjectScene, SceneSystem sceneSystem)
        {
            // Create handle for ref counting
            unsafe
            {
                var gameObjectSceneReference = new GameObjectSceneData
                {
                    Scene = gameObjectScene,
                    gameObjectSceneHandle = GameObjectSceneRefCount.CreateOrRetainScene(gameObjectScene),
                };

                entityManager.AddSharedComponentData(sceneEntity, gameObjectSceneReference);
            }

            #if UNITY_EDITOR
            entityManager.SetName(sceneEntity, $"GameObject Scene: {gameObjectScene.name}");
            #endif

            var subSceneDataEnum = GetSubScenes(gameObjectScene);
            entityManager.AddBuffer <GameObjectSceneSubScene>(sceneEntity);

            while (subSceneDataEnum.MoveNext())
            {
                var subSceneData           = subSceneDataEnum.Current;
                var subSceneLoadParameters = new SceneSystem.LoadParameters {
                    AutoLoad = subSceneData.AutoLoad
                };
                var subSceneEntity = sceneSystem.GetSceneEntity(subSceneData.SceneGUID);
                if (subSceneEntity == Entity.Null)
                {
                    subSceneEntity = sceneSystem.LoadSceneAsync(subSceneData.SceneGUID, subSceneLoadParameters);
                }

                var subSceneBuffer = entityManager.GetBuffer <GameObjectSceneSubScene>(sceneEntity);
                subSceneBuffer.Add(new GameObjectSceneSubScene
                {
                    SceneEntity = subSceneEntity,
                });
            }
        }