Exemplo n.º 1
0
        void AddSceneEntities()
        {
            Assert.IsTrue(_AddedSceneGUID == default);
            Assert.IsFalse(_SceneGUID == default);

            var flags = AutoLoadScene ? 0 : SceneLoadFlags.DisableAutoLoad;

#if UNITY_EDITOR
            flags |= EditorApplication.isPlaying ? SceneLoadFlags.BlockOnImport : 0;
#else
            flags |= SceneLoadFlags.BlockOnImport;
#endif
            foreach (var world in World.All)
            {
                var sceneSystem = world.GetExistingSystem <SceneSystem>();
                if (sceneSystem != null)
                {
                    var loadParams = new SceneSystem.LoadParameters
                    {
                        Flags = flags
                    };

                    var sceneEntity = sceneSystem.LoadSceneAsync(_SceneGUID, loadParams);
                    sceneSystem.EntityManager.AddComponentObject(sceneEntity, this);
                    _AddedSceneGUID = _SceneGUID;
                }
            }
        }
Exemplo n.º 2
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,
                });
            }
        }
Exemplo n.º 3
0
        internal static void LoadGameObjectSceneAsync(SceneSystem sys, Entity sceneEntity, SceneSystem.LoadParameters parameters)
        {
            var requestSceneLoaded = new RequestSceneLoaded {
                LoadFlags = parameters.Flags
            };

            sys.EntityManager.AddComponentData(sceneEntity, requestSceneLoaded);

            if ((parameters.Flags & SceneLoadFlags.LoadAdditive) == SceneLoadFlags.LoadAdditive)
            {
                Debug.LogWarning("Deprecation Warning - SceneLoadFlags.LoadAdditive is deprecated. Scenes loaded through the SceneSystem are always loaded Additively. (RemovedAfter 2021-02-05)");
            }

            var loadSceneParameters = new LoadSceneParameters(LoadSceneMode.Additive);
            var activeOnLoad        = (parameters.Flags & SceneLoadFlags.DisableAutoLoad) != SceneLoadFlags.DisableAutoLoad;

            var sceneLoadRequest = new RequestGameObjectSceneLoaded
            {
                loadParameters = loadSceneParameters,
                activateOnLoad = activeOnLoad,
                priority       = parameters.Priority
            };

            sys.EntityManager.AddComponentData(sceneEntity, sceneLoadRequest);
        }
Exemplo n.º 4
0
        internal static Entity LoadGameObjectSceneAsync(SceneSystem sys, Hash128 sceneGUID, SceneSystem.LoadParameters parameters)
        {
            var sceneEntity = CreateGameObjectSceneEntity(sys, sceneGUID);

            LoadGameObjectSceneAsync(sys, sceneEntity, parameters);
            return(sceneEntity);
        }