示例#1
0
    // Method that will make sure all currently loaded scenes will
    // be unloaded.
    public static void unloadScenes()
    {
        levelsFetched = AssetFetcher.GetLevels();
        levelsArray   = levelsFetched.ToArray <string> ();
        Scene sceneToUnload;

        foreach (string level in levelsArray)
        {
            sceneToUnload = SceneManager.GetSceneByName(level);
            EditorSceneManager.CloseScene(sceneToUnload, true);
        }         // foreach
    }
示例#2
0
            Manifest PrepareSceneManifest(Entry sceneEntry, HashSet <Scene> currentScenes)
            {
                Scene scene = EditorSceneManager.OpenScene(sceneEntry.mainAssetFile, OpenSceneMode.Additive);

                NodeTreeLoader[] loaders  = GameObject.FindObjectsOfType <NodeTreeLoader>();
                string           dataPath = GameObject.FindObjectOfType <NodeTreeLoader>()?.GetFullDataPath();
                List <Tuple <string, string> > loaderPaths = new List <Tuple <string, string> >();

                foreach (NodeTreeLoader loader in loaders)
                {
                    loaderPaths.Add(new Tuple <string, string>(Utilities.Utility.StringToGUID(loader.GetDataPath()).ToString(), loader.GetFullDataPath()));
                }

                try
                {
                    foreach (GameObject root in scene.GetRootGameObjects())
                    {
                        MapOrigin origin = root.GetComponentInChildren <MapOrigin>();
                        if (origin != null)
                        {
                            var manifest = new Manifest
                            {
                                assetName    = sceneEntry.name,
                                assetGuid    = Guid.NewGuid().ToString(),
                                bundleFormat = BundleConfig.Versions[BundleConfig.BundleTypes.Environment],
                                description  = origin.Description,
                                licenseName  = origin.LicenseName,
                                authorName   = "",
                                authorUrl    = "",
                                fmuName      = "",
                            };
                            manifest.additionalFiles = new Dictionary <string, string>();
                            foreach (Tuple <string, string> t in loaderPaths)
                            {
                                if (!manifest.additionalFiles.ContainsKey($"pointcloud_{t.Item1}"))
                                {
                                    manifest.additionalFiles.Add($"pointcloud_{t.Item1}", t.Item2);
                                }
                            }

                            return(manifest);
                        }
                    }
                    throw new Exception($"Build failed: MapOrigin on {sceneEntry.name} not found. Please add a MapOrigin component.");
                }
                finally
                {
                    if (!currentScenes.Contains(scene))
                    {
                        EditorSceneManager.CloseScene(scene, true);
                    }
                }
            }
示例#3
0
 private static void AddSceneByPath(string scenePath, bool setActive, bool isClosed, OpenSceneMode sceneMode)
 {
     EditorSceneManager.OpenScene(scenePath, sceneMode);
     if (setActive)
     {
         SceneManager.SetActiveScene(SceneManager.GetSceneByPath(scenePath));
     }
     if (isClosed)
     {
         EditorSceneManager.CloseScene(SceneManager.GetSceneByPath(scenePath), false);
     }
 }
        static void CreateSceneFromTemplate(SceneAsset template, bool append = false)
        {
            var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, append? NewSceneMode.Additive: NewSceneMode.Single);
            var temp     = EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(template), OpenSceneMode.Additive);
            var objects  = temp.GetRootGameObjects();

            foreach (var obj in objects)
            {
                SceneManager.MoveGameObjectToScene(obj, newScene);
            }
            EditorSceneManager.CloseScene(temp, true);
        }
示例#5
0
    void DeleteScene(string guid)
    {
        mSceneListData.guids.Remove(guid);
        string path  = AssetDatabase.GUIDToAssetPath(guid);
        Scene  scene = SceneManager.GetSceneByPath(path);

        EditorSceneManager.CloseScene(scene, true);
        if (AssetDatabase.DeleteAsset(path))
        {
            Debug.Log("移除:" + scene.name);
        }
    }
