Skip to content

Game.Notifications.RaycastJobs.RaycastIconsJob

Assembly:
Game (inferred from namespace; adjust to your mod assembly if different)

Namespace:
Game.Notifications

Type:
struct (public) — nested in static class Game.Notifications.RaycastJobs

Base:
Unity.Jobs.IJobParallelFor

Summary:
Burst-compiled parallel job that performs raycasts against notification icons and icon clusters. It checks both icon clusters (grouped icons used for LOD / density management) and individual icon archetype chunks, validates hits against owner objects and placeholders, and accumulates RaycastResult entries into a NativeAccumulator. Designed to be scheduled across many raycast inputs (m_Input) in parallel. Uses several ECS handles and ComponentLookup structures to read icon and owner component data. Note: m_Results uses NativeDisableContainerSafetyRestriction and is expected to be the ParallelWriter of a NativeAccumulator created outside the job.


Fields

  • public NativeArray<RaycastInput> m_Input
    Array of raycast requests. Each RaycastInput encodes a line, the requested TypeMask (static/moving/icons), icon layer mask, flags and other raycast parameters. The job processes one input per Execute(index) invocation.

  • public float3 m_CameraUp
    Camera up vector used to position icon quads in world space for intersection tests.

  • public float3 m_CameraRight
    Camera right vector used to position icon quads in world space for intersection tests.

  • public IconClusterSystem.ClusterData m_ClusterData
    Read-only cluster spatial index / data for icon clusters. Used to query cluster roots, subclusters and icons inside clusters.

  • public NativeList<ArchetypeChunk> m_IconChunks
    List of archetype chunks that contain Icon components. Iterated to check per-icon hit tests when clusters are not used.

  • public EntityTypeHandle m_EntityType
    Entity type handle used to retrieve entity IDs from chunks.

  • public ComponentTypeHandle<Icon> m_IconType
    Component type handle for reading Icon components from chunks.

  • public ComponentTypeHandle<PrefabRef> m_PrefabRefType
    Component type handle for reading PrefabRef components from chunks (used to get prefab for display data).

  • public ComponentLookup<Owner> m_OwnerData
    ComponentLookup for Owner component (maps an entity to its owner). Used to walk ownership chains when resolving a hit result to real game objects.

  • public ComponentLookup<Temp> m_TempData
    ComponentLookup used to check for Temp components; temp icons are ignored in cluster tests.

  • public ComponentLookup<Static> m_StaticData
    ComponentLookup to detect static objects. Static objects are treated differently depending on input.m_TypeMask.

  • public ComponentLookup<Object> m_ObjectData
    ComponentLookup presence check to ensure the owner resolves to a valid object entity.

  • public ComponentLookup<Transform> m_TransformData
    ComponentLookup to read Transform (position) when placeholder or static objects require translation of hit position.

  • public ComponentLookup<Placeholder> m_PlaceholderData
    ComponentLookup used to identify placeholders; placeholders can optionally be ignored by CheckPlaceholder depending on RaycastFlags.

  • public ComponentLookup<Attachment> m_AttachmentData
    ComponentLookup to detect attachments; used to resolve attached entities to their parent transform when a placeholder is attached to another object.

  • public ComponentLookup<CullingInfo> m_CullingInfoData
    ComponentLookup used to get culling bounds / center for moving objects to compute a hit position.

  • public ComponentLookup<NotificationIconDisplayData> m_IconDisplayData
    Lookup table providing display parameters per prefab (min/max params used to compute icon screen size / radius).

  • NativeDisableContainerSafetyRestriction
    public NativeAccumulator<RaycastResult>.ParallelWriter m_Results
    Parallel writer to a NativeAccumulator that collects RaycastResult values produced by the job. Marked with NativeDisableContainerSafetyRestriction — the caller must ensure safe usage and that the accumulator is correctly created and disposed outside the job.

Properties

  • None (this job type exposes only public fields to be assigned before scheduling)

Constructors

  • public RaycastIconsJob() (default struct constructor)
    Default value-type constructor. All fields must be initialized by the caller before scheduling the job. There is no custom constructor in the source.

