Skip to main content

Sensor

The base class for the majority of sensors in the kit. It provides functionality for querying the detected Signal's, and events for OnDetection, OnLostDetection.

Properties

Detections

Enumerate through all the detected GameObject's. Can be used in foreach and will not allocate garbage.

Signals

Enumerate through all the detected Signal's. Can be used in foreach and will not allocate garbage.

SignalProcessors

Provides a way to apply custom transformation logic on the detected Signal's. This is for advanced use-cases.

Events

OnDetected

A UnityEvent<GameObject, Sensor> invoked when a GameObject is detected (and previously undetected).

OnLostDetection

A UnityEvent<GameObject, Sensor> invoked when a GameObject that was previously detected is no longer detected.

OnSignalAdded

An Action<Signal, Sensor> invoked when a GameObject is detected (and previously undetected).

OnSignalChanged

An Action<Signal, Sensor> invoked when a Signal for some detected GameObject was changed. This means either the Shape or Strength of the Signal.

OnSignalLost

An Action<Signal, Sensor> invoked when a GameObject that was previously detected is no longer detected.

OnPulsed

An Action invoked straight after the Sensor is Pulse'd.

Methods

GetSignal(gameObject)

Signal GetSignal(GameObject go)
Returns the Signal associated with the detected GameObject.

TryGetSignal(gameObject, out signal)

bool TryGetSignal(GameObject go, out Signal signal)
Safely retrieve the Signal associated with the detected GameObject.

IsDetected(gameObject)

bool IsDetected(GameObject go)
Is the GameObject currently detected by the Sensor?

Pulse()

void Pulse()
Causes the Sensor to perform it's sensing routine, and determine a new list of detected Signal's. Any detection events will fire at the end of this method.

Query Methods

There are many methods for retrieving the list of detections based on some parameters. They all follow a pattern so I won't list them all but rather show the main forms. The query functions can operate on one of:

  • Signals - Return a list of detected Signal's.
  • Detections - Return a list of detected GameObject's.
  • DetectedComponents - Return a list of Component's owned by detected Signal's.

Furthermore each query function is overloaded and will optionally take a Predicate function or a tag which detections must match.

caution

You can optionally provide your own List instance when you call a query method. If you omit it the Sensor will reuse the same List instance each time a query method is called. This makes them convenient to use without worrying about garbage generated, but it's important to be aware!

Get[...]

Return a list of detected [...]

Get[...]ByDistance

Same as above except the list is sorted by distance to the Sensor.

Get[...]ByDistanceToPoint

Same as above except the list is sorted by distance to some point.

GetNearest[...]

Returns only the nearest [...] to the sensor.

GetNearest[...]ToPoint

Returns only the nearest [...] to some point.