Skip to content

Game.NotificationIconRenderSystem

Assembly: Assembly-CSharp.dll
Namespace: Game.Rendering

Type: class

Base: GameSystemBase

Summary:
NotificationIconRenderSystem is an ECS system responsible for rendering notification icons (UI overlays) using GPU instanced indirect draws. It gathers icon instance data from NotificationIconBufferSystem, builds a quad mesh, a material (with a Texture2DArray composed from NotificationIconPrefabs and a missing-icon fallback from an IconConfigurationPrefab), maintains ComputeBuffers for indirect draw arguments and instance data, and issues Graphics.DrawMeshInstancedIndirect calls for Game and SceneView cameras. The system subscribes to RenderPipelineManager.beginContextRendering to perform rendering and handles resource creation / cleanup (mesh, material, texture array, compute buffers).


Fields

  • private struct TypeHandle
    Holds ComponentTypeHandle instances for PrefabData and NotificationIconDisplayData. Used to obtain component arrays from archetype chunks when building the texture array. Contains an __AssignHandles method that initializes the handles from a SystemState.

  • private PrefabSystem m_PrefabSystem
    Reference to the game's PrefabSystem. Used to resolve IconConfigurationPrefab and NotificationIconPrefab instances.

  • private NotificationIconBufferSystem m_BufferSystem
    Reference to the NotificationIconBufferSystem that provides the per-instance data buffer (InstanceData[]) and icon bounds.

  • private RenderingSystem m_RenderingSystem
    Reference to the RenderingSystem used to check overlay visibility (hideOverlay) and related context.

  • private Mesh m_Mesh
    Quad mesh used for rendering a single icon instance (created lazily by GetMesh()).

  • private Material m_Material
    Material used for rendering icons. Created from the IconConfigurationPrefab material and assigned a Texture2DArray containing all icon textures.

  • private ComputeBuffer m_ArgsBuffer
    ComputeBuffer used for indirect draw arguments (DrawMeshInstancedIndirect). Created lazily by GetArgsBuffer().

  • private ComputeBuffer m_InstanceBuffer
    ComputeBuffer holding per-instance data uploaded from NotificationIconBufferSystem.InstanceData. Managed by GetInstanceBuffer(int).

  • private Texture2DArray m_TextureArray
    Texture2DArray containing all icon textures (and a missing-icon fallback at index 0). Built in GetMaterial() by copying textures from prefabs.

  • private uint[] m_ArgsArray
    Managed uint[] backing for m_ArgsBuffer data (index count, instance count, etc.).

  • private EntityQuery m_ConfigurationQuery
    EntityQuery used to find the singleton IconConfigurationData (to get the IconConfigurationPrefab).

  • private EntityQuery m_PrefabQuery
    EntityQuery used to enumerate entities that have NotificationIconData and PrefabData to discover all NotificationIconPrefabs and their icons.

  • private int m_InstanceBufferID
    Shader property ID (from Shader.PropertyToID("instanceBuffer")) used to bind the instance compute buffer to the material.

  • private bool m_UpdateBuffer
    Flag set in OnUpdate to indicate the instance buffer must be refreshed prior to rendering.

  • private TypeHandle __TypeHandle
    Instance of the inner TypeHandle struct used to get component type handles for chunk access.

Properties

  • None (this system exposes no public properties).

