Example #1
0
        public void OnEnable()
        {
            Debug.Log("DefaultWorldInitializationVerificationScript.OnEnable");
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();

            WasEnabled = true;
        }
        void OnEnable()
        {
            // Do not move the default initialization below the early out, it's important for the world to exist
            // if the Subscene gets assigned later, otherwise the change won't trigger an import/conversion.
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();

            GameObjectSceneUtility.RegisterSubScene(gameObject.scene, this);

#if UNITY_EDITOR
            WarnIfNeeded();

            _IsAddedToListOfAllSubScenes = true;
            m_AllSubScenes.Add(this);

            if (_SceneGUID == default(Hash128))
            {
                return;
            }

            if (!IsInMainStage())
            {
                return;
            }
#endif

            AddSceneEntities();
        }
        void OnEnable()
        {
    #if UNITY_EDITOR
            _IsEnabled = true;

            if (_SceneGUID == default(Hash128))
            {
                return;
            }

            if (UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetPrefabStage(gameObject) != null)
            {
                return;
            }

            foreach (var subscene in m_AllSubScenes)
            {
                if (subscene.SceneAsset == SceneAsset)
                {
                    UnityEngine.Debug.LogWarning($"A sub-scene can not include the same scene ('{EditableScenePath}') multiple times.", this);
                    return;
                }
            }

            m_AllSubScenes.Add(this);
    #endif

            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            AddSceneEntities();
        }
Example #4
0
        private static World GetEditorModeWorld()
        {
            if (World.Active == null)
            {
                DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            }

            if (!EditorModeEnabled)
            {
                EditorModeEnabled = true;

                foreach (var config in SystemConfigs)
                {
                    var system = World.Active.GetOrCreateSystem(config.Type);

                    if (config.Update)
                    {
                        system.Enabled = true;
                        UnityEditor.EditorApplication.update += system.Update;
                    }
                }

                Debug.Log("Editor systems started");
            }

            return(World.Active);
        }
Example #5
0
 public static void SetUp()
 {
     DefaultWorldInitialization.DefaultLazyEditModeInitialize();
     s_Connection = new LiveLinkTestConnection();
     EditorSceneLiveLinkToPlayerSendSystem.instance.SetConnection(s_Connection);
     LiveLinkAssetBundleBuildSystem.instance.SetConnection(s_Connection);
 }
 static World GetLiveLinkWorld(bool playMode)
 {
     if (!playMode)
     {
         DefaultWorldInitialization.DefaultLazyEditModeInitialize();
     }
     return(World.DefaultGameObjectInjectionWorld);
 }
Example #7
0
        public override void SetUp()
        {
            m_GraphInstances = m_GraphInstances ?? new Dictionary <Entity, GraphInstance>();
            base.SetUp();

            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            SetUpWorld();
        }
 public void SetUpBase()
 {
     DefaultWorldInitialization.DefaultLazyEditModeInitialize();
     World = World.DefaultGameObjectInjectionWorld;
     // Unity lazily generates the world time component on the first
     // world update. This will cause a structural  change which
     // could invalidate certain state during testing
     World.Update();
 }
Example #9
0
        public NetCodeTestWorld()
        {
#if UNITY_EDITOR
            // Not having a default world means RegisterUnloadOrPlayModeChangeShutdown has not been called which causes memory leaks
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
#endif
            _oldState    = ClientServerBootstrap.SystemStates;
            DefaultWorld = new World("NetCodeTest");
        }
        static World GetLiveLinkWorld()
        {
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            var world = World.DefaultGameObjectInjectionWorld;

            // This should be a fresh world, but make sure that it is not part of the player loop so we have manual
            // control on its updates.
            ScriptBehaviourUpdateOrder.RemoveWorldFromCurrentPlayerLoop(world);
            return(world);
        }
