Skip to content

Commit 58eef32

Browse files
committed
Added "Copy All Logs On Resize Button Click" option (disabled by default) + DebugLogManager.GetAllLogs now optionally takes maxLogCount and maxElapsedTime parameters
1 parent b96318c commit 58eef32

5 files changed

Lines changed: 89 additions & 6 deletions

File tree

Plugins/IngameDebugConsole/Editor/DebugLogManagerEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class DebugLogManagerEditor : Editor
2020
private SerializedProperty toggleKey;
2121
private SerializedProperty enableSearchbar;
2222
private SerializedProperty topSearchbarMinWidth;
23+
private SerializedProperty copyAllLogsOnResizeButtonClick;
2324
private SerializedProperty receiveLogsWhileInactive;
2425
private SerializedProperty receiveInfoLogs;
2526
private SerializedProperty receiveWarningLogs;
@@ -76,6 +77,7 @@ private void OnEnable()
7677
maxLogCount = serializedObject.FindProperty( "maxLogCount" );
7778
logsToRemoveAfterMaxLogCount = serializedObject.FindProperty( "logsToRemoveAfterMaxLogCount" );
7879
queuedLogLimit = serializedObject.FindProperty( "queuedLogLimit" );
80+
copyAllLogsOnResizeButtonClick = serializedObject.FindProperty("copyAllLogsOnResizeButtonClick");
7981
clearCommandAfterExecution = serializedObject.FindProperty( "clearCommandAfterExecution" );
8082
commandHistorySize = serializedObject.FindProperty( "commandHistorySize" );
8183
showCommandSuggestions = serializedObject.FindProperty( "showCommandSuggestions" );
@@ -133,6 +135,8 @@ public override void OnInspectorGUI()
133135
if( enableSearchbar.boolValue )
134136
DrawSubProperty( topSearchbarMinWidth );
135137

138+
EditorGUILayout.PropertyField(copyAllLogsOnResizeButtonClick);
139+
136140
EditorGUILayout.Space();
137141

138142
EditorGUILayout.PropertyField( receiveLogsWhileInactive );

Plugins/IngameDebugConsole/IngameDebugConsole.prefab

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ GameObject:
228228
- component: {fileID: 22261918}
229229
- component: {fileID: 11431488}
230230
- component: {fileID: 114538072837526774}
231+
- component: {fileID: 7084366004531900487}
231232
m_Layer: 5
232233
m_Name: DebugLogWindowResize
233234
m_TagString: Untagged
@@ -307,6 +308,20 @@ MonoBehaviour:
307308
m_Name:
308309
m_EditorClassIdentifier:
309310
debugManager: {fileID: 11452418}
311+
--- !u!114 &7084366004531900487
312+
MonoBehaviour:
313+
m_ObjectHideFlags: 0
314+
m_CorrespondingSourceObject: {fileID: 0}
315+
m_PrefabInstance: {fileID: 0}
316+
m_PrefabAsset: {fileID: 0}
317+
m_GameObject: {fileID: 110786}
318+
m_Enabled: 1
319+
m_EditorHideFlags: 0
320+
m_Script: {fileID: 11500000, guid: 298319a3c52d37442b63e30622b8c05d, type: 3}
321+
m_Name:
322+
m_EditorClassIdentifier:
323+
maxLogCount: 2147483647
324+
maxElapsedTime: Infinity
310325
--- !u!1 &118212
311326
GameObject:
312327
m_ObjectHideFlags: 0
@@ -851,6 +866,7 @@ MonoBehaviour:
851866
toggleKey: 96
852867
enableSearchbar: 1
853868
topSearchbarMinWidth: 360
869+
copyAllLogsOnResizeButtonClick: 0
854870
receiveLogsWhileInactive: 0
855871
receiveInfoLogs: 1
856872
receiveWarningLogs: 1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections;
2+
using UnityEngine;
3+
using UnityEngine.EventSystems;
4+
5+
namespace IngameDebugConsole
6+
{
7+
public class CopyLogsOnResizeButtonClick : MonoBehaviour, IPointerClickHandler
8+
{
9+
[SerializeField]
10+
private int maxLogCount = int.MaxValue;
11+
[SerializeField]
12+
private float maxElapsedTime = float.PositiveInfinity;
13+
14+
void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
15+
{
16+
if (!eventData.dragging && eventData.eligibleForClick && DebugLogManager.Instance.copyAllLogsOnResizeButtonClick)
17+
{
18+
GUIUtility.systemCopyBuffer = DebugLogManager.Instance.GetAllLogs(maxLogCount, maxElapsedTime);
19+
StartCoroutine(ScaleAnimationCoroutine());
20+
}
21+
}
22+
23+
private IEnumerator ScaleAnimationCoroutine()
24+
{
25+
for (float t = 0f; t < 1f; t += Time.unscaledDeltaTime * 3f)
26+
{
27+
transform.localScale = Vector3.one * (1f + Mathf.PingPong(t, 0.5f));
28+
yield return null;
29+
}
30+
31+
transform.localScale = Vector3.one;
32+
}
33+
}
34+
}

