Skip to content

Commit

Permalink
feat: Refresh on message count changed
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarianZ committed Nov 13, 2024
1 parent ce6d52d commit 13075ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Editor/MessageBanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public bool ShowMessageTypeCount
public IList<Message> Messages { get; private set; }
public int CurrentMessageIndex { get; private set; }

private int _messageCountCache;


public MessageBanner(object source, string sourceName,
bool showMessageTypeCount = true, bool allowClearMessages = false)
Expand Down Expand Up @@ -116,6 +118,14 @@ public MessageBanner(IList<Message> messages, object source, string sourceName,
RegisterCallback<ContextClickEvent>(OnContextClick);

InitializeMessageSwitch();

schedule.Execute(() =>
{
if ((Messages?.Count ?? 0) != _messageCountCache)
{
Refresh();
}
}).Every(200);
}

private Image CreateMessageTypeImage(Texture defaultIcon)
Expand Down Expand Up @@ -160,8 +170,8 @@ public void Refresh()
// ReSharper disable once PossibleNullReferenceException
Message message = CurrentMessageIndex > -1 ? Messages[CurrentMessageIndex] : null;
SetMessage(message);

Messages.CountByType(out int infoCount, out int warningCount, out int errorCount);
_messageCountCache = Messages?.Count ?? 0;
SetMessageCount(MessageType.Info, infoCount);
SetMessageCount(MessageType.Warning, warningCount);
SetMessageCount(MessageType.Error, errorCount);
Expand Down
4 changes: 2 additions & 2 deletions Editor/MessageViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void CreateGUI()

private void Update()
{
if (Messages != null && Messages.Count != _messageCountCache)
if ((Messages?.Count ?? 0) != _messageCountCache)
{
Refresh();
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public void Refresh()
_tagList.Insert(0, TagAll);

Messages.CountByType(out int infoCount, out int warningCount, out int errorCount);
_messageCountCache = infoCount + warningCount + errorCount;
_messageCountCache = Messages?.Count ?? 0;
_infoMessageToggle.SetMessageCount(infoCount);
_warningMessageToggle.SetMessageCount(warningCount);
_errorMessageToggle.SetMessageCount(errorCount);
Expand Down

0 comments on commit 13075ba

Please sign in to comment.