NoticeCondition
Coding Style wiki
NoticeCondition is the notice condition base class (abstract class) of the NoticeSystem. Custom conditions inherit it and implement ShowCondition to decide whether the red dot shows, and are auto-assigned a condition ID once registered via NoticeManager.RegisterCondition. Condition templates can be created via Right-Click Create/OxGKit/Notice System/Template Notice Condition.cs (refer to the Module Intro).
| Namespace | OxGKit.NoticeSystem |
| Type | public abstract class NoticeCondition |
| Source | NoticeCondition.cs |
using OxGKit.NoticeSystem;
Quick Start
using OxGKit.NoticeSystem;
using UnityEngine;
public class NewMailCond : NoticeCondition
{
#region Default
// Convention: define a static property to get the auto-assigned condition ID
public static int id { get { return NoticeManager.GetConditionId<NewMailCond>(); } }
// Auto-register the condition before the scene loads (matches the BeforeSceneLoad template)
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Register()
{
NoticeManager.RegisterCondition<NewMailCond>();
}
#endregion
public override bool ShowCondition(object data)
{
if (data != null)
{
MailBox mailBox = data as MailBox;
// Show the red dot when there is unread mail
if (mailBox.unreadCount > 0) return true;
}
return false;
}
}
General Rules
- Condition classes are pure logic classes — do not hold MonoBehaviour state or scene references inside
ShowCondition. - The
datapassed toShowConditioncan benullor of a different type (when multiple UIs share the same condition) — perform defensive checks. - The condition ID is auto-assigned on registration by NoticeManager.RegisterCondition; by convention, define a static
idproperty in the condition class.
Reminder A NoticeItem holding multiple conditions uses OR logic (shown when any matches); for AND logic, put the whole predicate inside a single condition class's ShowCondition.
Method Overview
| Method | Description |
|---|---|
| SetId | Sets the condition ID (called automatically by NoticeManager on registration). |
| GetId | Gets the condition ID. |
| ShowCondition | (abstract) Decides from the data whether the condition matches (whether the red dot shows). |
SetId
public void SetId(int id)
Sets the condition ID.
Attention Called automatically by NoticeManager.RegisterCondition on registration — usually there is no need to call it yourself.
GetId
public int GetId()
Gets the condition ID (can also be queried by type via NoticeManager.GetConditionId<T>()).
ShowCondition
public abstract bool ShowCondition(object data)
Decides from the given data whether the condition matches — returning true means the red dot shows; data is the data passed in via NoticeInfo when registering on a NoticeItem.
NoticeInfo
Notice info (struct) containing the condition ID and the data to check, used as the registration unit for NoticeItem.RegisterNotice / RenewNotice.
| Type | public struct NoticeInfo |
| Source | NoticeInfo.cs |
Members
| Member | Description |
|---|---|
public int conditionId | The condition ID. |
public object data | The data handed to ShowCondition for the check (value type or reference type). |
Constructors
public NoticeInfo(int conditionId, object data)
// Reference-type data (Notify alone is enough after changes)
new NoticeInfo(NewMailCond.id, this._mailBox);
// Value-type data (RenewNotice to update the snapshot after changes, then Notify)
new NoticeInfo(CoinInWalletCond.id, this._coin);
Important Value-type data is stored as a snapshot — after the data changes, update it via NoticeItem.RenewNotice and then Notify, otherwise the red dot will not refresh.