Methods

  • public void Execute(int index) : System.Void
    Entry point for the parallel job for a single raycast input at m_Input[index]. Checks the input TypeMask to decide whether to process clusters and/or icon chunks, then delegates to CheckClusters and CheckChunks accordingly.

  • private void CheckClusters(int raycastIndex, RaycastInput input) : System.Void
    Performs hit tests against icon clusters. Traverses cluster roots, prunes clusters using distance and cluster radii, optionally subdivides to subclusters, and checks individual icons inside clusters for intersection with the ray. Uses m_CameraRight / m_CameraUp to compute icon quad positions. Valid hits are validated via ValidateResult and accumulated.

  • private void CheckChunks(int raycastIndex, RaycastInput input) : System.Void
    Iterates provided archetype chunks (m_IconChunks) containing Icon components, reads Icon and PrefabRef for each entity, computes per-icon radius from NotificationIconDisplayData and priority, performs distance/intersection tests against the ray, constructs a RaycastResult and passes it to ValidateResult.

  • private void ValidateResult(int raycastIndex, RaycastInput input, RaycastResult result, IconClusterLayer layer) : System.Void
    Validates a potential hit result against icon layer mask and owner/component restrictions. Walks the Owner chain to resolve to an actual object entity, checks static/moving object filtering based on input.m_TypeMask, handles placeholders and attachments, updates hit positions from Transform or CullingInfo as appropriate, and accumulates accepted RaycastResult instances to m_Results.

  • private bool CheckPlaceholder(RaycastInput input, ref Entity entity) : System.Boolean
    Helper to decide whether a placeholder entity should be treated as a valid hit. If RaycastFlags.Placeholders flag is set it returns true. If the entity has a Placeholder component and an Attachment mapping, attempts to resolve attached entity's Transform and update the reference; otherwise returns false to ignore placeholder hits.

Usage Example

// Example scheduling pattern (simplified):
var inputs = new NativeArray<RaycastInput>(count, Allocator.TempJob);
// fill inputs...

var resultsAccumulator = new NativeAccumulator<RaycastResult>(Allocator.TempJob);
var job = new RaycastJobs.RaycastIconsJob
{
    m_Input = inputs,
    m_CameraUp = cameraUp,
    m_CameraRight = cameraRight,
    m_ClusterData = clusterData,
    m_IconChunks = iconChunks,
    m_EntityType = entityTypeHandle,
    m_IconType = iconTypeHandle,
    m_PrefabRefType = prefabRefTypeHandle,
    m_OwnerData = ownerLookup,
    m_TempData = tempLookup,
    m_StaticData = staticLookup,
    m_ObjectData = objectLookup,
    m_TransformData = transformLookup,
    m_PlaceholderData = placeholderLookup,
    m_AttachmentData = attachmentLookup,
    m_CullingInfoData = cullingInfoLookup,
    m_IconDisplayData = iconDisplayDataLookup,
    m_Results = resultsAccumulator.AsParallelWriter()
};

// schedule with an appropriate batch size; tune for performance
JobHandle handle = job.Schedule(inputs.Length, 64);
handle.Complete();

// read resultsAccumulator into a NativeList/array as appropriate
// cleanup
resultsAccumulator.Dispose();
inputs.Dispose();

Additional notes: - The job is Burst-compiled ([BurstCompile]) and must only use-supported types and operations in the job body. Ensure all ComponentLookup and type handles are created with the correct read-only/read-write intent before scheduling. - m_Results is annotated with NativeDisableContainerSafetyRestriction — the caller is responsible for providing a valid ParallelWriter instance (e.g., NativeAccumulator.AsParallelWriter()) and for ensuring memory safety across threads. - The job expects IconClusterSystem and NotificationsUtils, MathUtils helpers to be available in the mod/runtime. Adjust names/usage if API changes. - The job treats icons with IconFlags.OnTop by slightly reducing normalized distance so they sort ahead in the result list. - Internal NativeList allocations used inside CheckClusters use Allocator.Temp and are disposed within the job; this is safe for short-lived per-execute usage but should be noted in profiling (allocations per Execute could be expensive if many clusters are visited). Consider prefiltering or alternative strategies if performance concerns arise.