using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; /// /// CoreCleaner - cleans the boot scene so it contains ONLY what a player needs: /// Kart (the McLaren) + Ground + Main Camera + Directional Light + volume /// Everything else that the old agent dumped at the origin (a giant orange box, /// sci-fi wall pieces, rocks) is moved into Assets/Scenes/Core/_removed/ /// instead of being deleted, so nothing is ever lost. /// /// Menu: Tools > Clean Core Scene /// Batch: Unity.exe -batchmode -quit -projectPath .. -executeMethod CoreCleaner.Run /// public static class CoreCleaner { const string Core = "Assets/Scenes/Core/Core.unity"; const string Parked = "Assets/Scenes/Core/_parked"; // roots we KEEP static readonly HashSet Keep = new HashSet { "Kart", "Ground", "Main Camera", "Directional Light", "Global Volume" }; public static void Run() { if (!File.Exists(Core)) { Debug.LogError("[CoreCleaner] " + Core + " missing"); return; } var scene = EditorSceneManager.OpenScene(Core, OpenSceneMode.Single); var roots = new List(scene.GetRootGameObjects()); int parked = 0; var names = new List(); foreach (var go in roots) { if (Keep.Contains(go.name)) { names.Add("KEEP " + go.name); continue; } // everything else -> parked folder as a prefab (nothing is deleted) if (!AssetDatabase.IsValidFolder(Parked)) AssetDatabase.CreateFolder("Assets/Scenes/Core", "_parked"); int rend = go.GetComponentsInChildren(true).Length; string file = Parked + "/" + go.name + ".prefab"; int i = 1; while (AssetDatabase.LoadAssetAtPath(file) != null) { file = Parked + "/" + go.name + "_" + i + ".prefab"; i++; } PrefabUtility.SaveAsPrefabAsset(go, file); names.Add("PARK " + go.name + " (renderers=" + rend + ") -> " + Path.GetFileName(file)); Object.DestroyImmediate(go); parked++; } EditorSceneManager.MarkSceneDirty(scene); EditorSceneManager.SaveScene(scene); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); foreach (var n in names) Debug.Log("[CoreCleaner] " + n); Debug.Log("[CoreCleaner] DONE. kept=" + (names.Count - parked) + " parked=" + parked); } }