hellbound/Assets/Editor/DirtyAndSaveSceneToRemoveDe...

26 lines
847 B
C#
Raw Permalink Normal View History

2021-11-26 11:16:25 +03:00
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.Linq;
public class DirtyAndSaveSceneToRemoveDeprecatedComponents : MonoBehaviour
{
[MenuItem("Cleanup/Cleanup Scenes with Deprecated Components")]
static void DoCleanup()
{
var sceneGUIDs = AssetDatabase.FindAssets("t:Scene");
string[] scenePaths = sceneGUIDs.Select(i => AssetDatabase.GUIDToAssetPath(i)).ToArray();
for (int i = 0; i < scenePaths.Length; i++)
{
var scene = EditorSceneManager.OpenScene(scenePaths[i], OpenSceneMode.Additive);
EditorSceneManager.MarkSceneDirty(scene);
EditorSceneManager.SaveScene(scene);
if(scene != EditorSceneManager.GetActiveScene())
EditorSceneManager.UnloadSceneAsync(scene);
}
}
}