|
|
|
|
|
|
float m_CastRadius; |
|
|
|
CastType m_CastType; |
|
|
|
Transform m_Transform; |
|
|
|
int m_LayerMask; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Debug information for the raycast hits. This is used by the RayPerceptionSensorComponent.
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public RayPerceptionSensor(string name, float rayDistance, List<string> detectableObjects, float[] angles, |
|
|
|
Transform transform, float startOffset, float endOffset, float castRadius, CastType castType) |
|
|
|
Transform transform, float startOffset, float endOffset, float castRadius, CastType castType, |
|
|
|
int rayLayerMask) |
|
|
|
{ |
|
|
|
var numObservations = (detectableObjects.Count + 2) * angles.Length; |
|
|
|
m_Shape = new[] { numObservations }; |
|
|
|
|
|
|
m_EndOffset = endOffset; |
|
|
|
m_CastRadius = castRadius; |
|
|
|
m_CastType = castType; |
|
|
|
m_LayerMask = rayLayerMask; |
|
|
|
|
|
|
|
if (Application.isEditor) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
PerceiveStatic( |
|
|
|
m_RayDistance, m_Angles, m_DetectableObjects, m_StartOffset, m_EndOffset, |
|
|
|
m_CastRadius, m_Transform, m_CastType, m_Observations, false, m_DebugDisplayInfo |
|
|
|
m_CastRadius, m_Transform, m_CastType, m_Observations, false, m_LayerMask, |
|
|
|
m_DebugDisplayInfo |
|
|
|
); |
|
|
|
adapter.AddRange(m_Observations); |
|
|
|
} |
|
|
|
|
|
|
float startOffset, float endOffset, float castRadius, |
|
|
|
Transform transform, CastType castType, float[] perceptionBuffer, |
|
|
|
bool legacyHitFractionBehavior = false, |
|
|
|
int layerMask = Physics.DefaultRaycastLayers, |
|
|
|
DebugDisplayInfo debugInfo = null) |
|
|
|
{ |
|
|
|
Array.Clear(perceptionBuffer, 0, perceptionBuffer.Length); |
|
|
|
|
|
|
RaycastHit rayHit; |
|
|
|
if (castRadius > 0f) |
|
|
|
{ |
|
|
|
castHit = Physics.SphereCast(startPositionWorld, castRadius, rayDirection, out rayHit, rayLength); |
|
|
|
castHit = Physics.SphereCast(startPositionWorld, castRadius, rayDirection, out rayHit, |
|
|
|
rayLength, layerMask); |
|
|
|
castHit = Physics.Raycast(startPositionWorld, rayDirection, out rayHit, rayLength); |
|
|
|
castHit = Physics.Raycast(startPositionWorld, rayDirection, out rayHit, |
|
|
|
rayLength, layerMask); |
|
|
|
} |
|
|
|
|
|
|
|
hitFraction = castHit ? rayHit.distance / rayLength : 1.0f; |
|
|
|
|
|
|
RaycastHit2D rayHit; |
|
|
|
if (castRadius > 0f) |
|
|
|
{ |
|
|
|
rayHit = Physics2D.CircleCast(startPositionWorld, castRadius, rayDirection, rayLength); |
|
|
|
rayHit = Physics2D.CircleCast(startPositionWorld, castRadius, rayDirection, |
|
|
|
rayLength, layerMask); |
|
|
|
rayHit = Physics2D.Raycast(startPositionWorld, rayDirection, rayLength); |
|
|
|
rayHit = Physics2D.Raycast(startPositionWorld, rayDirection, rayLength, layerMask); |
|
|
|
} |
|
|
|
|
|
|
|
castHit = rayHit; |
|
|
|