Skip to content

Commit

Permalink
- Added an option to show popup only when a log is received
Browse files Browse the repository at this point in the history
- Added opacity settings for log window and popup (closed #90)
- Combined "Start Minimized" and "Enable Popup" options (only "Start Minimized" remains)
  • Loading branch information
yasirkula committed Feb 18, 2024
1 parent c6af7bd commit b120470
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 22 deletions.
40 changes: 31 additions & 9 deletions Plugins/IngameDebugConsole/Editor/DebugLogManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ public class DebugLogManagerEditor : Editor
private SerializedProperty enableHorizontalResizing;
private SerializedProperty resizeFromRight;
private SerializedProperty minimumWidth;
private SerializedProperty enablePopup;
private SerializedProperty startInPopupMode;
private SerializedProperty logWindowOpacity;
private SerializedProperty popupOpacity;
private SerializedProperty popupVisibility;
private SerializedProperty popupVisibilityLogFilter;
private SerializedProperty startMinimized;
private SerializedProperty toggleWithKey;
private SerializedProperty toggleKey;
Expand All @@ -37,6 +39,9 @@ public class DebugLogManagerEditor : Editor
private SerializedProperty popupAvoidsScreenCutout;
private SerializedProperty autoFocusOnCommandInputField;

#if UNITY_2017_3_OR_NEWER
private readonly GUIContent popupVisibilityLogFilterLabel = new GUIContent( "Log Filter", "Determines which log types will show the popup on screen" );
#endif
private readonly GUIContent receivedLogTypesLabel = new GUIContent( "Received Log Types", "Only these logs will be received by the console window, other logs will simply be skipped" );
private readonly GUIContent receiveInfoLogsLabel = new GUIContent( "Info" );
private readonly GUIContent receiveWarningLogsLabel = new GUIContent( "Warning" );
Expand All @@ -50,8 +55,10 @@ private void OnEnable()
enableHorizontalResizing = serializedObject.FindProperty( "enableHorizontalResizing" );
resizeFromRight = serializedObject.FindProperty( "resizeFromRight" );
minimumWidth = serializedObject.FindProperty( "minimumWidth" );
enablePopup = serializedObject.FindProperty( "enablePopup" );
startInPopupMode = serializedObject.FindProperty( "startInPopupMode" );
logWindowOpacity = serializedObject.FindProperty( "logWindowOpacity" );
popupOpacity = serializedObject.FindProperty( "popupOpacity" );
popupVisibility = serializedObject.FindProperty( "popupVisibility" );
popupVisibilityLogFilter = serializedObject.FindProperty( "popupVisibilityLogFilter" );
startMinimized = serializedObject.FindProperty( "startMinimized" );
toggleWithKey = serializedObject.FindProperty( "toggleWithKey" );
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
Expand Down Expand Up @@ -103,11 +110,26 @@ public override void OnInspectorGUI()

EditorGUILayout.Space();

EditorGUILayout.PropertyField( enablePopup );
if( enablePopup.boolValue )
DrawSubProperty( startInPopupMode );
else
DrawSubProperty( startMinimized );
EditorGUILayout.PropertyField( startMinimized );
EditorGUILayout.PropertyField( logWindowOpacity );
EditorGUILayout.PropertyField( popupOpacity );

EditorGUILayout.PropertyField( popupVisibility );
if( popupVisibility.intValue == (int) PopupVisibility.WhenLogReceived )
{
EditorGUI.indentLevel++;
#if UNITY_2017_3_OR_NEWER
popupVisibilityLogFilter.intValue = (int) (DebugLogFilter) EditorGUILayout.EnumFlagsField( popupVisibilityLogFilterLabel, (DebugLogFilter) popupVisibilityLogFilter.intValue );
#else
EditorGUI.BeginChangeCheck();
bool infoLog = EditorGUILayout.Toggle( "Info", ( (DebugLogFilter) popupVisibilityLogFilter.intValue & DebugLogFilter.Info ) == DebugLogFilter.Info );
bool warningLog = EditorGUILayout.Toggle( "Warning", ( (DebugLogFilter) popupVisibilityLogFilter.intValue & DebugLogFilter.Warning ) == DebugLogFilter.Warning );
bool errorLog = EditorGUILayout.Toggle( "Error", ( (DebugLogFilter) popupVisibilityLogFilter.intValue & DebugLogFilter.Error ) == DebugLogFilter.Error );
if( EditorGUI.EndChangeCheck() )
popupVisibilityLogFilter.intValue = ( infoLog ? (int) DebugLogFilter.Info : 0 ) | ( warningLog ? (int) DebugLogFilter.Warning : 0 ) | ( errorLog ? (int) DebugLogFilter.Error : 0 );
#endif
EditorGUI.indentLevel--;
}

EditorGUILayout.PropertyField( toggleWithKey );
if( toggleWithKey.boolValue )
Expand Down
2 changes: 1 addition & 1 deletion Plugins/IngameDebugConsole/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= In-game Debug Console (v1.6.6) =
= In-game Debug Console (v1.6.7) =

Documentation: https://github.com/yasirkula/UnityIngameDebugConsole
FAQ: https://github.com/yasirkula/UnityIngameDebugConsole#faq
Expand Down
52 changes: 42 additions & 10 deletions Plugins/IngameDebugConsole/Scripts/DebugLogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ public enum DebugLogFilter
Info = 1,
Warning = 2,
Error = 4,
All = 7
All = ~0
}

public enum PopupVisibility
{
Always = 0,
WhenLogReceived = 1,
Never = 2
}

public class DebugLogManager : MonoBehaviour
Expand Down Expand Up @@ -68,13 +75,25 @@ public class DebugLogManager : MonoBehaviour

[SerializeField]
[HideInInspector]
[Tooltip( "If disabled, no popup will be shown when the console window is hidden" )]
private bool enablePopup = true;
[Tooltip( "Opacity of the console window" )]
[Range( 0f, 1f )]
private float logWindowOpacity = 1f;

[SerializeField]
[HideInInspector]
[Tooltip( "Opacity of the popup" )]
[Range( 0f, 1f )]
internal float popupOpacity = 1f;

[SerializeField]
[HideInInspector]
[Tooltip( "If enabled, console will be initialized as a popup" )]
private bool startInPopupMode = true;
[Tooltip( "Determines when the popup will show up (after the console window is closed)" )]
private PopupVisibility popupVisibility = PopupVisibility.Always;

[SerializeField]
[HideInInspector]
[Tooltip( "Determines which log types will show the popup on screen" )]
private DebugLogFilter popupVisibilityLogFilter = DebugLogFilter.All;

[SerializeField]
[HideInInspector]
Expand Down Expand Up @@ -630,12 +649,12 @@ private void OnDisable()

private void Start()
{
if( ( enablePopup && startInPopupMode ) || ( !enablePopup && startMinimized ) )
if( startMinimized )
HideLogWindow();
else
ShowLogWindow();

PopupEnabled = enablePopup;
PopupEnabled = ( popupVisibility != PopupVisibility.Never );
}

private void OnDestroy()
Expand Down Expand Up @@ -781,7 +800,19 @@ private void LateUpdate()
if( !isLogWindowVisible )
{
entryCountTextsDirty = true;
popupManager.NewLogsArrived( newInfoEntryCount, newWarningEntryCount, newErrorEntryCount );

if( popupVisibility == PopupVisibility.WhenLogReceived && !popupManager.IsVisible )
{
if( ( newInfoEntryCount > 0 && ( popupVisibilityLogFilter & DebugLogFilter.Info ) == DebugLogFilter.Info ) ||
( newWarningEntryCount > 0 && ( popupVisibilityLogFilter & DebugLogFilter.Warning ) == DebugLogFilter.Warning ) ||
( newErrorEntryCount > 0 && ( popupVisibilityLogFilter & DebugLogFilter.Error ) == DebugLogFilter.Error ) )
{
popupManager.Show();
}
}

if( popupManager.IsVisible )
popupManager.NewLogsArrived( newInfoEntryCount, newWarningEntryCount, newErrorEntryCount );
}
}

Expand Down Expand Up @@ -925,7 +956,7 @@ public void ShowLogWindow()
{
// Show the log window
logWindowCanvasGroup.blocksRaycasts = true;
logWindowCanvasGroup.alpha = 1f;
logWindowCanvasGroup.alpha = logWindowOpacity;

popupManager.Hide();

Expand Down Expand Up @@ -954,7 +985,8 @@ public void HideLogWindow()
if( commandInputField.isFocused )
commandInputField.DeactivateInputField();

popupManager.Show();
if( popupVisibility == PopupVisibility.Always )
popupManager.Show();

isLogWindowVisible = false;

Expand Down
6 changes: 5 additions & 1 deletion Plugins/IngameDebugConsole/Scripts/DebugLogPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class DebugLogPopup : MonoBehaviour, IPointerClickHandler, IBeginDragHand
// Coroutines for simple code-based animations
private IEnumerator moveToPosCoroutine = null;

public bool IsVisible { get; private set; }

private void Awake()
{
popupTransform = (RectTransform) transform;
Expand Down Expand Up @@ -137,7 +139,8 @@ public void OnPointerClick( PointerEventData data )
public void Show()
{
canvasGroup.blocksRaycasts = true;
canvasGroup.alpha = 1f;
canvasGroup.alpha = debugManager.popupOpacity;
IsVisible = true;

// Reset the counters
ResetValues();
Expand All @@ -152,6 +155,7 @@ public void Hide()
canvasGroup.blocksRaycasts = false;
canvasGroup.alpha = 0f;

IsVisible = false;
isPopupBeingDragged = false;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.ingamedebugconsole",
"displayName": "In-game Debug Console",
"version": "1.6.6",
"version": "1.6.7",
"documentationUrl": "https://github.com/yasirkula/UnityIngameDebugConsole",
"changelogUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/releases",
"licensesUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/blob/master/LICENSE.txt",
Expand Down

0 comments on commit b120470

Please sign in to comment.