Skip to main content

NoticeManager

Important Attention Reminder

Coding Style wiki


NoticeManager is the static notice manager (the core of the red dot system) of the NoticeSystem. It handles registration of notice conditions (NoticeCondition) and condition ID lookup, and when data changes it uses Notify to look up the NoticeItems holding a condition by its ID and refresh their display.

NamespaceOxGKit.NoticeSystem
Typepublic static class NoticeManager
SourceNoticeManager.cs
using OxGKit.NoticeSystem;

Quick Start

using OxGKit.NoticeSystem;

// 1. Register the notice condition (once at startup)
NoticeManager.RegisterCondition<NewMailCond>();

// 2. Register the condition and data on a NoticeItem (condition ID + data)
this.mailNoticeItem.RegisterNotice(new NoticeInfo(NewMailCond.id, this._mailBox));

// 3. When data changes, notify the condition ID to refresh the red-dot display
this._mailBox.unreadCount++;
NoticeManager.Notify(NewMailCond.id);

General Rules

Condition ID

  • Condition IDs are auto-assigned when registering via RegisterCondition (the condition type is the unique key).
  • By convention, define a static id property in the condition class and get the ID via GetConditionId:
public class NewMailCond : NoticeCondition
{
public static int id { get { return NoticeManager.GetConditionId<NewMailCond>(); } }

public override bool ShowCondition(object data) { /* ... */ }
}

Important A condition must be registered with RegisterCondition before its ID can be resolved by GetConditionId (returns 0 when unregistered).

Notify & Refresh Flow

  1. Data state changes.
  2. Call Notify with the condition IDs.
  3. NoticeManager looks up all NoticeItems holding those conditions by ID.
  4. Each NoticeItem re-runs its condition checks (ShowCondition) — shown when any condition matches, hidden when none do.

Reminder During Notify, registrations of already destroyed NoticeItems are removed automatically — no need to worry about stale references.


Method Overview

MethodDescription
RegisterConditionRegisters a notice condition (auto-assigns the condition ID).
GetConditionIdGets a notice condition ID.
NotifyNotifies by condition IDs or NoticeItems to refresh the display when data changes.

RegisterCondition

public static void RegisterCondition<TNoticeCondition>() where TNoticeCondition : NoticeCondition, new()

Registers a notice condition (creates the condition instance and auto-assigns its condition ID). Conditions can be added dynamically at runtime.

NoticeManager.RegisterCondition<NewMailCond>();
NoticeManager.RegisterCondition<CoinInWalletCond>();

Attention Registering the same condition twice is ignored and logs a warning.

GetConditionId

public static int GetConditionId<TNoticeCondition>() where TNoticeCondition : NoticeCondition

Gets the condition ID of a notice condition.

int conditionId = NoticeManager.GetConditionId<NewMailCond>();

Attention Returns 0 when the condition is not yet registered — register it first via RegisterCondition.

Notify

// Single condition ID (non-alloc)
public static void Notify(int conditionId)

// Multiple condition IDs
public static void Notify(params int[] conditionIds)

// Notify by NoticeItems (collects their held condition IDs and removes duplicates)
public static void Notify(params NoticeItem[] noticeItems)

Notifies on data changes — looks up all NoticeItems holding the conditions by ID, then performs the condition checks and refreshes the display.

  • Notify by condition IDs: pass the condition IDs directly (the single-ID overload is non-alloc, best efficiency).
  • Notify by NoticeItems: automatically collects the condition IDs held by the given NoticeItems, removes duplicates, then notifies them in one pass (avoids refreshing the same condition repeatedly).
// Data changes
this._wallet.IncreaseCoin();

// Single condition ID (non-alloc)
NoticeManager.Notify(CoinInWalletCond.id);

// Multiple condition IDs
NoticeManager.Notify(CoinInWalletCond.id, CoinIsEvenCond.id);

// Notify by NoticeItems
NoticeManager.Notify(this.walletNoticeItem, this.coinNoticeItem);

Important After data changes you must Notify the related condition IDs, otherwise the red-dot display will not refresh; for value-type data, update the data snapshot first via NoticeItem.RenewNotice, then Notify.

Attention Notifying an unregistered condition ID logs an error (Error Notice Condition Cannot find).