Skip to content

Game.Notifications.IconAnimationSystem

Assembly: Assembly-CSharp
Namespace: Game.Notifications

Type: class

Base: GameSystemBase

Summary: System that advances per-entity icon animations each frame. It schedules a Burst-compiled IJobChunk (IconAnimationJob) which iterates entities matching the Animation+Icon query, increments Animation.m_Timer by Time.deltaTime, and when an animation reaches its duration records structural changes via a ModificationBarrier5-created EntityCommandBuffer. Depending on Animation.m_Type the job either removes the Animation component and adds an Updated marker, or marks the entity as Deleted. The system uses an EntityQuery to require update only when animations exist and integrates with the modification barrier to safely issue structural changes from a parallel job.


Fields

  • private ModificationBarrier5 m_ModificationBarrier Used to obtain an EntityCommandBuffer (parallel writer) that records structural changes produced by the parallel IJobChunk. The system registers the job handle with this barrier so the barrier can play back changes safely.

  • private Unity.Entities.EntityQuery m_AnimationQuery EntityQuery selecting entities to process: ReadWrite(), ReadOnly(), and exclude Deleted(). This query is passed to ScheduleParallel so the IconAnimationJob only executes where relevant.

  • private TypeHandle __TypeHandle Compiler-generated helper struct instance that stores EntityTypeHandle and ComponentTypeHandle. It is assigned in OnCreateForCompiler and later used to get handles for the scheduled job.

Properties

  • None exposed by this system.

Constructors

  • public IconAnimationSystem() Default constructor (preserved). No custom initialization beyond base.

Methods

  • protected override void OnCreate() : System.Void Initializes the system:
  • Retrieves/creates the ModificationBarrier5 from the World.
  • Builds the EntityQuery to match Animation + Icon and exclude Deleted.
  • Calls RequireForUpdate(m_AnimationQuery) so the system only runs when matching entities exist.

  • protected override void OnUpdate() : System.Void Schedules the IconAnimationJob in parallel:

  • Obtains EntityTypeHandle and ComponentTypeHandle via InternalCompilerInterface and the stored __TypeHandle.
  • Captures Time.deltaTime.
  • Creates a parallel EntityCommandBuffer from the modification barrier.
  • Schedules the job with JobChunkExtensions.ScheduleParallel and the m_AnimationQuery using the current base.Dependency.
  • Registers the returned job handle with the modification barrier via AddJobHandleForProducer and assigns it to base.Dependency.

  • private void __AssignQueries(ref SystemState state) : System.Void Compiler helper that currently constructs and disposes an empty EntityQueryBuilder(Allocator.Temp). Present for compiler-generated query assignment needs.

  • protected override void OnCreateForCompiler() : System.Void Called by generated code path to prepare type handles and queries for the Burst/Jobs usage:

  • Calls base.OnCreateForCompiler().
  • Calls __AssignQueries to satisfy compiler expectations.
  • Calls __TypeHandle.__AssignHandles to populate EntityTypeHandle and ComponentTypeHandle.

  • (Nested) IconAnimationJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void Job behavior:

  • Gets NativeArray and NativeArray for the chunk.
  • For each Animation in the chunk:
    • Increments Animation.m_Timer by m_DeltaTime.
    • Switches on Animation.m_Type:
    • MarkerAppear or WarningAppear: if m_Timer >= m_Duration -> remove Animation component and add Updated marker.
    • MarkerDisappear, WarningResolve, Transaction: if m_Timer >= m_Duration -> add Deleted marker.
    • Writes the updated Animation back to the component array.
  • Structural changes are enqueued via EntityCommandBuffer.ParallelWriter using unfilteredChunkIndex as the parallel index.
  • The job is Burst-compiled and implements IJobChunk.

  • (Nested) TypeHandle.__AssignHandles(ref SystemState state) : System.Void Assigns the EntityTypeHandle and ComponentTypeHandle from the provided SystemState.

Usage Example

// Example: create an entity with an Icon and an Animation so IconAnimationSystem will update it.
// (This code typically runs in another system or initialization code.)

var em = World.DefaultGameObjectInjectionWorld.EntityManager;

// Define archetype / create entity
EntityArchetype archetype = em.CreateArchetype(
    typeof(Game.Notifications.Animation),
    typeof(Game.Notifications.Icon)
);

// Create an entity and initialize Animation
Entity e = em.CreateEntity(archetype);

var anim = new Game.Notifications.Animation
{
    m_Type = Game.Notifications.AnimationType.MarkerAppear,
    m_Duration = 1.0f,   // 1 second animation
    m_Timer = 0f
};

em.SetComponentData(e, anim);

// After running the simulation for >= 1 second, IconAnimationSystem will remove the Animation
// component and add an Updated marker (for MarkerAppear). For other animation types the system
// may instead add a Deleted marker when the duration elapses.

Notes and implementation details: - The job uses m_CommandBuffer.RemoveComponent and AddComponent or AddComponent to perform structural changes; these are recorded and applied by the ModificationBarrier5 playback. - The system uses InternalCompilerInterface to obtain handles from the stored TypeHandle; this pattern is typical in generated/system code that needs stable handles across updates. - The IconAnimationJob is Burst-compiled for performance; ensure any changes to Animation fields remain Burst-compatible.