Skip to content

Commit

Permalink
Add show only last message in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanaiKama committed Aug 19, 2020
1 parent b673096 commit 2cdba4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.meta
/.vs/slnx.sqlite
/.vs/ProjectSettings.json
8 changes: 7 additions & 1 deletion Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Console : MonoBehaviour
/// </summary>
public bool shakeToOpen = true;

private bool onlyLastMessage = false;
/// <summary>
/// Also require touches while shaking to avoid accidental shakes.
/// </summary>
Expand Down Expand Up @@ -69,6 +70,7 @@ class Console : MonoBehaviour
#endregion

static readonly GUIContent clearLabel = new GUIContent("Clear", "Clear the contents of the console.");
static readonly GUIContent onlyOne = new GUIContent("Show Only Last Message", "Show only last messages.");
static readonly GUIContent collapseLabel = new GUIContent("Collapse", "Hide repeated messages.");
const int margin = 20;
const string windowTitle = "Console";
Expand Down Expand Up @@ -201,7 +203,10 @@ void DrawLogList()
GUILayout.BeginVertical();

var visibleLogs = logs.Where(IsLogVisible);

if (onlyLastMessage)
{
visibleLogs = new List<Log> { visibleLogs.Last() };
}
foreach (Log log in visibleLogs)
{
DrawLog(log, logStyle, badgeStyle);
Expand Down Expand Up @@ -237,6 +242,7 @@ void DrawToolbar()
}

isCollapsed = GUILayout.Toggle(isCollapsed, collapseLabel, GUILayout.ExpandWidth(false));
onlyLastMessage = GUILayout.Toggle(onlyLastMessage, onlyOne, GUILayout.ExpandWidth(false));

GUILayout.EndHorizontal();
}
Expand Down

0 comments on commit 2cdba4d

Please sign in to comment.