Raycast / Hit Cache
GetRaycastHits
GetRaycastHitspublic IEnumerable<Vector3> GetRaycastHits() => m_HitCache.ConvertAll(h => h.point);Purpose: Get all hit points (world space) from the last rebuild.
Returns: IEnumerable<Vector3>
Notes: Handy for debug rendering or custom analytics.
GetHitTransforms
GetHitTransformspublic List<Transform> GetHitTransforms()
{
List<Transform> list = new();
foreach (var h in m_HitCache)
if (h.transform && !list.Contains(h.transform))
list.Add(h.transform);
return list;
}Purpose: Unique set of Transforms that were hit.
Returns: List<Transform>
Notes: Which objects were touched by the projection.
GetHitMaterialSet
GetHitMaterialSetpublic HashSet<Material> GetHitMaterialSet()
{
HashSet<Material> set = new();
foreach (var h in m_HitCache)
if (h.collider && h.collider.TryGetComponent(out Renderer r) && r.sharedMaterials != null)
foreach (var mat in r.sharedMaterials)
if (mat) set.Add(mat);
return set;
}Purpose: Unique set of Materials belonging to hit renderers.
Returns: HashSet<Material>
Notes: Useful for material-specific logic or reporting.
GetLayerHitStatistics
GetLayerHitStatisticspublic Dictionary<int, int> GetLayerHitStatistics()
{
Dictionary<int, int> dict = new();
foreach (var h in m_HitCache)
{
int layer = h.collider ? h.collider.gameObject.layer : -1;
dict.TryAdd(layer, 0);
dict[layer]++;
}
return dict;
}Purpose: Map Layer → hit count.
Returns: Dictionary<int,int>
Notes: Helps tune masks and performance per-layer.
ClearHitCache
ClearHitCachepublic void ClearHitCache() => m_HitCache.Clear();Purpose: Clear cached hits (does not rebuild).
Returns: void
RegisterOnHitCallback
RegisterOnHitCallbackpublic void RegisterOnHitCallback(Func<RaycastHit, bool> filter, Action<RaycastHit> callback)
{
if (filter == null || callback == null) return;
m_HitFilters.Add(filter);
m_OnHitCallbacks.Add(hit => { if (filter(hit)) callback(hit); });
}Purpose: Register a filter + callback to be invoked for each cached hit after a rebuild. Parameters:
filter— predicate; only hits returningtruetrigger the callback.callback— invoked for each passing hit. Returns:voidNotes: You can register multiple filtered callbacks; great for analytics and selective processing.
Last updated