示例#6
0
        internal IEnumerator RestoreOriginalScenes()
        {
            // Don't restore scene state if we didn't save it in the first place
            if (string.IsNullOrEmpty(m_OriginalActiveSceneAssetPath))
            {
                yield break;
            }

            // Exit play mode so we can open scenes (without necessarily loading them)
            EditorApplication.isPlaying = false;

            int currentFrameCount = Time.frameCount;

            while (currentFrameCount == Time.frameCount)
            {
                yield return(null); //going out of play mode requires a frame
            }

            foreach (var sceneInfo in m_OriginalScenes)
            {
                // Don't open scene if path is empty (this is the case for a new unsaved unmodified scene)
                if (sceneInfo.AssetPath == string.Empty)
                {
                    continue;
                }

                var openSceneMode = sceneInfo.WasLoaded ? OpenSceneMode.Additive : OpenSceneMode.AdditiveWithoutLoading;

                EditorSceneManager.OpenScene(sceneInfo.AssetPath, openSceneMode);
            }

            var originalScenePaths = m_OriginalScenes.Select(sceneInfo => sceneInfo.AssetPath).ToArray();

            for (var sceneIndex = 0; sceneIndex < SceneManager.sceneCount; sceneIndex++)
            {
                var scene = SceneManager.GetSceneAt(sceneIndex);

                // Set originally active scene
                if (scene.path == m_OriginalActiveSceneAssetPath)
                {
                    SceneManager.SetActiveScene(scene);
                    continue;
                }

                // Close scene if was not opened originally
                if (!originalScenePaths.Contains(scene.path))
                {
                    EditorSceneManager.CloseScene(scene, true);
                }
            }

            m_OriginalActiveSceneAssetPath = null;
        }
示例#7
0
        public static void Draw(Rect position, SceneReference scene, GUIContent label, string newSceneName, Action newSceneSetup)
        {
            position = EditorGUI.PrefixLabel(position, label);

            var loadRect    = RectHelper.TakeTrailingIcon(ref position);
            var refreshRect = RectHelper.TakeTrailingIcon(ref position);

            if (GUI.Button(refreshRect, _refreshScenesButton.Content, GUIStyle.none))
            {
                SceneHelper.RefreshLists();
            }

            var list     = SceneHelper.GetSceneList(true, newSceneSetup != null);
            var index    = list.GetIndex(scene.Path);
            var selected = EditorGUI.Popup(position, index, list.Names);

            if (selected != index && selected == list.CreateIndex)
            {
                var newScene = SceneHelper.CreateScene(newSceneName, newSceneSetup);
                scene.Path = newScene.path;
            }
            else
            {
                scene.Path = list.GetPath(selected);
            }

            if (!string.IsNullOrEmpty(scene.Path))
            {
                var s = SceneManager.GetSceneByPath(scene.Path);

                using (ColorScope.ContentColor(Color.black))
                {
                    if (s.IsValid() && s.isLoaded)
                    {
                        if (GUI.Button(loadRect, _unloadSceneButton.Content, GUIStyle.none))
                        {
                            if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(new Scene[] { s }))
                            {
                                EditorSceneManager.CloseScene(s, true);
                            }
                        }
                    }
                    else
                    {
                        if (GUI.Button(loadRect, _loadSceneButton.Content, GUIStyle.none))
                        {
                            s = EditorSceneManager.OpenScene(scene.Path, OpenSceneMode.Additive);
                            SceneManager.SetActiveScene(s);
                        }
                    }
                }
            }
        }
示例#8
0
 public static void EndTest()
 {
     #if UNITY_EDITOR
     EditorSceneManager.SetActiveScene(originalActiveScene);
     foreach (var scene in loadedScenes)
     {
         SceneManager.LoadSceneAsync(scene.path);
     }
     EditorSceneManager.CloseScene(testScene, true);
     EditorApplication.isPlaying = false;
     #endif
 }
示例#9
0
        void RemoveScenesNotInAnyList()
        {
            var loaders = FindAllMultisceneLoaders();

            foreach (var scene in GetAllLoadedScenes())
            {
                if (ShouldRemoveScene(scene, loaders))
                {
                    EditorSceneManager.CloseScene(scene, true);
                }
            }
        }
示例#10
0
    public static void ReloadLastScene()
    {
        if (EditorApplication.isPlaying)
        {
            return;
        }

        Debug.Log("Reloading editor scene setup...");

        bool _dropRunScene = true;

        UnityEngine.SceneManagement.Scene _runScene = EditorSceneManager.GetActiveScene();

        string[] _scenesToLoad = LoadedScenes;

        //Loop through the stored scene list and add them back in
        for (int i = 0; i < _scenesToLoad.Length; i++)
        {
            if (_scenesToLoad[i] == string.Empty)
            {
                break;
            }

            //If the scene to load is the run mode scene then leave it alone and clear the drop flag
            if (_scenesToLoad[i] == _runScene.path)
            {
                _dropRunScene = false;
            }
            else
            {
                EditorSceneManager.OpenScene(_scenesToLoad[i], OpenSceneMode.Additive);
            }
        }

        //Now set the active scene
        for (int i = 0; i < EditorSceneManager.loadedSceneCount; i++)
        {
            if (EditorSceneManager.GetSceneAt(i).name == ActiveScene)
            {
                EditorSceneManager.SetActiveScene(EditorSceneManager.GetSceneAt(i));
                break;
            }
        }

        //Finally close out the run scene if it is not required
        if (_dropRunScene)
        {
            EditorSceneManager.CloseScene(_runScene, true);
        }

        EditorApplication.update -= ReloadLastScene;;
    }
示例#11
0
    public void UnloadData()
    {
        if (Data == null)
        {
            return;
        }

        //Saving
        if (Data.IsDirty())
        {
            if (Application.isPlaying)
            {
                Debug.Log("Can not save asset " + name + " in play mode.");
            }
            else
            {
                //Debug.Log("Saving asset " + Data.GetName() + ".");
                AssetDatabase.SaveAssets();
                EditorSceneManager.SaveScene(Data.GetScene());
            }
        }

        //Unloading Scene
        Scene scene = EditorSceneManager.GetSceneByName(Data.name);

        if (Application.isPlaying)
        {
            SceneManager.UnloadSceneAsync(scene);
        }
        else
        {
            EditorCoroutines.StartCoroutine(RemoveScene(0.25f), this);
        }
        IEnumerator RemoveScene(float delay)
        {
            EditorSceneManager.CloseScene(scene, false);
            yield return(new WaitForSeconds(delay));

            if (!scene.isLoaded)
            {
                EditorSceneManager.CloseScene(scene, true);
                EditorApplication.RepaintHierarchyWindow();
            }
        }

        //Unloading Asset
        Resources.UnloadUnusedAssets();

        //Reset Temporary
        TimeSeries  = null;
        BoneMapping = null;
    }
		// Search a scene for references
		private void SearchScene( string scenePath, List<SearchResultGroup> searchResult, SceneSetup[] initialSceneSetup )
		{
			Scene scene = EditorSceneManager.GetSceneByPath( scenePath );
			if( EditorApplication.isPlaying && !scene.isLoaded )
				return;

			bool canContainSceneObjectReference = scene.isLoaded && ( !EditorSceneManager.preventCrossSceneReferences || sceneObjectsToSearchScenesSet.Contains( scenePath ) );
			if( !canContainSceneObjectReference )
			{
				bool canContainAssetReference = assetsToSearchSet.Count > 0 && ( EditorApplication.isPlaying || AssetHasAnyReference( scenePath ) );
				if( !canContainAssetReference )
					return;
			}

			if( !EditorApplication.isPlaying )
				scene = EditorSceneManager.OpenScene( scenePath, OpenSceneMode.Additive );

			currentSearchResultGroup = new SearchResultGroup( scenePath, true );

			// Search through all the GameObjects in the scene
			GameObject[] rootGameObjects = scene.GetRootGameObjects();
			for( int i = 0; i < rootGameObjects.Length; i++ )
				SearchGameObjectRecursively( rootGameObjects[i] );

			// If no references are found in the scene and if the scene is not part of the initial scene setup, close it
			if( currentSearchResultGroup.NumberOfReferences == 0 )
			{
				if( !EditorApplication.isPlaying )
				{
					bool sceneIsOneOfInitials = false;
					for( int i = 0; i < initialSceneSetup.Length; i++ )
					{
						if( initialSceneSetup[i].path == scenePath )
						{
							if( !initialSceneSetup[i].isLoaded )
								EditorSceneManager.CloseScene( scene, false );

							sceneIsOneOfInitials = true;
							break;
						}
					}

					if( !sceneIsOneOfInitials )
						EditorSceneManager.CloseScene( scene, true );
				}
			}
			else
			{
				// Some references are found in this scene, save the results
				searchResult.Add( currentSearchResultGroup );
			}
		}
示例#13
0
    private static bool CleanScenes()
    {
        string[] sceneList =
            AssetDatabase.GetAllAssetPaths()
            .Where(
                path =>
                path.EndsWith(
                    ".unity",
                    StringComparison.OrdinalIgnoreCase))
            .ToArray();

        Scene activeScene = EditorSceneManager.GetActiveScene();

        int count = sceneList.Length;
        int index = 0;

        for (int i = 0; i < sceneList.Length; i++)
        {
            try {
                if (EditorUtility.DisplayCancelableProgressBar(
                        "Removing components with a missing script",
                        sceneList[i],
                        (float)(index++) / (float)count))
                {
                    return(false);
                }

                Scene scene = EditorSceneManager.GetSceneByPath(sceneList[i]);

                if (!scene.isLoaded)
                {
                    scene =
                        EditorSceneManager.OpenScene(
                            sceneList[i],
                            OpenSceneMode.Additive);
                }

                CleanScene(scene);

                EditorSceneManager.SaveScene(scene);

                if (scene != activeScene)
                {
                    EditorSceneManager.CloseScene(scene, true);
                }
            } catch (Exception e) {
                Debug.LogException(e);
            }
        }

        return(true);
    }
        void SetupScene(Tutorial tutorial)
        {
            // For some reason Yamato runs fail to load an existing scenes so create one on the fly.
            var tutorialScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

            m_TutorialScenePath = m_TempFolderPath + "/TutorialScene.unity";
            EditorSceneManager.SaveScene(tutorialScene, m_TutorialScenePath);
            EditorSceneManager.CloseScene(tutorialScene, true);

            tutorial.Scenes = new[] { AssetDatabase.LoadAssetAtPath <SceneAsset>(m_TutorialScenePath) };

            Assert.That(tutorial.Scenes[0], Is.Not.Null, $"Could not load tutorial scene '{m_TutorialScenePath}'.");
        }
        private void CloseSelectedScenes(bool removeScenes)
        {
            List <int> selectedScenes = this.GetSelectedScenes();

            if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(this.GetModifiedScenes(selectedScenes)))
            {
                foreach (int num in selectedScenes)
                {
                    EditorSceneManager.CloseScene(EditorSceneManager.GetSceneByHandle(num), removeScenes);
                }
                EditorApplication.RequestRepaintAllViews();
            }
        }
示例#16
0
            public override void Action(int instanceId, string pathName, string resourceFile)
            {
                if (s_CreateEmptySceneAsset(pathName))
                {
                    UnityEngine.Object sceneAsset = AssetDatabase.LoadAssetAtPath(pathName, typeof(SceneAsset));
                    ProjectWindowUtil.ShowCreatedAsset(sceneAsset);

                    Scene scene = EditorSceneManager.OpenScene(pathName, OpenSceneMode.Additive);
                    FillScene(scene);
                    EditorSceneManager.SaveScene(scene);
                    EditorSceneManager.CloseScene(scene, true);
                }
            }
 public void TearDown()
 {
     if (settings != null)
     {
         settings.BlobAssetStore.Dispose();
     }
     EditorSceneManager.CloseScene(scene, true);
     if (world != null)
     {
         world.Dispose();
     }
     entityManager = default;
 }
示例#18
0
 public void UnloadScene(SubsceneTag tag, bool editMode)
 {
     tag.loaded = false;
     //Call OnUnload();
     if (editMode)
     {
         var scene = EditorSceneManager.CloseScene(tempRef, false);
     }
     else
     {
         var scene = SceneManager.UnloadSceneAsync(tempRef);
     }
 }
