diff --git a/Editor/MessageBanner.cs b/Editor/MessageBanner.cs index bb8e2ec..3739ff5 100644 --- a/Editor/MessageBanner.cs +++ b/Editor/MessageBanner.cs @@ -37,6 +37,8 @@ public bool ShowMessageTypeCount public IList 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) @@ -116,6 +118,14 @@ public MessageBanner(IList messages, object source, string sourceName, RegisterCallback(OnContextClick); InitializeMessageSwitch(); + + schedule.Execute(() => + { + if ((Messages?.Count ?? 0) != _messageCountCache) + { + Refresh(); + } + }).Every(200); } private Image CreateMessageTypeImage(Texture defaultIcon) @@ -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); diff --git a/Editor/MessageViewer.cs b/Editor/MessageViewer.cs index 2f505d0..f40f946 100644 --- a/Editor/MessageViewer.cs +++ b/Editor/MessageViewer.cs @@ -325,7 +325,7 @@ private void CreateGUI() private void Update() { - if (Messages != null && Messages.Count != _messageCountCache) + if ((Messages?.Count ?? 0) != _messageCountCache) { Refresh(); } @@ -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);