Example #11
0
        public NetCodeTestWorld()
        {
#if UNITY_EDITOR
            // Not having a default world means RegisterUnloadOrPlayModeChangeShutdown has not been called which causes memory leaks
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
#endif
            m_OldBootstrapState           = ClientServerBootstrap.s_State;
            ClientServerBootstrap.s_State = default;
            m_DefaultWorld = new World("NetCodeTest");
            m_ElapsedTime  = 42;
        }
Example #12
0
 public void SetUp()
 {
     m_TempAssets.SetUp();
     m_SubSceneTest.Setup();
     m_World.Setup();
     DefaultWorldInitialization.DefaultLazyEditModeInitialize();
     m_Texture1 = new Texture2D(64, 64);
     AssetDatabase.CreateAsset(m_Texture1, m_TempAssets.GetNextPath("Texture1.asset"));
     m_Texture2 = new Texture2D(32, 32);
     AssetDatabase.CreateAsset(m_Texture2, m_TempAssets.GetNextPath("Texture2.asset"));
 }
    public void OnEnable()
    {
        if (_mapGeneratorSystem != null)
        {
            return;
        }

        DefaultWorldInitialization.DefaultLazyEditModeInitialize();//boots the ECS EditorWorld

        _mapGeneratorSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <MapGeneratorSystem>();


        //EditorApplication.update += () => _mapGeneratorSystem.Update();//makes the system tick properly, not every 2 seconds !
    }
Example #14
0
        public void UpdateSceneEntities()
        {
#if UNITY_EDITOR
            var sceneHeaderPath = EntityScenesPaths.GetLoadPath(SceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1);
            m_SubSceneHeader = AssetDatabase.LoadAssetAtPath <SubSceneHeader>(sceneHeaderPath);
#endif

            if (_SceneEntityManager != null && _SceneEntityManager.IsCreated)
            {
                foreach (var sceneEntity in _SceneEntities)
                {
                    _SceneEntityManager.DestroyEntity(sceneEntity);
                }
            }
            _SceneEntities.Clear();
            _SceneEntityManager = null;

            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            if (World.Active != null && m_SubSceneHeader != null)
            {
                _SceneEntityManager = World.Active.EntityManager;

                for (int i = 0; i < m_SubSceneHeader.Sections.Length; ++i)
                {
                    var sceneEntity = _SceneEntityManager.CreateEntity();
                    #if UNITY_EDITOR
                    _SceneEntityManager.SetName(sceneEntity, i == 0 ? $"Scene: {SceneName}" : $"Scene: {SceneName} ({i})");
                    #endif

                    _SceneEntities.Add(sceneEntity);
                    _SceneEntityManager.AddComponentObject(sceneEntity, this);

                    if (AutoLoadScene)
                    {
                        _SceneEntityManager.AddComponentData(sceneEntity, new RequestSceneLoaded());
                    }

                    _SceneEntityManager.AddComponentData(sceneEntity, m_SubSceneHeader.Sections[i]);
                    _SceneEntityManager.AddComponentData(sceneEntity, new SceneBoundingVolume {
                        Value = m_SubSceneHeader.Sections[i].BoundingVolume
                    });
                }
            }
        }
        public IEnumerator DefaultBootstrappedWorld_OnDomainReload_RecreatesEditorWorld()
        {
            DisableSetupAndTearDown();

            // Make sure we have an Editor world initialized
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            Assert.NotNull(World.DefaultGameObjectInjectionWorld);
            Assert.NotZero(GetEditorWorldsCount());

            AddVerificationScript();

            // Request domain reload
            EditorUtility.RequestScriptReload();
            yield return(new RecompileScripts(false));

            Assert.AreEqual(0, GetDefaultWorldsCount()); // No game world in the edit mode
            Assert.AreEqual(1, GetEditorWorldsCount());  // Lazy init should be done by DefaultWorldInitializationVerificationScript script

            EnableSetupAndTearDown();
        }
