Game.Prefabs.NotificationIconPrefabSystem
Assembly:
Game
Namespace:
Game.Prefabs
Type:
class
Base:
GameSystemBase
Summary:
A Unity ECS system that initializes and updates NotificationIconDisplayData for notification icon prefabs. The system queries entities that have NotificationIconData and PrefabData, reads the prefab definitions via PrefabSystem, assigns a unique icon index, transfers display size and pulsate amplitude ranges from the prefab into the NotificationIconDisplayData min/max parameters, and ensures a default category mask is applied when none is set. After updating display data it notifies the NotificationIconRenderSystem that display data changed.
Fields
-
private EntityQuery m_UpdatedQuery
This query is used to determine when the system should run. It matches entities with NotificationIconData and PrefabData and with either Created or Deleted flags. The system calls RequireForUpdate(m_UpdatedQuery) in OnCreate so the system only updates when this query has matching entities. -
private EntityQuery m_PrefabQuery
A query that matches entities with NotificationIconData and PrefabData but excludes Deleted. This query is used during OnUpdate to iterate the archetype chunks whose NotificationIconDisplayData need to be initialized/updated. -
private PrefabSystem m_PrefabSystem
Cached reference to the game's PrefabSystem used to resolve a PrefabData instance into a strongly-typed prefab (NotificationIconPrefab) so display parameters (size, pulsate amplitude) can be read. -
private NotificationIconRenderSystem m_NotificationIconRenderSystem
Cached reference to the render system that consumes NotificationIconDisplayData. The system calls m_NotificationIconRenderSystem.DisplayDataUpdated() after making changes so the renderer can react. -
private TypeHandle __TypeHandle
A private struct instance holding ComponentTypeHandle fields (see nested TypeHandle). It is used to get ComponentTypeHandle instances in OnUpdate via InternalCompilerInterface so chunk iteration can obtain NativeArrayfor PrefabData and NotificationIconDisplayData. -
private struct TypeHandle
Internal helper struct generated to store component type handles used during chunk iteration. -
[ReadOnly] public ComponentTypeHandle<PrefabData> __Game_Prefabs_PrefabData_RO_ComponentTypeHandle
A read-only handle for PrefabData components used to fetch the PrefabData array from a chunk. -
public ComponentTypeHandle<NotificationIconDisplayData> __Game_Prefabs_NotificationIconDisplayData_RW_ComponentTypeHandle
A read-write handle for NotificationIconDisplayData used to read/modify display data in-place. -
public void __AssignHandles(ref SystemState state)
An AggressiveInlining helper that assigns the component type handles from the given SystemState (calls state.GetComponentTypeHandle).
Properties
- (none)
This system does not expose public properties. All state is private to the system and accessed via fields and methods.
Constructors
public NotificationIconPrefabSystem()
Parameterless constructor. Marked with [Preserve] to avoid stripping. Initializes the system instance; real setup is performed in OnCreate / OnCreateForCompiler.
Methods
[Preserve] protected override void OnCreate()
Creates and configures queries and caches system references. It performs:- base.OnCreate()
- acquires PrefabSystem and NotificationIconRenderSystem via World.GetOrCreateSystemManaged
() - builds m_UpdatedQuery to require NotificationIconData + PrefabData and either Created or Deleted
- builds m_PrefabQuery to match NotificationIconData + PrefabData and exclude Deleted
-
calls RequireForUpdate(m_UpdatedQuery) so the system only runs when relevant entities change
-
[Preserve] protected override void OnUpdate()
Main update routine. Behavior: - Converts m_PrefabQuery to an ArchetypeChunk array (Allocator.TempJob) and iterates chunks.
- Uses the stored ComponentTypeHandle instances (via InternalCompilerInterface.GetComponentTypeHandle) to get NativeArray
and NativeArray for each chunk. - For each element:
- Resolves the NotificationIconPrefab using m_PrefabSystem.GetPrefab
(prefabData) - Assigns a unique sequential m_IconIndex (starting at 1)
- Copies min/max parameters: m_MinParams = (prefab.m_DisplaySize.min, prefab.m_PulsateAmplitude.min), m_MaxParams = (prefab.m_DisplaySize.max, prefab.m_PulsateAmplitude.max)
- Ensures a default category mask is applied when value.m_CategoryMask is zero: value.m_CategoryMask = math.select(2147483648u, value.m_CategoryMask, value.m_CategoryMask != 0)
- Writes the modified NotificationIconDisplayData back into the chunk array
- Resolves the NotificationIconPrefab using m_PrefabSystem.GetPrefab
- Properly disposes of the temporary chunk array in a finally block
- Calls m_NotificationIconRenderSystem.DisplayDataUpdated() to notify the renderer
Notes: - Uses Allocator.TempJob for the chunk array and must dispose it (the code does dispose in finally). - Reads PrefabData in read-only mode and writes NotificationIconDisplayData. - The default category mask value used is 2147483648u (0x80000000) when no mask is present.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler-generated stub that can initialize or validate any queries for compiler-specific code paths. In this build it creates and immediately disposes an EntityQueryBuilder with Allocator.Temp; used as part of OnCreateForCompiler. -
protected override void OnCreateForCompiler()
Calls base.OnCreateForCompiler(), then calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) so the compiler-generated handles/queries are assigned for Ahead-of-Time/IL2CPP scenarios. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] public void __AssignHandles(ref SystemState state)
(inside TypeHandle)
Assigns the ComponentTypeHandleand ComponentTypeHandle from the provided SystemState. This is used by OnCreateForCompiler to initialize the cached handles.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Cache systems the same way the system does:
m_PrefabSystem = World.GetOrCreateSystemManaged<PrefabSystem>();
m_NotificationIconRenderSystem = World.GetOrCreateSystemManaged<NotificationIconRenderSystem>();
// Create queries equivalent to the system's setup:
m_UpdatedQuery = GetEntityQuery(new EntityQueryDesc {
All = new ComponentType[] {
ComponentType.ReadOnly<NotificationIconData>(),
ComponentType.ReadOnly<PrefabData>()
},
Any = new ComponentType[] {
ComponentType.ReadOnly<Created>(),
ComponentType.ReadOnly<Deleted>()
}
});
m_PrefabQuery = GetEntityQuery(
ComponentType.ReadOnly<NotificationIconData>(),
ComponentType.ReadOnly<PrefabData>(),
ComponentType.Exclude<Deleted>());
RequireForUpdate(m_UpdatedQuery);
}
Notes and tips:
- Ensure PrefabData and NotificationIconData components are added to entities before this system runs so it can initialize NotificationIconDisplayData properly.
- The system relies on PrefabSystem.GetPrefab