change: better support for BoxOverlap observers, small tweaks to the editor and task

This commit is contained in:
Chris
2025-10-03 13:28:15 -04:00
parent f0c7b8f863
commit 5b911f9f47
2 changed files with 43 additions and 7 deletions

View File

@@ -43,19 +43,27 @@ public class EnvironmentObserver{
public bool active;
// Parameters for Cast cast types
[FoldoutGroup("Settings")] public float length;
[FoldoutGroup("Settings")] [HideIf("@castType == CastType.BoxOverlap || castType == CastType.SphereOverlap")]
public float length;
[FoldoutGroup("Settings")] public Vector3 direction;
[FoldoutGroup("Settings")] public Vector3 offset;
[PropertySpace(0, 5), FoldoutGroup("Settings")] public LayerMask ignoreLayers = ~0;
[ShowIfGroup("Settings/CastsOnly", VisibleIf = "@castType == CastType.SphereCast || castType == CastType.SphereOverlap")]
[FoldoutGroup("Settings")] [ShowIf("@castType == CastType.BoxOverlap || castType == CastType.SphereOverlap")]
public List<Collider> ignoreObjects = new List<Collider>();
[FoldoutGroup("Settings")] [ShowIf("@castType == CastType.BoxOverlap || castType == CastType.SphereOverlap")]
public bool dontIgnoreSelf;
[ShowIfGroup("Settings/SpheresOnly", VisibleIf = "@castType == CastType.SphereCast || castType == CastType.SphereOverlap")]
[FoldoutGroup("Settings")] public float width;
// Parameters for Overlap cast types
[ShowIfGroup("Settings/3DOnly", VisibleIf = "@castType == CastType.BoxCast && castType != CastType.BoxOverlap")] [FoldoutGroup("Settings")]
[FoldoutGroup("Settings")]
[ShowIfGroup("Settings/BoxesOnly", VisibleIf = "@castType == CastType.BoxCast || castType == CastType.BoxOverlap")]
public Vector3 size;
[ShowIfGroup("Settings/3DOnly")]
[ShowIfGroup("Settings/BoxesOnly")]
public Vector3 rotation;
[HideInInspector]
@@ -96,8 +104,30 @@ public class EnvironmentObserver{
Physics.Raycast(relativeStart, source.transform.rotation * direction, out hit, length, ignoreLayers);
break;
case CastType.BoxOverlap:
overlapHits = Physics.OverlapBox(relativeStartWithRotation, size / 2f,
// Create original box overlap
Collider[] originalOverlap = Physics.OverlapBox(relativeStartWithRotation, size / 2f,
source.transform.rotation * Quaternion.Euler(rotation), ignoreLayers);
// Convert to a list for editing
List<Collider> collidersAsList = new List<Collider>();
collidersAsList.AddRange(originalOverlap);
// Remove any specifically specified objects
foreach (Collider ignoredObject in ignoreObjects) {
if (collidersAsList.Contains(ignoredObject)) {
collidersAsList.Remove(ignoredObject);
}
}
// Remove the source but only if requested
if (!dontIgnoreSelf) {
if (collidersAsList.Contains(source.GetComponent<Collider>())) {
collidersAsList.Remove(source.GetComponent<Collider>());
}
}
// Send back to an array and done
overlapHits = collidersAsList.ToArray();
if (overlapHits.Length > 0) {
return true;
@@ -165,7 +195,6 @@ public class EnvironmentObserver{
} else {
gizmosRotation = source.transform.rotation * Quaternion.LookRotation(direction) * Quaternion.Euler(rotation);
}
Vector3 firstBoxOffset = gizmosRotation * (Vector3.forward * size.z);
Color gizmoColor = Evaluate(source) ? Color.green : Color.red;
gizmoColor = active ? gizmoColor : Color.gray;