Skip to main content

CullingGroupHandler

A class in Root.Township, the global namespace.

Client: one hidden shared Unity CullingGroup on the local player's camera that other scripts register bounding spheres with to get visibility callbacks. Created on first RegisterSphere.

Constructors​

MemberWhat it is
CullingGroupHandler()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

8 private and internal fields
MemberWhat it is
private CullingGroup cullingThe Unity CullingGroup, bound to the local player's camera.
private Dictionary<int, Action<CullingGroupEvent>> eventsCallback for each registered sphere index.
private static CullingGroupHandler handlerThe single shared instance.
private bool isSetupUnused flag.
private int nextIndexNext free slot to use for a new sphere.
private int sphereCountHow many array slots the culling group checks (one past the highest used slot).
private BoundingSphere[] spheresBounding spheres; starts at 16 and doubles when full.
private bool[] usageWhich sphere slots are in use.

Methods​

MemberWhat it is
static void DeregisterSphere(ref int index)Removes a sphere by index, shrinks the active count if it was last, and sets the caller's index to -1.
static int RegisterSphere(Vector3 center, float radius, Action<CullingGroupEvent> callback)Registers a sphere and callback, creating the handler if needed; returns the index to pass to DeregisterSphere. Used by StorageOrganizer and SphereVisibilityCheck.
5 private and internal methods
MemberWhat it is
private void OnDestroy()Clears the singleton, disposes the culling group and unsubscribes from PlayerController.LocalPlayerSet.
private int RegisterSphereInternal(Vector3 center, float radius, Action<CullingGroupEvent> callback)Stores the sphere in the next free slot, doubles the arrays when full, and updates the culling group.
private void SetupCulling(PlayerController player)Creates a new culling group on the given player's camera. Runs again whenever the local player is set.
private void SetupSpheres()Pushes the sphere array and count to the culling group.
private void UpdateStates(CullingGroupEvent sphere)Culling group callback: forwards the event to the callback registered for that sphere index.