Skip to main content

VisibleNetworkRigidbody

A class in Root.Township, the global namespace.

Client: turns off a group of NetworkRigidbody components (inactive and kinematic) while a bounding sphere is out of the local player's camera view, and back on when it comes into view. Does nothing on a headless server.

Constructors​

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

Fields​

4 private and internal fields
MemberWhat it is
private CullingGroup cullingUnity CullingGroup on the local player's camera.
private BoundingSphere[] spheresThe single bounding sphere, at the start position plus visibilityCenter.
private Vector3 visibilityCenterOffset of the visibility sphere from the object.
private float visibilityRadiusRadius of the visibility sphere.

Methods​

7 private and internal methods
MemberWhat it is
private void Initialize(PlayerController current)Builds a culling group on the player's camera and starts with all the rigidbodies off and kinematic.
private void IUpdateOnMove.Moved()Rebuilds the culling group when the object moves. The sphere keeps the position set in Start.
private void OnDestroy()Disposes the culling group and unhooks PlayerController.LocalPlayerSet.
private void OnDrawGizmosSelected()Draws the visibility sphere in the editor.
private void Reset()Disposes the current culling group.
private void Start()Client: makes the bounding sphere and initialises now or when the local player is set.
private void UpdateVisibility(CullingGroupEvent sphere)Culling callback: turns the rigidbodies on and refreshes them when visible, off and kinematic when hidden.