Example #16
0
        void OnEnable()
        {
#if UNITY_EDITOR
            WarnIfNeeded();

            _IsAddedToListOfAllSubScenes = true;
            m_AllSubScenes.Add(this);

            if (_SceneGUID == default(Hash128))
            {
                return;
            }

            if (!IsInMainStage())
            {
                return;
            }
#endif

            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            AddSceneEntities();
        }
Example #17
0
        public void createEntity()
        {
            if (_entityManager == null)
            {
                DefaultWorldInitialization.DefaultLazyEditModeInitialize();
                _entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            }


            // Get the needed gameobject component
            if (!gameObject.TryGetComponent <MeshRenderer>(out _meshRenderer) ||
                !gameObject.TryGetComponent <MeshFilter>(out _meshFilter) ||
                !gameObject.TryGetComponent <Transform>(out _transform))
            {
                return;
            }

            Entity entity = _entityManager.CreateEntity(getArchetype());

            setEntity(entity);
            gameObject.SetActive(false);
        }
Example #18
0
        void OnEnable()
        {
#if UNITY_EDITOR
            WarnDuplicate();

            _IsEnabled = true;
            m_AllSubScenes.Add(this);

            if (_SceneGUID == default(Hash128))
            {
                return;
            }

            if (UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetPrefabStage(gameObject) != null)
            {
                return;
            }
#endif

            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            AddSceneEntities();
        }
        public void OneTimeSetUp()
        {
            // set up temporary GameObject injection world
            PreviousGameObjectInjectionWorld      = World.DefaultGameObjectInjectionWorld;
            World.DefaultGameObjectInjectionWorld = default;
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();

            // create folder for temporary assets
            string folderName;

            do
            {
                folderName = Path.GetRandomFileName();
            }while (AssetDatabase.IsValidFolder(Path.Combine("Assets", folderName)));
            TemporaryAssetsPath = AssetDatabase.GUIDToAssetPath(AssetDatabase.CreateFolder("Assets", folderName));

            // create non-readable mesh asset
            NonReadableMesh = UnityMesh.Instantiate(Resources.GetBuiltinResource <UnityMesh>("New-Cylinder.fbx"));
            NonReadableMesh.UploadMeshData(true);
            Assume.That(NonReadableMesh.isReadable, Is.False, $"{NonReadableMesh} was readable.");
            AssetDatabase.CreateAsset(NonReadableMesh, $"{TemporaryAssetsPath}/NonReadableMesh.asset");
        }
Example #20
0
        public void UpdateSceneEntities(bool warnIfMissing = false)
        {
#if UNITY_EDITOR
            var sceneHeaderPath = EntityScenesPaths.GetLoadPath(SceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1);
            m_SubSceneHeader = AssetDatabase.LoadAssetAtPath <SubSceneHeader>(sceneHeaderPath);
#endif
            if (warnIfMissing && m_SubSceneHeader == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning($"Sub-scene '{EditableScenePath}' has no valid header at '{sceneHeaderPath}'. Please rebuild the Entity Cache.", this);
#else
                Debug.LogWarning($"Sub-scene '{name}' has no valid header. Please rebuild the Entity Cache.", this);
#endif
            }


            if (_SceneEntityManager != null && _SceneEntityManager.IsCreated)
            {
                foreach (var sceneEntity in _SceneEntities)
                {
                    _SceneEntityManager.DestroyEntity(sceneEntity);
                }
            }
            _SceneEntities.Clear();
            _SceneEntityManager = null;

            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            if (World.Active != null)
            {
                _SceneEntityManager = World.Active.EntityManager;

                if (m_SubSceneHeader != null)
                {
                    for (int i = 0; i < m_SubSceneHeader.Sections.Length; ++i)
                    {
                        var sceneEntity = _SceneEntityManager.CreateEntity();
                        #if UNITY_EDITOR
                        _SceneEntityManager.SetName(sceneEntity, i == 0 ? $"Scene: {SceneName}" : $"Scene: {SceneName} ({i})");
                        #endif

                        _SceneEntities.Add(sceneEntity);
                        _SceneEntityManager.AddComponentObject(sceneEntity, this);

                        if (AutoLoadScene)
                        {
                            _SceneEntityManager.AddComponentData(sceneEntity, new RequestSceneLoaded());
                        }

                        _SceneEntityManager.AddComponentData(sceneEntity, m_SubSceneHeader.Sections[i]);
                        _SceneEntityManager.AddComponentData(sceneEntity, new SceneBoundingVolume {
                            Value = m_SubSceneHeader.Sections[i].BoundingVolume
                        });
                    }
                }
                else
                {
                    var sceneEntity = _SceneEntityManager.CreateEntity();
                    #if UNITY_EDITOR
                    _SceneEntityManager.SetName(sceneEntity, "Scene: {SceneName}");
                    #endif

                    _SceneEntities.Add(sceneEntity);
                    _SceneEntityManager.AddComponentObject(sceneEntity, this);
                }
            }
        }
