Skip to content

Instantly share code, notes, and snippets.

@HassakuTb
Created April 12, 2022 04:36
Show Gist options
  • Save HassakuTb/bdf1ccf81ddbab1d5f29d083b74bc761 to your computer and use it in GitHub Desktop.
Save HassakuTb/bdf1ccf81ddbab1d5f29d083b74bc761 to your computer and use it in GitHub Desktop.
EditorWindow to display PlayerLoop in Unity.
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.LowLevel;
namespace HassakuLab.Utils.PlayerLoops.Editor
{
public class PlayerLoopViewer : EditorWindow
{
[MenuItem("HassakuLab/PlayerLoopViewer")]
private static void ShowWindow()
{
var window = GetWindow<PlayerLoopViewer>();
window.titleContent = new GUIContent("PlayerLoopViewer");
window.Show();
}
private readonly Dictionary<Type, bool> isFoldOpenTable = new();
private Vector2 scrollPosition;
private void RenderSubsystemOnGui(PlayerLoopSystem system, int depth)
{
if (!isFoldOpenTable.ContainsKey(system.type))
{
isFoldOpenTable.Add(system.type, false);
}
EditorGUI.indentLevel = depth;
isFoldOpenTable[system.type] = EditorGUILayout.Foldout(isFoldOpenTable[system.type],system.type.Name);
if (isFoldOpenTable[system.type])
{
if (system.subSystemList != null)
{
foreach (var subSystem in system.subSystemList)
{
RenderSubsystemOnGui(subSystem, depth+1);
}
}
}
}
private void OnGUI()
{
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
if (EditorApplication.isPlaying)
{
PlayerLoopSystem playerLoop = PlayerLoop.GetCurrentPlayerLoop();
foreach (var subSystem in playerLoop.subSystemList)
{
RenderSubsystemOnGui(subSystem, 0);
}
}
else
{
EditorGUILayout.LabelField("Move to PlayMode to display PlayerLoopSystem.");
}
EditorGUILayout.EndScrollView();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment