Skip to main content

EyeFocusController

A class in Root.Township, Alta.Character.

Client: picks something for a character's eyes to look at. Every so often it scores nearby colliders by angle, distance, speed and layer, and moves a focus handle to the best one. Turned off on headless servers.

Constructors​

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

Fields​

10 private and internal fields
MemberWhat it is
private Transform currentTargetBacking field for CurrentTarget.
private Transform focusHandleBacking field for FocusHandle.
private int foundHow many colliders the last overlap check found.
private static Logger loggerNLog logger for this class.
private Transform managerTransformBacking field for ManagerTransform.
private Collider[] overlapReused buffer for the overlap check, sized from settings.MaximumOverlap.
private Transform overrideTargetBacking field for OverrideTarget.
private Vector3[] positionsPositions of the found colliders at scan time, used to work out how fast each moves.
private EyeFocusControllerSettings settingsThe EyeFocusControllerSettings asset with detection range, angle limits and scoring curves.
private float timeUntilUpdateTime left before the current target is reconsidered.

Properties​

MemberWhat it is
Transform CurrentTarget { get; set; }What the eyes look at now. Setting it is ignored while OverrideTarget is set.
Transform FocusHandle { get; set; }Transform moved to the target's position each update. The eye rig probably looks at it.
Transform ManagerTransform { get; set; }Transform whose space angles and distances are measured in. The editor setup defaults it to this component's transform.
Transform OverrideTarget { get; set; }Forces a target, which also becomes CurrentTarget. Set to null to go back to automatic picking.

Methods​

MemberWhat it is
override void UpdateCharacterComponent()Moves the focus handle to the current target's position.
6 private and internal methods
MemberWhat it is
private void Awake()Turns the component off on a headless server.
private IEnumerator CheckFocus() (iterator)Coroutine that keeps the current target while it stays in view and its timer runs, otherwise rescans and picks the lowest-scoring collider.
private bool EditorSetup()Editor fix-up: fills in managerTransform, enables or disables the component to match settings, and sizes the overlap arrays.
private void OnDisable()Stops the CheckFocus coroutine.
private void OnDrawGizmosSelected()Draws the detection sphere, the view angle limits and lines to the found colliders, with the current target in red.
private void OnEnable()Starts the CheckFocus coroutine.

Used in​

Members of other types that take, return or hold a EyeFocusController: