public SystemInfo(ISystem system) { _system = system; var reactiveSystem = system as ReactiveSystem; var isReactive = reactiveSystem != null; Type systemType; if (isReactive) { _interfaceFlags = getInterfaceFlags(reactiveSystem.subsystem, isReactive); systemType = reactiveSystem.subsystem.GetType(); } else { _interfaceFlags = getInterfaceFlags(system, isReactive); systemType = system.GetType(); } var debugSystem = system as DebugSystems; if (debugSystem != null) { _systemName = debugSystem.name; } else { _systemName = systemType.Name.EndsWith(SYSTEM_SUFFIX, StringComparison.Ordinal) ? systemType.Name.Substring(0, systemType.Name.Length - SYSTEM_SUFFIX.Length) : systemType.Name; } isActive = true; }
private void DrawSystemSection(string header, ref bool showSystems, DebugSystems systems, SystemInterfaceFlags systemInterfaceFlags) { showSystems = EditorGUILayoutTools.DrawSectionHeaderToggle(header, showSystems); if (showSystems && ShouldShowSystems(systems, systemInterfaceFlags)) { using (new EditorGUILayout.VerticalScope(EntitasReduxStyles.SectionContent)) { var systemsDrawn = DrawSystemInfos(systems, systemInterfaceFlags); if (systemsDrawn == 0) { EditorGUILayout.LabelField(string.Empty); } } } }
private GUIStyle GetSystemStyle(SystemInfo systemInfo, SystemInterfaceFlags systemFlag) { var style = new GUIStyle(GUI.skin.label); var color = systemInfo.IsReactiveSystems && EditorGUIUtility.isProSkin ? Color.white : style.normal.textColor; if (systemFlag == SystemInterfaceFlags.FixedUpdateSystem && systemInfo.AverageFixedUpdateDuration >= VisualDebuggingPreferences.SystemWarningThreshold) { color = Color.red; } if (systemFlag == SystemInterfaceFlags.UpdateSystem && systemInfo.AverageUpdateDuration >= VisualDebuggingPreferences.SystemWarningThreshold) { color = Color.red; } if (systemFlag == SystemInterfaceFlags.LateUpdateSystem && systemInfo.AverageLateUpdateDuration >= VisualDebuggingPreferences.SystemWarningThreshold) { color = Color.red; } if (systemFlag == SystemInterfaceFlags.ReactiveSystem && systemInfo.AverageReactiveDuration >= VisualDebuggingPreferences.SystemWarningThreshold) { color = Color.red; } if (systemFlag == SystemInterfaceFlags.CleanupSystem && systemInfo.AverageCleanupDuration >= VisualDebuggingPreferences.SystemWarningThreshold) { color = Color.red; } style.normal.textColor = color; return(style); }
GUIStyle getSystemStyle(SystemInfo systemInfo, SystemInterfaceFlags systemFlag) { var style = new GUIStyle(GUI.skin.label); var color = systemInfo.isReactiveSystems && EditorGUIUtility.isProSkin ? Color.white : style.normal.textColor; if (systemFlag == SystemInterfaceFlags.IExecuteSystem && systemInfo.averageExecutionDuration >= _systemWarningThreshold) { color = Color.red; } if (systemFlag == SystemInterfaceFlags.ICleanupSystem && systemInfo.averageCleanupDuration >= _systemWarningThreshold) { color = Color.red; } style.normal.textColor = color; return(style); }
public SystemInfo(ISystem system) { _system = system; _interfaceFlags = getInterfaceFlags(system); var debugSystem = system as DebugSystems; if (debugSystem != null) { _systemName = debugSystem.name; } else { var systemType = system.GetType(); _systemName = systemType.Name.EndsWith(SYSTEM_SUFFIX, StringComparison.Ordinal) ? systemType.Name.Substring(0, systemType.Name.Length - SYSTEM_SUFFIX.Length) : systemType.Name; } isActive = true; }
int drawSystemInfos(DebugSystems systems, SystemInterfaceFlags type) { SystemInfo[] systemInfos = null; switch (type) { case SystemInterfaceFlags.IInitializeSystem: systemInfos = systems.initializeSystemInfos .Where(systemInfo => systemInfo.initializationDuration >= _threshold) .ToArray(); break; case SystemInterfaceFlags.IExecuteSystem: systemInfos = systems.executeSystemInfos .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold) .ToArray(); break; case SystemInterfaceFlags.ICleanupSystem: systemInfos = systems.cleanupSystemInfos .Where(systemInfo => systemInfo.cleanupDuration >= _threshold) .ToArray(); break; case SystemInterfaceFlags.ITearDownSystem: systemInfos = systems.tearDownSystemInfos .Where(systemInfo => systemInfo.teardownDuration >= _threshold) .ToArray(); break; } systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod); var systemsDrawn = 0; foreach (var systemInfo in systemInfos) { var debugSystems = systemInfo.system as DebugSystems; if (debugSystems != null) { if (!shouldShowSystems(debugSystems, type)) { continue; } } if (EditorLayout.MatchesSearchString(systemInfo.systemName.ToLower(), _systemNameSearchString.ToLower())) { EditorGUILayout.BeginHorizontal(); { var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; var wasActive = systemInfo.isActive; if (systemInfo.areAllParentsActive) { systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20)); } else { EditorGUI.BeginDisabledGroup(true); { EditorGUILayout.Toggle(false, GUILayout.Width(20)); } } EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel = indent; if (systemInfo.isActive != wasActive) { var reactiveSystem = systemInfo.system as IReactiveSystem; if (reactiveSystem != null) { if (systemInfo.isActive) { reactiveSystem.Activate(); } else { reactiveSystem.Deactivate(); } } } switch (type) { case SystemInterfaceFlags.IInitializeSystem: EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.initializationDuration.ToString(), getSystemStyle(systemInfo, SystemInterfaceFlags.IInitializeSystem)); break; case SystemInterfaceFlags.IExecuteSystem: var avgE = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12); var minE = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12); var maxE = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration); EditorGUILayout.LabelField(systemInfo.systemName, avgE + minE + maxE, getSystemStyle(systemInfo, SystemInterfaceFlags.IExecuteSystem)); break; case SystemInterfaceFlags.ICleanupSystem: var avgC = string.Format("Ø {0:00.000}", systemInfo.averageCleanupDuration).PadRight(12); var minC = string.Format("▼ {0:00.000}", systemInfo.minCleanupDuration).PadRight(12); var maxC = string.Format("▲ {0:00.000}", systemInfo.maxCleanupDuration); EditorGUILayout.LabelField(systemInfo.systemName, avgC + minC + maxC, getSystemStyle(systemInfo, SystemInterfaceFlags.ICleanupSystem)); break; case SystemInterfaceFlags.ITearDownSystem: EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.teardownDuration.ToString(), getSystemStyle(systemInfo, SystemInterfaceFlags.ITearDownSystem)); break; } } EditorGUILayout.EndHorizontal(); systemsDrawn += 1; } var debugSystem = systemInfo.system as DebugSystems; if (debugSystem != null) { var indent = EditorGUI.indentLevel; EditorGUI.indentLevel += 1; systemsDrawn += drawSystemInfos(debugSystem, type); EditorGUI.indentLevel = indent; } } return(systemsDrawn); }
int drawSystemInfos(DebugSystems systems, SystemInterfaceFlags type, bool isChildSystem) { SystemInfo[] systemInfos = null; var drawExecutionDuration = false; switch (type) { case SystemInterfaceFlags.IInitializeSystem: systemInfos = systems.initializeSystemInfos; break; case SystemInterfaceFlags.IExecuteSystem: systemInfos = systems.executeSystemInfos; drawExecutionDuration = true; break; case SystemInterfaceFlags.ICleanupSystem: systemInfos = systems.cleanupSystemInfos; break; case SystemInterfaceFlags.ITearDownSystem: systemInfos = systems.tearDownSystemInfos; break; } systemInfos = systemInfos .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold) .ToArray(); systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod); var systemsDrawn = 0; foreach (var systemInfo in systemInfos) { var debugSystems = systemInfo.system as DebugSystems; if (debugSystems != null) { if (!shouldShowSystems(debugSystems, type)) { continue; } } if (systemInfo.systemName.ToLower().Contains(_systemNameSearchTerm.ToLower())) { EntitasEditorLayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup(isChildSystem); { systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20)); } EditorGUI.EndDisabledGroup(); var reactiveSystem = systemInfo.system as ReactiveSystem; if (reactiveSystem != null) { if (systemInfo.isActive) { reactiveSystem.Activate(); } else { reactiveSystem.Deactivate(); } } if (drawExecutionDuration) { var avg = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12); var min = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12); var max = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration); EditorGUILayout.LabelField(systemInfo.systemName, avg + min + max, getSystemStyle(systemInfo)); } else { EditorGUILayout.LabelField(systemInfo.systemName, getSystemStyle(systemInfo)); } } EntitasEditorLayout.EndHorizontal(); systemsDrawn += 1; } var debugSystem = systemInfo.system as DebugSystems; if (debugSystem != null) { var indent = EditorGUI.indentLevel; EditorGUI.indentLevel += 1; systemsDrawn += drawSystemInfos(debugSystem, type, true); EditorGUI.indentLevel = indent; } } return(systemsDrawn); }
private int DrawSystemInfos(DebugSystems systems, SystemInterfaceFlags type) { IEnumerable <SystemInfo> systemInfos = null; switch (type) { case SystemInterfaceFlags.InitializeSystem: systemInfos = systems.InitializeSystemInfos .Where(systemInfo => systemInfo.InitializationDuration >= _threshold); break; case SystemInterfaceFlags.FixedUpdateSystem: systemInfos = systems.FixedUpdateSystemInfos .Where(systemInfo => systemInfo.AverageFixedUpdateDuration >= _threshold); break; case SystemInterfaceFlags.UpdateSystem: systemInfos = systems.UpdateSystemInfos .Where(systemInfo => systemInfo.AverageUpdateDuration >= _threshold); break; case SystemInterfaceFlags.LateUpdateSystem: systemInfos = systems.LateUpdateSystemInfos .Where(systemInfo => systemInfo.AverageLateUpdateDuration >= _threshold); break; case SystemInterfaceFlags.ReactiveSystem: systemInfos = systems.ReactiveSystemInfos .Where(systemInfo => systemInfo.AverageReactiveDuration >= _threshold); break; case SystemInterfaceFlags.CleanupSystem: systemInfos = systems.CleanupSystemInfos .Where(systemInfo => systemInfo.CleanupDuration >= _threshold); break; case SystemInterfaceFlags.TearDownSystem: systemInfos = systems.TearDownSystemInfos .Where(systemInfo => systemInfo.TeardownDuration >= _threshold); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } systemInfos = GetSortedSystemInfos(systemInfos, _systemSortMethod); var systemsDrawn = 0; foreach (var systemInfo in systemInfos) { if (systemInfo.System is DebugSystems debugSystems) { if (!ShouldShowSystems(debugSystems, type)) { continue; } } if (EditorGUILayoutTools.MatchesSearchString(systemInfo.SystemName.ToLower(), _systemNameSearchString.ToLower())) { using (new EditorGUILayout.HorizontalScope()) { var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; var wasActive = systemInfo.isActive; var areParentsActive = systemInfo.AreAllParentsActive; if (areParentsActive) { systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20)); } else { using (new EditorGUI.DisabledScope(true)) { EditorGUILayout.Toggle(false, GUILayout.Width(20)); } } EditorGUI.indentLevel = indent; if (systemInfo.isActive != wasActive) { if (systemInfo.System is IReactiveSystem reactiveSystem) { if (systemInfo.isActive) { reactiveSystem.Activate(); } else { reactiveSystem.Deactivate(); } } } using (new EditorGUI.DisabledScope(!systemInfo.isActive || !areParentsActive)) { var guiStyle = GetSystemStyle(systemInfo, type); switch (type) { case SystemInterfaceFlags.InitializeSystem: DrawSimpleSystemInfoPerformance( systemInfo.SystemName, systemInfo.InitializationDuration, guiStyle); break; case SystemInterfaceFlags.FixedUpdateSystem: DrawDetailedSystemInfoPerformance( systemInfo.SystemName, systemInfo.AverageFixedUpdateDuration, systemInfo.MinFixedUpdateDuration, systemInfo.MaxFixedUpdateDuration, guiStyle); break; case SystemInterfaceFlags.UpdateSystem: DrawDetailedSystemInfoPerformance( systemInfo.SystemName, systemInfo.AverageUpdateDuration, systemInfo.MinUpdateDuration, systemInfo.MaxUpdateDuration, guiStyle); break; case SystemInterfaceFlags.LateUpdateSystem: DrawDetailedSystemInfoPerformance( systemInfo.SystemName, systemInfo.AverageLateUpdateDuration, systemInfo.MinLateUpdateDuration, systemInfo.MaxLateUpdateDuration, guiStyle); break; case SystemInterfaceFlags.ReactiveSystem: DrawDetailedSystemInfoPerformance( systemInfo.SystemName, systemInfo.AverageReactiveDuration, systemInfo.MinReactiveDuration, systemInfo.MaxReactiveDuration, guiStyle); break; case SystemInterfaceFlags.CleanupSystem: DrawDetailedSystemInfoPerformance( systemInfo.SystemName, systemInfo.AverageCleanupDuration, systemInfo.MinCleanupDuration, systemInfo.MaxCleanupDuration, guiStyle); break; case SystemInterfaceFlags.TearDownSystem: DrawSimpleSystemInfoPerformance( systemInfo.SystemName, systemInfo.TeardownDuration, guiStyle); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } } } systemsDrawn += 1; } if (systemInfo.System is DebugSystems debugSystem) { var indent = EditorGUI.indentLevel; EditorGUI.indentLevel += 1; systemsDrawn += DrawSystemInfos(debugSystem, type); EditorGUI.indentLevel = indent; } } return(systemsDrawn); }
int drawSystemInfos(DebugSystems systems, SystemInterfaceFlags type, bool isChildSystem) { SystemInfo[] systemInfos = null; var drawExecutionDuration = false; switch(type) { case SystemInterfaceFlags.IInitializeSystem: systemInfos = systems.initializeSystemInfos; break; case SystemInterfaceFlags.IExecuteSystem: systemInfos = systems.executeSystemInfos; drawExecutionDuration = true; break; case SystemInterfaceFlags.ICleanupSystem: systemInfos = systems.cleanupSystemInfos; break; case SystemInterfaceFlags.ITearDownSystem: systemInfos = systems.tearDownSystemInfos; break; } systemInfos = systemInfos .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold) .ToArray(); systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod); var systemsDrawn = 0; foreach(var systemInfo in systemInfos) { var debugSystems = systemInfo.system as DebugSystems; if(debugSystems != null) { if(!shouldShowSystems(debugSystems, type)) { continue; } } if(systemInfo.systemName.ToLower().Contains(_systemNameSearchTerm.ToLower())) { EntitasEditorLayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup(isChildSystem); { systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20)); } EditorGUI.EndDisabledGroup(); var reactiveSystem = systemInfo.system as ReactiveSystem; if(reactiveSystem != null) { if(systemInfo.isActive) { reactiveSystem.Activate(); } else { reactiveSystem.Deactivate(); } } if(drawExecutionDuration) { var avg = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12); var min = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12); var max = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration); EditorGUILayout.LabelField(systemInfo.systemName, avg + min + max, getSystemStyle(systemInfo)); } else { EditorGUILayout.LabelField(systemInfo.systemName, getSystemStyle(systemInfo)); } } EntitasEditorLayout.EndHorizontal(); systemsDrawn += 1; } var debugSystem = systemInfo.system as DebugSystems; if(debugSystem != null) { var indent = EditorGUI.indentLevel; EditorGUI.indentLevel += 1; systemsDrawn += drawSystemInfos(debugSystem, type, true); EditorGUI.indentLevel = indent; } } return systemsDrawn; }
static bool shouldShowSystems(DebugSystems systems, SystemInterfaceFlags type) { if(!_hideEmptySystems) { return true; } switch(type) { case SystemInterfaceFlags.IInitializeSystem: return systems.totalInitializeSystemsCount > 0; case SystemInterfaceFlags.IExecuteSystem: return systems.totalExecuteSystemsCount > 0; case SystemInterfaceFlags.ICleanupSystem: return systems.totalCleanupSystemsCount > 0; case SystemInterfaceFlags.ITearDownSystem: return systems.totalTearDownSystemsCount > 0; default: return true; } }