示例#19
0
        /// <summary>
        /// OnDestroy
        /// </summary>
        private void OnDestroy()
        {
            if (string.IsNullOrEmpty(this.defaultScenePath) || EditorApplication.isPlaying == true)
            {
                return;
            }

            Scene currentScene = EditorSceneManager.GetActiveScene();

            EditorSceneManager.OpenScene(this.defaultScenePath);
            EditorSceneManager.CloseScene(currentScene, true);
            this.defaultScenePath = string.Empty;
        }
示例#20
0
 public void TearDown()
 {
     EditorSceneManager.CloseScene(scene, true);
     if (blobAssetStore != null)
     {
         blobAssetStore.Dispose();
     }
     if (world != null)
     {
         world.Dispose();
     }
     entityManager = default;
 }
示例#21
0
        public void SetTestSceneSingle()
        {
            if (!CheckProperties())
            {
                return;
            }
            //保存场景
            EditorSceneManager.SaveOpenScenes();

            //激活场景重定向
            GameObject ag = Selection.activeGameObject;

            if (ag != null)
            {
                EditorSceneManager.SetActiveScene(ag.scene);
            }

            //删除多余场景
            Scene activeScene = EditorSceneManager.GetActiveScene();

            if (activeScene.name == _system.name)
            {
                LogError("请选中除了System以外的任一场景(中的物体)");
                return;
            }
            for (int i = EditorSceneManager.sceneCount - 1; i >= 0; i--)
            {
                Scene s = EditorSceneManager.GetSceneAt(i);
                if (s != activeScene)
                {
                    EditorSceneManager.CloseScene(s, true);
                }
            }

            //加载system场景并配置The Matrix
            Scene systemScene =
                EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(_system), OpenSceneMode.Additive);

            systemScene.GetRootGameObjects()[0].GetComponent <TheMatrix>().test = false;

            EditorSceneManager.SetActiveScene(activeScene);
            EditorSceneManager.SaveScene(systemScene);

            Log("单独测试环境准备完毕!");

            if (quickStart)
            {
                EditorApplication.isPlaying = true;
            }
        }
        /// <summary>
        /// Creates a scene in the current project that acts as a loading scene until assetbundles are
        /// downloaded from the CDN. Takes in a loadingScreenImagePath, a path to the image shown in the loading scene,
        /// and an assetbundle URL. Replaces the current loading scene with a new one if it exists.
        /// </summary>
        public static void GenerateScene(string assetBundleUrl, string loadingScreenImagePath)
        {
            if (string.IsNullOrEmpty(assetBundleUrl))
            {
                throw new ArgumentException("AssetBundle URL text field cannot be null or empty.");
            }

            if (!File.Exists(loadingScreenImagePath))
            {
                throw new FileNotFoundException(string.Format("Loading screen image file cannot be found: {0}",
                                                              loadingScreenImagePath));
            }

            // Removes the loading scene if it is present, otherwise does nothing.
            EditorSceneManager.CloseScene(SceneManager.GetSceneByName(Path.GetFileNameWithoutExtension(SceneName)),
                                          true);

            var loadingScreenScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

            var loadingScreenGameObject = new GameObject(CanvasName);

            AddImageToScene(loadingScreenGameObject, loadingScreenImagePath);

            AddScript(loadingScreenGameObject);

            LoadingBar.AddComponent(loadingScreenGameObject);

            bool saveOk = EditorSceneManager.SaveScene(loadingScreenScene, SceneFilePath);

            if (!saveOk)
            {
                // Not a fatal issue. User can attempt to resave this scene.
                var warningMessage = string.Format("Issue while saving scene {0}.",
                                                   SceneName);

                Debug.LogWarning(warningMessage);

                DialogHelper.DisplayMessage(SaveErrorTitle, warningMessage);
            }
            else
            {
                //TODO: investigate GUI Layout errors that occur when moving this to DialogHelper
                if (EditorUtility.DisplayDialog("Change Scenes in Build",
                                                "Would you like to replace any existing Scenes in Build with the loading screen scene?", "Yes",
                                                "No"))
                {
                    SetMainSceneInBuild(SceneFilePath);
                }
            }
        }
 /// <summary>
 /// シーンロード状態を切り替えます.
 /// 非ロード状態になるとき、シーンを自動的に保存します.
 /// </summary>
 /// <param name="scene">シーン.</param>
 static void ToggleSceneLoaded(Scene scene)
 {
     //現在ロード済み.シーンを保存してunloadする.
     if (scene.isLoaded)
     {
         EditorSceneManager.SaveScene(scene);
         EditorSceneManager.CloseScene(scene, false);
     }
     //現在非ロード済み.シーンをloadする.
     else
     {
         EditorSceneManager.OpenScene(scene.path, OpenSceneMode.Additive);
     }
 }
    public new void OnDestroy()
    {
        //inform  calling window of new chunks list
        callingWindow.UpdateChunksToManage(manager.ToManage);

        //reload all old scenes
        ReopenPreviousScenes();

        //close current scene and destoy i guess
        EditorSceneManager.CloseScene(openScene, true);

        Tools.hidden = false;
        base.OnDestroy();
    }
