Game.Tools.ApplyNotificationsSystem
Assembly: Assembly-CSharp
Namespace: Game.Tools
Type: class
Base: GameSystemBase
Summary:
ApplyNotificationsSystem is an ECS system that finalizes tool-produced temporary notification icons and applies them to their original (permanent) entities. It runs each frame (when Temp components exist) and schedules a Burst-compiled job (ApplyTempIconsJob) to process archetype chunks of Temp components. The job matches temporary icons to originals, merges or replaces existing icons when appropriate, removes or marks icons as deleted when they are temporary-only or invalid, and updates ownership and applied-state component sets via an EntityCommandBuffer produced by a ToolOutputBarrier. The system uses safe multi-threaded collections (NativeHashMap / NativeParallelMultiHashMap) and buffer lookups for IconElement linking, and respects ToolErrorData and Destroyed flags when deciding whether to keep or delete icons.
Fields
-
private ToolOutputBarrier m_ToolOutputBarrier
Holds a reference to the ToolOutputBarrier system. Used to create an EntityCommandBuffer to record structural and component changes from the worker job, and to register the job handle as a producer so the barrier can synchronize correctly. -
private EntityQuery m_TempQuery
An EntityQuery that selects entities with the Temp component. The system requires this query for update (RequireForUpdate). It is also used to produce an asynchronous archetype chunk list fed to the job. -
private ComponentTypeSet m_AppliedTypes
A ComponentTypeSet containing component types that mark an icon as applied: Applied, Created, and Updated. The job adds these types to entities when a temporary icon becomes a permanent/applied icon. -
private TypeHandle __TypeHandle
Internal container of entity/component/buffer lookup handles (EntityTypeHandle, component type handles for Temp, Icon, Owner, PrefabRef, buffer type handle for IconElement, and ComponentLookup/BufferLookup instances). __TypeHandle.__AssignHandles(ref SystemState) initializes these handles before use in jobs.
Properties
- This system exposes no public properties.
Constructors
public ApplyNotificationsSystem()
Parameterless constructor. The class is preserved for runtime linking by the [Preserve] attribute on lifecycle methods. Initialization of runtime state is done in OnCreate rather than the constructor.
Methods
-
protected override void OnCreate()
Called when the system is created. Retrieves or creates the ToolOutputBarrier system reference, builds the EntityQuery for Temp components, creates the ComponentTypeSet for applied types (Applied, Created, Updated), and calls RequireForUpdate(m_TempQuery) so the system only updates when Temp entities exist. -
protected override void OnUpdate()
Main update function. Builds an asynchronous archetype chunk list from m_TempQuery (ToArchetypeChunkListAsync), then schedules the Burst-compiled ApplyTempIconsJob with the chunk list, relevant type handles & lookups, the applied-types set, and an EntityCommandBuffer from m_ToolOutputBarrier. It disposes of the chunk list with the returned job handle and registers the job handle with the barrier. The job will perform component changes via the ECB. -
protected override void OnCreateForCompiler()
Compiler-time helper that assigns queries and component/buffer handles on systems compiled with the source generator / job interface. Calls __AssignQueries and __TypeHandle.__AssignHandles. -
private void __AssignQueries(ref SystemState state)
Internal method that sets up any entity queries required for the compiler path. In this class it currently contains an EntityQueryBuilder placeholder (no persistent queries added here because m_TempQuery is created in OnCreate).
Nested types / job methods (key behaviors):
private struct ApplyTempIconsJob : IJob
Burst-compiled worker job that processes the archetype chunks. High-level responsibilities:- Count total entities across provided chunks to size NativeParallelMultiHashMap and NativeHashMap.
- Iterate chunks. For chunks that have Icon component:
- Iterate entities, consult Owner and PrefabRef, check ToolErrorData to see if the prefab is temporary-only.
- If Owner refers to a Temp container whose Temp.m_Original is set:
- If prefab is temporary-only -> add Deleted to the temporary icon entity.
- Else -> add a mapping from original -> temporary-icon entity in nativeParallelMultiHashMap and ensure original appears in nativeHashMap keys.
- If Owner has no Temp component -> mark the icon entity Deleted.
- If Temp.m_Original == Entity.Null and not temporary-only -> remove Temp and add the applied types to the icon entity.
- For chunks without Icon component (i.e., Temp-only entities), check Temp.m_Original and optionally remove IconElement buffer from the temporary container.
- After the first pass, iterate each original entity (keys in nativeHashMap):
- Collect existing IconElement buffer entries (if any) into a temporary list.
- For each temporary icon mapped to the original via nativeParallelMultiHashMap:
- If an existing icon in the buffer matches same prefab & same Target -> treat as a merge: copy cluster index, mark existing icon Updated, mark temporary entity Deleted, and add the existing icon back to the new IconElement buffer.
- Else -> add the temporary icon to the original's IconElement buffer, set Owner to the original, remove Temp from the icon, and add "applied" component types.
- For any leftover old icons in the buffer that were not matched, ValidateOldIcon(icon, original, tempContainer) determines whether to keep or mark Deleted (considers ToolErrorData and Destroyed flags).
- If no resulting IconElement buffer entries remain, remove IconElement from the original entity.
-
Uses EntityCommandBuffer to do all structural and component changes.
-
private bool ApplyTempIconsJob.ValidateOldIcon(Entity icon, Entity container, Entity tempContainer)
Validation helper used by the job to decide whether an old icon should be kept on the original entity. It returns false if the icon's prefab has ToolErrorData (tool-only/invalid), or if the original container is destroyed and the icon has very high priority (>= 250) and the tempContainer is not destroyed — in those cases the old icon should be deleted. Otherwise returns true. -
private struct TypeHandle.__AssignHandles(ref SystemState state)
Populates all EntityTypeHandle, ComponentTypeHandle, BufferTypeHandle, ComponentLookup and BufferLookup fields from the provided SystemState (used prior to scheduling the job so the job has correct handles for current frame).
Notes on concurrency & performance: - ApplyTempIconsJob is Burst-compiled and uses parallel-friendly native collections to avoid race conditions while grouping temporary icons by their original. - Structural changes are recorded into an EntityCommandBuffer created by the ToolOutputBarrier; the job is registered as a producer of that ECB. - The temporary native collections and lists are allocated with Allocator.Temp and disposed within Execute; archetype chunk list is disposed in OnUpdate with the scheduled job handle.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_ToolOutputBarrier = base.World.GetOrCreateSystemManaged<ToolOutputBarrier>();
m_TempQuery = GetEntityQuery(ComponentType.ReadOnly<Temp>());
m_AppliedTypes = new ComponentTypeSet(
ComponentType.ReadWrite<Applied>(),
ComponentType.ReadWrite<Created>(),
ComponentType.ReadWrite<Updated>());
RequireForUpdate(m_TempQuery);
}
[Preserve]
protected override void OnUpdate()
{
// The system schedules a Burst job that processes Temp/icon entities and uses
// m_ToolOutputBarrier.CreateCommandBuffer() for structural changes.
}
If you need a shorter summary, an entity/ component map, or documentation for the related component types (Temp, Icon, Owner, IconElement, PrefabRef, ToolErrorData, Applied/Created/Updated), tell me which ones and I can add separate reference entries.