Plugins/IngameDebugConsole/Scripts/CopyLogsOnResizeButtonClick.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugins/IngameDebugConsole/Scripts/DebugLogManager.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ public class DebugLogManager : MonoBehaviour
126126
[Tooltip( "Width of the canvas determines whether the searchbar will be located inside the menu bar or underneath the menu bar. This way, the menu bar doesn't get too crowded on narrow screens. This value determines the minimum width of the canvas for the searchbar to appear inside the menu bar" )]
127127
private float topSearchbarMinWidth = 360f;
128128

129+
[SerializeField, HideInInspector]
130+
[Tooltip("If enabled, clicking the resize button of the console window will copy all logs to clipboard. It'll also play a scale animation to give feedback.")]
131+
internal bool copyAllLogsOnResizeButtonClick;
132+
129133
[SerializeField]
130134
[HideInInspector]
131135
[Tooltip( "If enabled, the console window will continue receiving logs in the background even if its GameObject is inactive. But the console window's GameObject needs to be activated at least once because its Awake function must be triggered for this to work" )]
@@ -1722,27 +1726,41 @@ private void FilterLogs()
17221726
OnLogEntriesUpdated( true, true );
17231727
}
17241728

1725-
public string GetAllLogs()
1729+
public string GetAllLogs()
1730+
{
1731+
return GetAllLogs(int.MaxValue, float.PositiveInfinity);
1732+
}
1733+
1734+
/// <param name="maxLogCount">Maximum allowed log count.</param>
1735+
/// <param name="maxElapsedTime">Maximum allowed time interval (in seconds) between now and the logs' arrival time (requires <see cref="captureLogTimestamps"/> to be enabled).</param>
1736+
public string GetAllLogs(int maxLogCount, float maxElapsedTime)
17261737
{
17271738
// Process all pending logs since we want to return "all" logs
17281739
ProcessQueuedLogs( queuedLogEntries.Count );
17291740

1730-
int count = uncollapsedLogEntries.Count;
1741+
int startIndex = uncollapsedLogEntries.Count - Mathf.Min(uncollapsedLogEntries.Count, maxLogCount);
1742+
if (uncollapsedLogEntriesTimestamps != null)
1743+
{
1744+
float currentElapsedSeconds = Time.realtimeSinceStartup;
1745+
while (startIndex < uncollapsedLogEntries.Count && currentElapsedSeconds - uncollapsedLogEntriesTimestamps[startIndex].elapsedSeconds > maxElapsedTime)
1746+
startIndex++;
1747+
}
1748+
17311749
int length = 0;
17321750
int newLineLength = System.Environment.NewLine.Length;
1733-
for( int i = 0; i < count; i++ )
1751+
for (int i = startIndex; i < uncollapsedLogEntries.Count; i++)
17341752
{
17351753
DebugLogEntry entry = uncollapsedLogEntries[i];
17361754
length += entry.logString.Length + entry.stackTrace.Length + newLineLength * 3;
17371755
}
17381756

1739-
if( uncollapsedLogEntriesTimestamps != null )
1740-
length += count * 30;
1757+
if (uncollapsedLogEntriesTimestamps != null)
1758+
length += (uncollapsedLogEntries.Count - startIndex) * 30;
17411759

17421760
length += 200; // Just in case...
17431761

17441762
StringBuilder sb = new StringBuilder( length );
1745-
for( int i = 0; i < count; i++ )
1763+
for (int i = startIndex; i < uncollapsedLogEntries.Count; i++)
17461764
{
17471765
DebugLogEntry entry = uncollapsedLogEntries[i];
17481766

0 commit comments

Comments
 (0)