Net-Game/Library/PackageCache/com.unity.2d.common@bb1fc9b3d81b/Editor/DebugTools/PlayerLoopInspector.cs
2025-03-28 08:33:16 -04:00

49 lines
1.5 KiB
C#

using UnityEngine.LowLevel;
using UnityEngine.UIElements;
namespace UnityEditor.U2D.Common
{
internal class PlayerLoopInspector : EditorWindow
{
[MenuItem("internal:Window/Player Loop Inspector")]
static void ShowWindow()
{
var wind = GetWindow<PlayerLoopInspector>(false, "Player Loop");
wind.Show();
}
void OnEnable()
{
Refresh();
}
void Refresh()
{
rootVisualElement.Clear();
rootVisualElement.Add(new Button(Refresh) { text = "Refresh" });
var scrollView = new ScrollView();
rootVisualElement.Add(scrollView);
var loop = PlayerLoop.GetCurrentPlayerLoop();
ShowSystems(scrollView.contentContainer, loop.subSystemList, 0);
}
static void ShowSystems(VisualElement root, PlayerLoopSystem[] systems, int indent)
{
foreach (var playerLoopSystem in systems)
{
if (playerLoopSystem.subSystemList != null)
{
var foldout = new Foldout { text = playerLoopSystem.type.Name, style = { left = indent * 15 } };
root.Add(foldout);
ShowSystems(foldout, playerLoopSystem.subSystemList, indent + 1);
}
else
{
root.Add(new Label(playerLoopSystem.type.Name) { style = { left = indent * 15 } });
}
}
}
}
}