Added conditional compilation for 2021.3 for removing batched raycasts.
This commit is contained in:
Родитель
8b86648e53
Коммит
b7c908afe9
|
@ -64,10 +64,12 @@ namespace Unity.MLAgents.Editor
|
|||
}
|
||||
|
||||
EditorGUILayout.PropertyField(so.FindProperty("m_AlternatingRayOrder"), true);
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
if (is3d)
|
||||
{
|
||||
EditorGUILayout.PropertyField(so.FindProperty("m_UseBatchedRaycasts"), true);
|
||||
}
|
||||
#endif
|
||||
|
||||
EditorGUILayout.PropertyField(so.FindProperty("rayHitColor"), true);
|
||||
EditorGUILayout.PropertyField(so.FindProperty("rayMissColor"), true);
|
||||
|
|
|
@ -74,10 +74,12 @@ namespace Unity.MLAgents.Sensors
|
|||
/// </summary>
|
||||
public int LayerMask;
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
/// <summary>
|
||||
/// Whether to use batched raycasts.
|
||||
/// </summary>
|
||||
public bool UseBatchedRaycasts;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the expected number of floats in the output.
|
||||
|
@ -252,7 +254,9 @@ namespace Unity.MLAgents.Sensors
|
|||
RayPerceptionInput m_RayPerceptionInput;
|
||||
RayPerceptionOutput m_RayPerceptionOutput;
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
bool m_UseBatchedRaycasts;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Time.frameCount at the last time Update() was called. This is only used for display in gizmos.
|
||||
|
@ -273,8 +277,9 @@ namespace Unity.MLAgents.Sensors
|
|||
{
|
||||
m_Name = name;
|
||||
m_RayPerceptionInput = rayInput;
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
m_UseBatchedRaycasts = rayInput.UseBatchedRaycasts;
|
||||
|
||||
#endif
|
||||
SetNumObservations(rayInput.OutputSize());
|
||||
|
||||
m_DebugLastFrameCount = Time.frameCount;
|
||||
|
@ -348,19 +353,22 @@ namespace Unity.MLAgents.Sensors
|
|||
{
|
||||
m_RayPerceptionOutput.RayOutputs = new RayPerceptionOutput.RayOutput[numRays];
|
||||
}
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
if (m_UseBatchedRaycasts && m_RayPerceptionInput.CastType == RayPerceptionCastType.Cast3D)
|
||||
{
|
||||
PerceiveBatchedRays(ref m_RayPerceptionOutput.RayOutputs, m_RayPerceptionInput);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For each ray, do the casting and save the results.
|
||||
for (var rayIndex = 0; rayIndex < numRays; rayIndex++)
|
||||
{
|
||||
m_RayPerceptionOutput.RayOutputs[rayIndex] = PerceiveSingleRay(m_RayPerceptionInput, rayIndex);
|
||||
}
|
||||
#endif
|
||||
// For each ray, do the casting and save the results.
|
||||
for (var rayIndex = 0; rayIndex < numRays; rayIndex++)
|
||||
{
|
||||
m_RayPerceptionOutput.RayOutputs[rayIndex] = PerceiveSingleRay(m_RayPerceptionInput, rayIndex);
|
||||
}
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
@ -406,22 +414,25 @@ namespace Unity.MLAgents.Sensors
|
|||
{
|
||||
RayPerceptionOutput output = new RayPerceptionOutput();
|
||||
output.RayOutputs = new RayPerceptionOutput.RayOutput[input.Angles.Count];
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
if (batched)
|
||||
{
|
||||
PerceiveBatchedRays(ref output.RayOutputs, input);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var rayIndex = 0; rayIndex < input.Angles.Count; rayIndex++)
|
||||
{
|
||||
output.RayOutputs[rayIndex] = PerceiveSingleRay(input, rayIndex);
|
||||
}
|
||||
#endif
|
||||
for (var rayIndex = 0; rayIndex < input.Angles.Count; rayIndex++)
|
||||
{
|
||||
output.RayOutputs[rayIndex] = PerceiveSingleRay(input, rayIndex);
|
||||
}
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
}
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
/// <summary>
|
||||
/// Evaluate the raycast results of all the rays from the RayPerceptionInput as a batch.
|
||||
/// </summary>
|
||||
|
@ -548,6 +559,7 @@ namespace Unity.MLAgents.Sensors
|
|||
raycastCommands.Dispose();
|
||||
spherecastCommands.Dispose();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Evaluate the raycast results of a single ray from the RayPerceptionInput.
|
||||
|
|
|
@ -145,8 +145,9 @@ namespace Unity.MLAgents.Sensors
|
|||
set { m_AlternatingRayOrder = value; }
|
||||
}
|
||||
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
[HideInInspector, SerializeField]
|
||||
[Tooltip("Enable to use batched raycasts and the jobs system.")]
|
||||
[Tooltip("Enable to use batched raycasts and the jobs system. Only available in Unity 2022.3 LTS or newer.")]
|
||||
public bool m_UseBatchedRaycasts = false;
|
||||
|
||||
/// <summary>
|
||||
|
@ -157,7 +158,7 @@ namespace Unity.MLAgents.Sensors
|
|||
get { return m_UseBatchedRaycasts; }
|
||||
set { m_UseBatchedRaycasts = value; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Color to code a ray that hits another object.
|
||||
|
@ -303,8 +304,9 @@ namespace Unity.MLAgents.Sensors
|
|||
rayPerceptionInput.Transform = transform;
|
||||
rayPerceptionInput.CastType = GetCastType();
|
||||
rayPerceptionInput.LayerMask = RayLayerMask;
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
rayPerceptionInput.UseBatchedRaycasts = UseBatchedRaycasts;
|
||||
|
||||
#endif
|
||||
return rayPerceptionInput;
|
||||
}
|
||||
|
||||
|
@ -349,6 +351,7 @@ namespace Unity.MLAgents.Sensors
|
|||
// and there's no way to turn off the "Tag ... is not defined" error logs.
|
||||
// So just don't use any tags here.
|
||||
rayInput.DetectableTags = null;
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
if (m_UseBatchedRaycasts && rayInput.CastType == RayPerceptionCastType.Cast3D)
|
||||
{
|
||||
// TODO add call to PerceiveBatchedRays()
|
||||
|
@ -361,12 +364,15 @@ namespace Unity.MLAgents.Sensors
|
|||
}
|
||||
else
|
||||
{
|
||||
for (var rayIndex = 0; rayIndex < rayInput.Angles.Count; rayIndex++)
|
||||
{
|
||||
var rayOutput = RayPerceptionSensor.PerceiveSingleRay(rayInput, rayIndex);
|
||||
DrawRaycastGizmos(rayOutput);
|
||||
}
|
||||
#endif
|
||||
for (var rayIndex = 0; rayIndex < rayInput.Angles.Count; rayIndex++)
|
||||
{
|
||||
var rayOutput = RayPerceptionSensor.PerceiveSingleRay(rayInput, rayIndex);
|
||||
DrawRaycastGizmos(rayOutput);
|
||||
}
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче