public void SubScene_WithDependencyOnAssetInScene_Reimport_EndToEnd() { var subScene = SubSceneTestsHelper.CreateSubSceneFromObjects(ref m_TempAssets, "SubScene", false, () => { var go = new GameObject(); var authoring = go.AddComponent <DependencyTestAuthoring>(); var sphereHolder = GameObject.CreatePrimitive(PrimitiveType.Sphere); authoring.Asset = sphereHolder.GetComponent <MeshFilter>().sharedMesh; UnityEngine.Object.DestroyImmediate(sphereHolder); return(new List <GameObject> { go }); }); var buildSettings = default(Unity.Entities.Hash128); var originalHash = EntityScenesPaths.GetSubSceneArtifactHash(subScene.SceneGUID, buildSettings, ImportMode.Synchronous); Assert.IsTrue(originalHash.IsValid); SubSceneInspectorUtility.ForceReimport(new [] { subScene }); var newHashCreated = EntityScenesPaths.GetSubSceneArtifactHash(subScene.SceneGUID, buildSettings, ImportMode.Synchronous); Assert.IsTrue(newHashCreated.IsValid); Assert.AreNotEqual(originalHash, newHashCreated); SubSceneInspectorUtility.ForceReimport(new [] { subScene }); var newHashUpdated = EntityScenesPaths.GetSubSceneArtifactHash(subScene.SceneGUID, buildSettings, ImportMode.Synchronous); Assert.IsTrue(newHashUpdated.IsValid); Assert.AreNotEqual(newHashCreated, newHashUpdated); Assert.AreNotEqual(originalHash, newHashUpdated); }
public static SubScene CreateSubSceneInSceneFromObjects(string name, bool keepOpen, Scene parentScene, Func <List <GameObject> > createObjects = null) { var args = new SubSceneContextMenu.NewSubSceneArgs { parentScene = parentScene, newSubSceneMode = SubSceneContextMenu.NewSubSceneMode.EmptyScene }; SceneManager.SetActiveScene(parentScene); var subScene = SubSceneContextMenu.CreateNewSubScene(name, args, InteractionMode.AutomatedAction); SubSceneInspectorUtility.EditScene(subScene); var objects = createObjects?.Invoke(); if (objects != null) { foreach (var obj in objects) { SceneManager.MoveGameObjectToScene(obj, subScene.EditingScene); } } EditorSceneManager.SaveScene(subScene.EditingScene); EditorSceneManager.SaveScene(parentScene); if (!keepOpen) { SubSceneInspectorUtility.CloseSceneWithoutSaving(subScene); } return(subScene); }
public IEnumerator SubScene_OpenedForEdit_RemainsOpenInPlayMode([Values(EnterPlayModeOptions.DisableDomainReload | EnterPlayModeOptions.DisableSceneReload)] EnterPlayModeOptions enterPlayModeOptions) { // Set editor settings EditorSettings.enterPlayModeOptionsEnabled = enterPlayModeOptions != EnterPlayModeOptions.None; EditorSettings.enterPlayModeOptions = enterPlayModeOptions; var expectingDomainReload = !enterPlayModeOptions.HasFlag(EnterPlayModeOptions.DisableDomainReload); DisableSetupAndTearDown(); EditorSceneManager.OpenScene("Assets/HelloCube/3. SubScene/SubScene.unity", OpenSceneMode.Single); var subScene = Object.FindObjectOfType <SubScene>(); Assert.NotNull(subScene); SubSceneInspectorUtility.EditScene(subScene); Assert.IsTrue(subScene.IsLoaded); Assert.AreEqual(2, SceneManager.sceneCount); // Enter play mode yield return(new EnterPlayMode(expectingDomainReload)); // Validate that subscene is still loaded subScene = Object.FindObjectOfType <SubScene>(); Assert.NotNull(subScene); Assert.IsTrue(subScene.IsLoaded); Assert.AreEqual(2, SceneManager.sceneCount); yield return(new ExitPlayMode()); EnableSetupAndTearDown(); }
internal static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect) { var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject; if (gameObject != null) { SubScene subScene; if (gameObject.TryGetComponent(out subScene)) { if (!subScene.CanBeLoaded()) { return; } if (PrefabUtility.IsOutermostPrefabInstanceRoot(subScene.gameObject)) { return; } var evt = Event.current; Rect buttonRect = selectionRect; buttonRect.x = buttonRect.xMax; buttonRect.width = Styles.subSceneEditingButtonWidth; var loaded = subScene.EditingScene.isLoaded; var wantsLoaded = EditorGUI.Toggle(buttonRect, loaded); if (wantsLoaded != loaded) { SubScene[] subScenes; var selectedSubScenes = Selection.GetFiltered <SubScene>(SelectionMode.TopLevel); if (selectedSubScenes.Contains(subScene)) { subScenes = selectedSubScenes; } else { subScenes = new[] { subScene } }; if (wantsLoaded) { SubSceneInspectorUtility.EditScene(subScenes); } else { SubSceneInspectorUtility.CloseAndAskSaveIfUserWantsTo(subScenes); } } if (buttonRect.Contains(evt.mousePosition)) { GUI.Label(buttonRect, Styles.subSceneEditingTooltip); } } } } }
public IEnumerator SubScene_OpenedForEdit_UnloadsSceneOnDestroyImmediate() { EditorSceneManager.OpenScene("Assets/HelloCube/3. SubScene/SubScene.unity", OpenSceneMode.Single); var subScene = Object.FindObjectOfType <SubScene>(); Assert.NotNull(subScene); SubSceneInspectorUtility.EditScene(subScene); Assert.IsTrue(subScene.IsLoaded); Assert.AreEqual(2, SceneManager.sceneCount); Object.DestroyImmediate(subScene.gameObject); yield return(null); Assert.AreEqual(1, SceneManager.sceneCount); }
public IEnumerator ClosedSubSceneCanBeOpened_Play([Values] EnteringPlayMode useDomainReload) { { SetDomainReload(useDomainReload); CreateEmptySubScene("TestSubScene", false); } yield return(GetEnterPlayMode(true)); { var subScene = Object.FindObjectOfType <SubScene>(); Assert.IsFalse(subScene.IsLoaded); SubSceneInspectorUtility.EditScene(subScene); yield return(null); Assert.IsTrue(subScene.IsLoaded); } }
public void SubScene_WithDependencyOnAsset_IsInvalidatedWhenAssetChanges() { var subScene = CreateSubScene("SubScene", nameof(SubScene_WithDependencyOnAsset_IsInvalidatedWhenAssetChanges)); SubSceneInspectorUtility.EditScene(subScene); var go = new GameObject(); var authoring = go.AddComponent <DependencyTestAuthoring>(); var dependency = new GameObject(); authoring.GameObject = dependency; var texture = new Texture2D(64, 64); authoring.Asset = texture; var assetPath = Path.Combine(m_TempAssetDir, "Texture.asset"); AssetDatabase.CreateAsset(authoring.Asset, assetPath); SceneManager.MoveGameObjectToScene(dependency, subScene.EditingScene); SceneManager.MoveGameObjectToScene(go, subScene.EditingScene); EditorSceneManager.SaveScene(subScene.EditingScene); AssetDatabase.TryGetGUIDAndLocalFileIdentifier(subScene.SceneAsset, out var guid, out long _); var buildSettings = default(Unity.Entities.Hash128); var subSceneGuid = new GUID(guid); var hash = EntityScenesPaths.GetSubSceneArtifactHash(subSceneGuid, buildSettings, ImportMode.Synchronous); Assert.IsTrue(hash.IsValid); texture.wrapMode = texture.wrapMode == TextureWrapMode.Repeat ? TextureWrapMode.Mirror : TextureWrapMode.Repeat; AssetDatabase.SaveAssets(); var newHash = EntityScenesPaths.GetSubSceneArtifactHash(subSceneGuid, buildSettings, ImportMode.NoImport); Assert.AreNotEqual(hash, newHash); Assert.IsFalse(newHash.IsValid); }
public override BuildStepResult RunBuildStep(BuildContext context) { var manifest = context.BuildManifest; var settings = GetRequiredComponent <DotsRuntimeBuildProfile>(context); var buildScenes = GetRequiredComponent <SceneList>(context); var exportedSceneGuids = new HashSet <Guid>(); var originalActiveScene = SceneManager.GetActiveScene(); void ExportSceneToFile(Scene scene, Guid guid) { var outputFile = settings.DataDirectory.GetFile(guid.ToString("N")); using (var exportWorld = new World("Export World")) { var exportDriver = new TinyExportDriver(context, settings.DataDirectory); exportDriver.DestinationWorld = exportWorld; exportDriver.SceneGUID = new Hash128(guid.ToString("N")); SceneManager.SetActiveScene(scene); GameObjectConversionUtility.ConvertScene(scene, exportDriver); context.GetOrCreateValue <WorldExportTypeTracker>()?.AddTypesFromWorld(exportWorld); #if EXPORT_TINY_SHADER RenderSettingsConversion.ConvertRenderSettings(exportWorld.EntityManager); #endif WorldExport.WriteWorldToFile(exportWorld, outputFile); exportDriver.Write(manifest); } manifest.Add(guid, scene.path, outputFile.ToSingleEnumerable()); } foreach (var rootScenePath in buildScenes.GetScenePathsForBuild()) { using (var loadedSceneScope = new LoadedSceneScope(rootScenePath)) { var thisSceneGuid = new Guid(AssetDatabase.AssetPathToGUID(rootScenePath)); if (exportedSceneGuids.Contains(thisSceneGuid)) { continue; } ExportSceneToFile(loadedSceneScope.ProjectScene, thisSceneGuid); exportedSceneGuids.Add(thisSceneGuid); var thisSceneSubScenes = loadedSceneScope.ProjectScene.GetRootGameObjects() .Select(go => go.GetComponent <SubScene>()) .Where(g => g != null && g); foreach (var subScene in thisSceneSubScenes) { var guid = new Guid(subScene.SceneGUID.ToString()); if (exportedSceneGuids.Contains(guid)) { continue; } var isLoaded = subScene.IsLoaded; if (!isLoaded) { SubSceneInspectorUtility.EditScene(subScene); } var scene = subScene.EditingScene; var sceneGuid = subScene.SceneGUID; ExportSceneToFile(scene, guid); if (!isLoaded) { SubSceneInspectorUtility.CloseSceneWithoutSaving(subScene); } } } } SceneManager.SetActiveScene(originalActiveScene); return(Success()); }
static void OpenAllSubScenes() => SubSceneInspectorUtility.EditScene(SubScene.AllSubScenes.ToArray());