Skip to content

Commit

Permalink
chore: add some secret debug tools (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore authored Aug 18, 2024
1 parent 9acbdd1 commit 25c246c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Editor/MiscDebugTools.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace nadena.dev.ndmf.ui
{
internal static class MiscDebugTools
{
#if NDMF_DEBUG
[MenuItem("Tools/NDM Framework/Debug Tools/Dump Scenes")]
public static void DumpScenes()
{
Expand All @@ -29,11 +31,47 @@ public static void DumpSceneObjects()
}
}

[MenuItem("Tools/NDM Framework/Debug Tools/Dump Prefab Stage Objects (recursive)")]
public static void DumpPrefabStageObjects()
{
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage == null)
{
Debug.Log("No prefab stage active.");
return;
}

Debug.Log($"Prefab stage {prefabStage.name}:");
DumpPrefabStageObjectsRecursive(prefabStage.prefabContentsRoot, indent: 0);

void DumpPrefabStageObjectsRecursive(GameObject obj, int indent)
{
Debug.Log(new string(' ', indent * 2) + obj.name);
foreach (Transform child in obj.transform)
{
DumpPrefabStageObjectsRecursive(child.gameObject, indent + 1);
}
}
}

[MenuItem("Tools/NDM Framework/Debug Tools/Create GameObject at root")]
public static void CreateGameObjectAtRoot()
{
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
var scene = prefabStage?.scene ?? SceneManager.GetActiveScene();

var go = new GameObject("New GameObject");
SceneManager.MoveGameObjectToScene(go, scene);

go.transform.SetParent(null, worldPositionStays: true);
}

[MenuItem("Tools/NDM Framework/Debug Tools/Reload Domain")]
public static void ReloadDomain()
{
Debug.Log("Reloading domain...");
UnityEditor.EditorUtility.RequestScriptReload();
}
#endif
}
}

0 comments on commit 25c246c

Please sign in to comment.