Class KaijuVisionSensor<T>
KaijuSensor to allow for visual detection of a component type.
Inheritance
Inherited Members
Namespace: KaijuSolutions.Agents.Sensors
Syntax
public abstract class KaijuVisionSensor<T> : KaijuSensor where T : Component
Type Parameters
| Name | Description |
|---|---|
| T | The type of component. |
Fields
editorColor
The visualizations color in the editor.
Declaration
public Color editorColor
Field Value
| Type | Description |
|---|---|
| Color |
editorFromAgent
If the visualizations in the editor for the line-of-sight checks should come from the Agent's position or from the KaijuSensor's position. The range and view arc are always drawn from the Agent's Y height and the KaijuSensor's X and Z positions.
Declaration
public bool editorFromAgent
Field Value
| Type | Description |
|---|---|
| System.Boolean |
lineOfSight
If line-of-sight checks should be made for the vision. Turning off line-of-sight checks will return items within the view arc based on the angle and distance.
Declaration
public bool lineOfSight
Field Value
| Type | Description |
|---|---|
| System.Boolean |
mask
What layers to collide with on the line-of-sight checks.
Declaration
public LayerMask mask
Field Value
| Type | Description |
|---|---|
| LayerMask |
Observables
The objects which this can detect.
Declaration
public IEnumerable<T> Observables
Field Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> |
offset
Any vertical offset to add to the line-of-sight checks. This can be useful if you for instance have targets which are a few units high but their origins are at their bases.
Declaration
public float offset
Field Value
| Type | Description |
|---|---|
| System.Single |
triggers
How line-of-sight checks should handle hitting triggers.
Declaration
public QueryTriggerInteraction triggers
Field Value
| Type | Description |
|---|---|
| QueryTriggerInteraction |
Properties
Angle
What angle the vision detection should cover.
Declaration
public float Angle { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Distance
How far vision can extend.
Declaration
public float Distance { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
HasObserved
If at least one instance has been Observed.
Declaration
public bool HasObserved { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Observed
All observed items.
Declaration
public IReadOnlyCollection<T> Observed { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IReadOnlyCollection<T> |
ObservedCount
The number of Observed items.
Declaration
public int ObservedCount { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Radius
The radius of the line-of-sight checks.
Declaration
public float Radius { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Methods
Cleanup()
Perform any needed resetting of the KaijuSensor.
Declaration
protected override void Cleanup()
Overrides
DefaultObservables()
If there are no explicitly defined observable objects, define how to query for default observables.
Declaration
protected virtual IEnumerable<T> DefaultObservables()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> | All active instances. |
EditorVisualize(Vector3)
Allow for visualizing in the editor. The position of the Agent.
Declaration
public override void EditorVisualize(Vector3 position)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position |
Overrides
Farthest(out Single, Boolean)
Declaration
public T Farthest(out float farthest, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | farthest | The distance to the farthest Observed instance. |
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| T | The farthest Observed instance. Will be NULL if the Observed list is empty. |
Farthest3(out Single, Boolean)
Declaration
public T Farthest3(out float farthest, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | farthest | The distance to the farthest Observed instance. |
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| T | The farthest Observed instance. Will be NULL if the Observed list is empty. |
FarthestPosition(Boolean)
Declaration
public Vector2 FarthestPosition(bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector2 | The farthest Observed position instance. Will be a zero vector if the Observed list is empty. |
FarthestPosition3(Boolean)
Declaration
public Vector3 FarthestPosition3(bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector3 | The farthest Observed position instance. Will be a zero vector if the Observed list is empty. |
Nearest(out Single, Boolean)
Declaration
public T Nearest(out float nearest, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | nearest | The distance to the nearest Observed instance. |
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| T | The nearest Observed instance. Will be NULL if the Observed list is empty. |
Nearest3(out Single, Boolean)
Declaration
public T Nearest3(out float nearest, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | nearest | The distance to the nearest Observed instance. |
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| T | The nearest Observed instance. Will be NULL if the Observed list is empty. |
NearestPosition(Boolean)
Declaration
public Vector2 NearestPosition(bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector2 | The nearest Observed position instance. Will be a zero vector if the Observed list is empty. |
NearestPosition3(Boolean)
Declaration
public Vector3 NearestPosition3(bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | normalize | If the distance should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector3 | The nearest Observed position instance. Will be a zero vector if the Observed list is empty. |
Run()
Run the KaijuSensor.
Declaration
protected override void Run()
Overrides
SortAngle(T[], KaijuAngleSortMode, Nullable<Boolean>)
Sort Observed instances by angle to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortAngle(T[] cache, KaijuAngleSortMode mode = null, bool? farthest = false)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with NULL values. |
| KaijuAngleSortMode | mode | How to handle sorting. |
| System.Nullable<System.Boolean> | farthest | How to handle breaking ties by distance. NULL means no tie breaking, false for nearest distance, and true for farthest distance. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortAngle(KaijuAngleSortMode, Nullable<Boolean>)
Declaration
public T[] SortAngle(KaijuAngleSortMode mode = null, bool? farthest = false)
Parameters
| Type | Name | Description |
|---|---|---|
| KaijuAngleSortMode | mode | How to handle sorting. |
| System.Nullable<System.Boolean> | farthest | How to handle breaking ties by distance. NULL means no tie breaking, false for nearest distance, and true for farthest distance. |
Returns
| Type | Description |
|---|---|
| T[] | The sorted Observed instances. |
SortAnglePosition(KaijuAngleSortMode, Nullable<Boolean>, Boolean)
Declaration
public Vector2[] SortAnglePosition(KaijuAngleSortMode mode = null, bool? farthest = false, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| KaijuAngleSortMode | mode | How to handle sorting. |
| System.Nullable<System.Boolean> | farthest | How to handle breaking ties by distance. NULL means no tie breaking, false for nearest distance, and true for farthest distance. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector2[] | The sorted Observed instances. |
SortAnglePosition(Vector2[], KaijuAngleSortMode, Nullable<Boolean>, Boolean)
Sort Observed instances by angle to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortAnglePosition(Vector2[] cache, KaijuAngleSortMode mode = null, bool? farthest = false, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with NULL values. |
| KaijuAngleSortMode | mode | How to handle sorting. |
| System.Nullable<System.Boolean> | farthest | How to handle breaking ties by distance. NULL means no tie breaking, false for nearest distance, and true for farthest distance. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortAnglePosition3(KaijuAngleSortMode, Nullable<Boolean>, Boolean)
Declaration
public Vector3[] SortAnglePosition3(KaijuAngleSortMode mode = null, bool? farthest = false, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| KaijuAngleSortMode | mode | How to handle sorting. |
| System.Nullable<System.Boolean> | farthest | How to handle breaking ties by distance. NULL means no tie breaking, false for nearest distance, and true for farthest distance. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector3[] | The sorted Observed instances. |
SortAnglePosition3(Vector3[], KaijuAngleSortMode, Nullable<Boolean>, Boolean)
Sort Observed instances by angle to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortAnglePosition3(Vector3[] cache, KaijuAngleSortMode mode = null, bool? farthest = false, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with NULL values. |
| KaijuAngleSortMode | mode | How to handle sorting. |
| System.Nullable<System.Boolean> | farthest | How to handle breaking ties by distance. NULL means no tie breaking, false for nearest distance, and true for farthest distance. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortDistance(T[], Boolean, Nullable<KaijuAngleSortMode>)
Sort Observed instances by distance to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortDistance(T[] cache, bool farthest = false, KaijuAngleSortMode? mode = null)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with NULL values. |
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortDistance(Boolean, Nullable<KaijuAngleSortMode>)
Declaration
public T[] SortDistance(bool farthest = false, KaijuAngleSortMode? mode = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
Returns
| Type | Description |
|---|---|
| T[] | The sorted Observed instances. |
SortDistance3(T[], Boolean, Nullable<KaijuAngleSortMode>)
Sort Observed instances by distance across all axes to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortDistance3(T[] cache, bool farthest = false, KaijuAngleSortMode? mode = null)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with NULL values. |
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortDistance3(Boolean, Nullable<KaijuAngleSortMode>)
Declaration
public T[] SortDistance3(bool farthest = false, KaijuAngleSortMode? mode = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
Returns
| Type | Description |
|---|---|
| T[] | The sorted Observed instances. |
SortDistance3Position(Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Declaration
public Vector2[] SortDistance3Position(bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector2[] | The sorted Observed instances. |
SortDistance3Position(Vector2[], Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Sort Observed instances by distance across all axes to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortDistance3Position(Vector2[] cache, bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with zero values. |
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortDistance3Position(Vector3[], Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Sort Observed instances by distance across all axes to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortDistance3Position(Vector3[] cache, bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with zero values. |
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortDistance3Position3(Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Declaration
public Vector3[] SortDistance3Position3(bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector3[] | The sorted Observed instances. |
SortDistancePosition(Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Declaration
public Vector2[] SortDistancePosition(bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector2[] | The sorted Observed instances. |
SortDistancePosition(Vector2[], Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Sort Observed instances by distance to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortDistancePosition(Vector2[] cache, bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with zero values. |
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortDistancePosition(Vector3[], Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Sort Observed instances by distance to the Agent, keeping only the first instances which fit into a cache.
Declaration
public int SortDistancePosition(Vector3[] cache, bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | cache | Where to store the observed instances. If this is less than the total Observed instances, only the first fitting instances will be returned. If this is larger than the Observed instances, any extra space will be filled with zero values. |
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of Observed instances fit into the cache. |
SortDistancePosition3(Boolean, Nullable<KaijuAngleSortMode>, Boolean)
Declaration
public Vector3[] SortDistancePosition3(bool farthest = false, KaijuAngleSortMode? mode = null, bool normalize = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | farthest | If this should sort by farthest items first. |
| System.Nullable<KaijuAngleSortMode> | mode | How to break ties based on angle. |
| System.Boolean | normalize | If positions should be normalized between [-1, 1]. |
Returns
| Type | Description |
|---|---|
| Vector3[] | The sorted Observed instances. |
Operators
Implicit(GameObject to KaijuVisionSensor<T>)
Implicit conversion from a GameObject.
Declaration
public static implicit operator KaijuVisionSensor<T>(GameObject o)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | o | The GameObject. |
Returns
| Type | Description |
|---|---|
| KaijuVisionSensor<T> | The KaijuVisionSensor<T> attached to the GameObject if there was one. |
Implicit(KaijuVisionSensor<T> to KaijuAgent)
Implicit conversion to a KaijuAgent.
Declaration
public static implicit operator KaijuAgent(KaijuVisionSensor<T> s)
Parameters
| Type | Name | Description |
|---|---|---|
| KaijuVisionSensor<T> | s | The KaijuVisionSensor<T>. |
Returns
| Type | Description |
|---|---|
| KaijuAgent | The KaijuAgent attached to the KaijuVisionSensor<T> if there was one. |
Implicit(Transform to KaijuVisionSensor<T>)
Implicit conversion from a transform.
Declaration
public static implicit operator KaijuVisionSensor<T>(Transform t)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | t | The transform. |
Returns
| Type | Description |
|---|---|
| KaijuVisionSensor<T> | The KaijuVisionSensor<T> attached to the transform if there was one. |