Created
April 12, 2022 04:36
-
-
Save HassakuTb/bdf1ccf81ddbab1d5f29d083b74bc761 to your computer and use it in GitHub Desktop.
EditorWindow to display PlayerLoop in Unity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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