示例#25
0
        private IEnumerator DoAnalyzeArea(Map map, AreaSpawner areaSpawner, bool showDialog = true)
        {
            string areaName   = areaSpawner.GetAreaScenePath();
            Area   exportArea = null;
            Scene  areaScene  = EditorSceneManager.OpenScene(areaName, OpenSceneMode.Additive);

            if (areaScene != null)
            {
                SceneManager.SetActiveScene(areaScene);
                GameObject[] rootObjArray = areaScene.GetRootGameObjects();
                if (rootObjArray != null && rootObjArray.Length > 0)
                {
                    for (int index = 0; index < rootObjArray.Length; index++)
                    {
                        SceneManager.MoveGameObjectToScene(rootObjArray[index], map.GetOwnerScene());
                        Area area = rootObjArray[index].GetComponent <Area>();
                        if (area != null)
                        {
                            exportArea = area;
                        }
                    }
                }
                EditorSceneManager.CloseScene(areaScene, true);
            }
            yield return(null);

            if (exportArea != null)
            {
                areaSpawner.SetArea(exportArea);
                IEnumerator areaSpawnerEnumerator = areaSpawner.DoUpdate(map, true);
                while (areaSpawnerEnumerator.MoveNext())
                {
                    yield return(null);
                }
                //TODO: 1、计算area的直径  2、计算所有unit的直径 3、算出推荐格子大小 对应层AABB范围
                //如果大于等于Area直径的90%以上的unit数量大于0 算一个层
                Bounds areaAABB        = exportArea.GetAABB();
                float  areaDiameter    = Mathf.Max(areaAABB.size.x, areaAABB.size.y, areaAABB.size.z);
                float  consultDiameter = areaDiameter * 0.9f;
                CalcuateLayer(map, exportArea, areaDiameter);
                EditorUtility.SetDirty(m_EditorSplitAreaSetting);
                GameObject.DestroyImmediate(exportArea.gameObject);
            }
            EditorUtility.ClearProgressBar();
            if (showDialog)
            {
                EditorUtility.DisplayDialog("Analyze", "分析成功", "OK");
            }
            AssetDatabase.Refresh();
        }
    private static void HierarchyWindowItemOnGUI(int instanceId, Rect selectionRect)
    {
        // 再生中は無視
        if (Application.isPlaying)
        {
            return;
        }

        // シーン以外は無視
        if (EditorUtility.InstanceIDToObject(instanceId) != null)
        {
            return;
        }

        // シーンオブジェクトを取得するメソッドを取得
        var getSceneByHandle = typeof(EditorSceneManager)
                               .GetMethod("GetSceneByHandle", BindingFlags.NonPublic | BindingFlags.Static);

        if (getSceneByHandle == null)
        {
            Debug.LogWarning("[EditorSceneLoadToggle] No such method: EditorSceneManager.GetSceneByHandle");
            return;
        }

        // シーンオブジェクトを取得
        var scene = (Scene)getSceneByHandle.Invoke(null, new object[] { instanceId });

        // チェックボックス表示位置
        selectionRect.x    += selectionRect.width - Width;
        selectionRect.width = Width;

        // チェックボックス表示
        if (scene.isLoaded == GUI.Toggle(selectionRect, scene.isLoaded, ""))
        {
            return;
        }

        // シーンがロードされていない場合はロードして終了
        if (!scene.isLoaded)
        {
            EditorSceneManager.OpenScene(scene.path, OpenSceneMode.Additive);
            return;
        }

        // ロードされているシーンの保存確認後、アンロード
        if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(new[] { scene }))
        {
            EditorSceneManager.CloseScene(scene, false);
        }
    }
示例#27
0
        public static void DuplicateToScene(
            [CommandParameter(Help = "The name of the scene to duplicate the objects to",
                              AutoCompleteMethodName = "SceneNameAutoComplete", ForceAutoCompleteUsage = true,
                              OverrideName = "Scene Name", PreventDefaultValueUsage = true)]
            string sceneName)
        {
            EditorUtility.DisplayProgressBar("Moving Objects to Scene...",
                                             "MonKey is duplicating your objects to another scene, please wait!", .5f);
            Scene scene = SceneManager.GetSceneByPath(sceneName);
            bool  unloadWhenDone;

            if (scene.IsValid())
            {
                unloadWhenDone = false;
            }
            else
            {
                unloadWhenDone = true;
                scene          = EditorSceneManager.OpenScene(sceneName, OpenSceneMode.Additive);
            }
            Scene previous = new Scene();

            foreach (var gameObject in Selection.gameObjects.Where(_ => _.scene.IsValid()))
            {
                if (!previous.IsValid())
                {
                    previous = gameObject.scene;
                }

                GameObject prefabParent = (GameObject)PrefabUtilities.GetPrefabParentPlatformIndependant(gameObject);

                if (prefabParent)
                {
                    PrefabUtility.InstantiatePrefab(prefabParent, scene);
                }
                else
                {
                    GameObject newGameObject = Object.Instantiate(gameObject);
                    SceneManager.MoveGameObjectToScene(newGameObject, scene);
                }
            }

            if (unloadWhenDone && previous.IsValid())
            {
                EditorSceneManager.SaveScene(previous);
                EditorSceneManager.SaveScene(scene);
                EditorSceneManager.CloseScene(scene, true);
            }
            EditorUtility.ClearProgressBar();
        }
示例#28
0
 /// <summary>
 /// 卸载MapScene
 /// </summary>
 public void UnLoadMapScene()
 {
     if (m_MapScene != null && m_MapScene.isLoaded)
     {
         if (Application.isPlaying)
         {
             SceneManager.UnloadSceneAsync(m_MapScene);
         }
         else
         {
             EditorSceneManager.CloseScene(m_MapScene, true);
         }
     }
 }
示例#29
0
        /// <summary>
        /// Unloads the specified scene asynchronously
        /// </summary>
        /// <param name="sceneName"></param>
        public static void Unload(SceneField scene, SceneCallback onSceneUnloaded = null)
        {
            // Editor mode
      #if UNITY_EDITOR
            if (isEditMode)
            {
                EditorSceneManager.CloseScene(scene.runtime, true);
                return;
            }
      #endif

            // Play Mode
            get.StartCoroutine(get.UnloadAsync(scene, onSceneUnloaded));
        }
    //***Close Otehr Scene***
    private void CloseOtherScene()
    {
        Scene _currentScene = SceneManager.GetActiveScene();

        for (int i = 0; i < flowData.levelNodeDatas.Count; i++)
        {
            if (flowData.levelNodeDatas[i].GetScenePath() != _currentScene.path)
            {
                //SceneAsset _scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(flowData.levelNodeDatas[i].scenePath);
                Scene _scene = EditorSceneManager.GetSceneByPath(flowData.levelNodeDatas[i].GetScenePath());
                EditorSceneManager.CloseScene(_scene, false);
            }
        }
    }