NoticeItem
Coding Style wiki
NoticeItem is the notice component (MonoBehaviour) mounted on the red-dot icon (ICON). It holds condition ID and data (NoticeInfo) registrations and automatically shows its own GameObject when any held condition matches. Import the NoticeItem Prefab via Package Manager -> Samples and drag it onto the UI to use it directly, or mount it yourself via Add Component -> OxGKit -> NoticeSystem -> NoticeItem.
| Namespace | OxGKit.NoticeSystem |
| Type | [DisallowMultipleComponent] public class NoticeItem : MonoBehaviour |
| Source | NoticeItem.cs |
using OxGKit.NoticeSystem;
Quick Start
using OxGKit.NoticeSystem;
using UnityEngine;
public class MailUI : MonoBehaviour
{
// Drag the NoticeItem prefab onto the UI, then assign the reference
public NoticeItem mailNoticeItem;
private MailBox _mailBox = new MailBox();
private void Awake()
{
// Register the condition and data (registration auto-checks the condition and refreshes the display)
this.mailNoticeItem.RegisterNotice
(
new NoticeInfo(NewMailCond.id, this._mailBox)
);
}
public void ReceiveMail()
{
// After the data changes, notify to refresh the red-dot display
this._mailBox.unreadCount++;
this.mailNoticeItem.Notify();
}
}
General Rules
Visibility Rules
- A single NoticeItem can hold multiple conditions. It shows its own GameObject when any held condition matches (
ShowConditionreturnstrue) and hides it when none match (OR logic).
Important A NoticeItem toggles its own GameObject — make the red dot a child icon node under the button, do not mount it on the button itself, or the button will be hidden along with it.
Reminder For AND logic, put the whole predicate inside a single condition class's ShowCondition.
Auto Deregistration
Attention When a NoticeItem is OnDestroy, it automatically calls DeregisterNotice to remove all of its held conditions.
Reminder Recycling pooled UI does not trigger OnDestroy — call DeregisterNotice yourself on recycle to avoid stale registrations.
Value-Type Data
Important For value-type data (such as int), NoticeInfo.data stores a snapshot — after the data changes, you must update it via RenewNotice and then Notify; reference-type data is held by reference, so Notify alone is enough after changes.
Method Overview
| Method | Description |
|---|---|
| HasCondition | Checks whether the item holds the given condition ID. |
| Notify | Notifies all conditions held by this item to refresh the display. |
| RenewNotice | Renews the condition data (Method Chaining); auto-registers when not held. |
| RegisterNotice | Registers conditions with data, then auto-checks conditions and refreshes the display. |
| DeregisterNotice | Deregisters the given conditions (no arguments = deregister all). |
HasCondition
public bool HasCondition(int conditionId)
Checks whether this item holds a registration for the given condition ID.
if (this.mailNoticeItem.HasCondition(NewMailCond.id))
{
// ...
}
Notify
public void Notify()
Notifies all condition IDs held by this item through NoticeManager.Notify to refresh the display.
// After the data changes (reference type), notify directly to refresh
this._mailBox.unreadCount++;
this.mailNoticeItem.Notify();
RenewNotice
public NoticeItem RenewNotice(NoticeInfo noticeInfo)
Renews the data of the given condition (returns itself for Method Chaining); when the condition is not held yet, it automatically falls back to RegisterNotice.
// Value-type data is a snapshot — RenewNotice to update the data first, then Notify to refresh
this._coin++;
this.coinNoticeItem.RenewNotice(new NoticeInfo(CoinInWalletCond.id, this._coin)).Notify();
RegisterNotice
public void RegisterNotice(params NoticeInfo[] noticeInfos)
Registers conditions with data (NoticeInfo), then auto-checks the conditions and refreshes the display; registering the same condition again renews its data and notifies once more.
// A single NoticeItem can hold multiple conditions (the red dot shows when any condition matches)
this.walletNoticeItem.RegisterNotice
(
// Value-type data
new NoticeInfo(CoinInWalletCond.id, this._coin),
// Reference-type data
new NoticeInfo(CoinIsEvenCond.id, this._wallet)
);
Attention The condition must already be registered via NoticeManager.RegisterCondition beforehand, otherwise its condition ID cannot be resolved (returns 0).
DeregisterNotice
public void DeregisterNotice(params int[] conditionIds)
Deregisters the given condition IDs; called without arguments it deregisters all conditions held by this item, then re-checks the conditions and refreshes the display.
// Deregister specific conditions
this.walletNoticeItem.DeregisterNotice(CoinInWalletCond.id);
// No arguments => deregister all held conditions
this.walletNoticeItem.DeregisterNotice();
Reminder This method is called automatically on OnDestroy to deregister all held conditions — usually no manual handling is needed (except for pooled UI recycling).