Example #21
0
        public static void SetUp()
        {
            s_Assets.SetUp();

            var assetGuids = new List <GUID>();

            try
            {
                {
                    string path = s_Assets.GetNextPath(".asset");
                    AssetDatabase.CreateAsset(s_TempTexture = new Texture2D(64, 64), path);
                    s_TempTextureGuid = new GUID(AssetDatabase.AssetPathToGUID(path));
                    assetGuids.Add(s_TempTextureGuid);
                }
                {
                    string path = s_Assets.GetNextPath(".mat");
                    AssetDatabase.CreateAsset(s_TempMaterial = new Material(Shader.Find("Standard")), path);
                    s_TempMaterialGuid = new GUID(AssetDatabase.AssetPathToGUID(path));
                    assetGuids.Add(s_TempMaterialGuid);
                    s_TempMaterial.mainTexture = s_TempTexture;
                }

                var tempScenePath = s_Assets.GetNextPath(".unity");
                s_TempScene            = SubSceneTestsHelper.CreateScene(tempScenePath);
                s_SubSceneWithSections = SubSceneTestsHelper.CreateSubSceneInSceneFromObjects("SubScene", false, s_TempScene, () =>
                {
                    var go1 = new GameObject();
                    go1.AddComponent <SceneSectionComponent>().SectionIndex = 0;
                    var go2 = new GameObject();
                    go2.AddComponent <SceneSectionComponent>().SectionIndex = 2;
                    go2.AddComponent <TestComponentAuthoring>().Material    = s_TempMaterial;
                    return(new List <GameObject> {
                        go1, go2
                    });
                });

                {
                    var path = s_Assets.GetNextPath("LiveLinkBuildConfig.buildconfiguration");
                    BuildConfiguration.CreateAsset(path, config =>
                    {
                        config.SetComponent(new SceneList
                        {
                            SceneInfos = new List <SceneList.SceneInfo>
                            {
                                new SceneList.SceneInfo
                                {
                                    Scene = GlobalObjectId.GetGlobalObjectIdSlow(AssetDatabase.LoadAssetAtPath <SceneAsset>(tempScenePath))
                                }
                            }
                        });
                    });
                    s_LiveLinkBuildConfigGuid = new GUID(AssetDatabase.AssetPathToGUID(path));
                }
            }
            catch
            {
                s_Assets.TearDown();
                throw;
            }

            // This call ensures that the asset worker is already running and no test times out because we're still
            // waiting for the asset worker. Effectively this doesn't change the runtime that much since we will have
            // to wait for the import to finish in most of the tests anyway.
            GeEntitySceneArtifactHash(s_SubSceneWithSections.SceneGUID, s_LiveLinkBuildConfigGuid, ImportMode.Synchronous);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            s_TempAssetGuids = assetGuids.ToArray();
            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            s_Connection = new LiveLinkTestConnection();
            EditorSceneLiveLinkToPlayerSendSystem.instance.SetConnection(s_Connection);
            LiveLinkAssetBundleBuildSystem.instance.SetConnection(s_Connection);
        }