Constructors

  • public NotificationIconRenderSystem()
    Default constructor (marked [Preserve] in the original source). No special initialization beyond what the ECS framework performs; resource setup is performed in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes references to PrefabSystem, NotificationIconBufferSystem and RenderingSystem; creates EntityQueries for icon configuration and prefabs; caches the shader property ID for instanceBuffer; registers the Render callback with RenderPipelineManager.beginContextRendering; calls RequireForUpdate on the configuration query so the system only runs when an IconConfigurationData singleton exists.

  • protected override void OnDestroy()
    Unregisters the Render callback and releases/destroys created resources: quad mesh, material, ComputeBuffers (args & instance), and the Texture2DArray. Calls base.OnDestroy().

  • protected override void OnUpdate()
    Marks m_UpdateBuffer = true so the instance compute buffer will be updated before the next render.

  • public void DisplayDataUpdated()
    Called when display data (icon textures/material) changes. Forces the material and texture array to be recreated by destroying the existing ones; next render will rebuild them via GetMaterial().

  • private void Render(ScriptableRenderContext context, List<Camera> cameras)
    Render callback invoked by the render pipeline. Steps:

  • Checks renderingSystem.hideOverlay and returns early if overlays are hidden.
  • Gets icon instance data from NotificationIconBufferSystem. Returns early if no instances exist.
  • Prepares bounds for the draw using icon bounds.
  • Acquires mesh, material, and args buffer (lazily creating them).
  • Fills the arguments buffer (index count, instance count, index start, base vertex).
  • If m_UpdateBuffer is set, uploads instance data to the instance compute buffer and assigns it to the material.
  • Iterates cameras and calls Graphics.DrawMeshInstancedIndirect for Game and SceneView camera types with ShadowCastingMode.Off and receiveShadows = false.
  • The method is robust to no-op conditions (empty instance array, missing buffers).

  • private Mesh GetMesh()
    Lazily creates and returns a 2D quad Mesh named "Notification icon" with 4 vertices, UVs and two triangles. Cached in m_Mesh.

  • private Material GetMaterial()
    Lazily creates and returns the material used for icons:

  • Retrieves the IconConfigurationPrefab from the singleton IconConfigurationData entity via m_PrefabSystem.
  • Clones its material (new Material(prefab.m_Material)) and names it.
  • Iterates all archetype chunks matching m_PrefabQuery to discover the number of distinct icon indices and maximum icon size/format among available NotificationIconPrefabs (uses internal component type handles stored in __TypeHandle).
  • Creates a Texture2DArray sized to hold all icons (including a missing-icon at index 0).
  • Copies the missing-icon into layer 0 and copies each prefab icon into its designated index via Graphics.CopyTexture.
  • Assigns the Texture2DArray to material.mainTexture.
  • Disposes temporary chunk arrays properly.
  • Note: this method relies on ComponentTypeHandle access and archetype chunk iteration; it uses m_PrefabSystem.GetPrefab(PrefabData) to get per-prefab textures.

  • private ComputeBuffer GetArgsBuffer()
    Creates and caches a ComputeBuffer for indirect draw args (one entry) sized for 5 uints (made into DrawIndirect type) and a backing uint[] (m_ArgsArray). Named "Notification args buffer".

  • private unsafe ComputeBuffer GetInstanceBuffer(int count)
    Ensures m_InstanceBuffer is large enough to hold 'count' instances. If existing buffer is too small, it is released and a new one of increased size is created (doubling strategy). Minimum initial size is 64. Buffer stride equals sizeof(NotificationIconBufferSystem.InstanceData). Named "Notification instance buffer". Returns the buffer to use for instance uploads.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler helper stub used in OnCreateForCompiler in the decompiled code. In this source it does no work (creates and disposes a temporary EntityQueryBuilder).

  • protected override void OnCreateForCompiler()
    Compiler helper that calls __AssignQueries and __TypeHandle.__AssignHandles to initialize handles for ahead-of-time compiled systems. Used by the generated code path.

Usage Example

// The system is created/managed by the World/Worlds used by the game.
// To force the instance buffer to be updated next frame (e.g. after you changed instance data):
var sys = world.GetOrCreateSystemManaged<Game.Rendering.NotificationIconRenderSystem>();
// Trigger a buffer refresh (OnUpdate sets m_UpdateBuffer so render will upload new data).
sys.Update(); // or let ECS call OnUpdate during normal system ticks

// If you changed icon textures or prefab configuration, notify the renderer to rebuild its material/texture array:
sys.DisplayDataUpdated();

Notes and tips: - The system relies on NotificationIconBufferSystem.InstanceData layout. Ensure any manual changes to that struct keep the same memory layout if you interact with the instance buffer. - Building the Texture2DArray copies textures via Graphics.CopyTexture; icon source textures must be compatible in format and size or the code chooses a maximum size/format discovered among prefabs. - The system uses DrawMeshInstancedIndirect for performance with potentially many icons; ensure the GPU supports the required features and that the shader used by the material reads the structured instance buffer bound as "instanceBuffer". - Call DisplayDataUpdated() whenever icon images or the source prefab textures change to force a rebuild of the material/texture array.