change: better support for BoxOverlap observers, small tweaks to the editor and task
This commit is contained in:
@@ -35,6 +35,7 @@ namespace Reset {
|
|||||||
private EnvironmentObserver observer;
|
private EnvironmentObserver observer;
|
||||||
|
|
||||||
public BBParameter<RaycastHit> outputHit;
|
public BBParameter<RaycastHit> outputHit;
|
||||||
|
public BBParameter<List<Collider>> outputHitArray;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
protected override void OnTaskInspectorGUI(){
|
protected override void OnTaskInspectorGUI(){
|
||||||
@@ -63,7 +64,13 @@ namespace Reset {
|
|||||||
drawGizmosOnlyWhenActive = EditorGUILayout.Toggle("Draw Gizmos Only When Active", drawGizmosOnlyWhenActive);
|
drawGizmosOnlyWhenActive = EditorGUILayout.Toggle("Draw Gizmos Only When Active", drawGizmosOnlyWhenActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
BBParameterEditor.ParameterField("Output Hit", outputHit);
|
if (castType.value == EnvironmentObserver.CastType.BoxCast ||
|
||||||
|
castType.value == EnvironmentObserver.CastType.SphereCast ||
|
||||||
|
castType.value == EnvironmentObserver.CastType.Ray) {
|
||||||
|
BBParameterEditor.ParameterField("Output Hit", outputHit);
|
||||||
|
} else {
|
||||||
|
BBParameterEditor.ParameterField("Output Hits", outputHitArray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -43,19 +43,27 @@ public class EnvironmentObserver{
|
|||||||
public bool active;
|
public bool active;
|
||||||
|
|
||||||
// Parameters for Cast cast types
|
// 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 direction;
|
||||||
[FoldoutGroup("Settings")] public Vector3 offset;
|
[FoldoutGroup("Settings")] public Vector3 offset;
|
||||||
[PropertySpace(0, 5), FoldoutGroup("Settings")] public LayerMask ignoreLayers = ~0;
|
[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;
|
[FoldoutGroup("Settings")] public float width;
|
||||||
|
|
||||||
// Parameters for Overlap cast types
|
// 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;
|
public Vector3 size;
|
||||||
|
|
||||||
[ShowIfGroup("Settings/3DOnly")]
|
[ShowIfGroup("Settings/BoxesOnly")]
|
||||||
public Vector3 rotation;
|
public Vector3 rotation;
|
||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
@@ -96,8 +104,30 @@ public class EnvironmentObserver{
|
|||||||
Physics.Raycast(relativeStart, source.transform.rotation * direction, out hit, length, ignoreLayers);
|
Physics.Raycast(relativeStart, source.transform.rotation * direction, out hit, length, ignoreLayers);
|
||||||
break;
|
break;
|
||||||
case CastType.BoxOverlap:
|
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);
|
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) {
|
if (overlapHits.Length > 0) {
|
||||||
return true;
|
return true;
|
||||||
@@ -165,7 +195,6 @@ public class EnvironmentObserver{
|
|||||||
} else {
|
} else {
|
||||||
gizmosRotation = source.transform.rotation * Quaternion.LookRotation(direction) * Quaternion.Euler(rotation);
|
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;
|
Color gizmoColor = Evaluate(source) ? Color.green : Color.red;
|
||||||
gizmoColor = active ? gizmoColor : Color.gray;
|
gizmoColor = active ? gizmoColor : Color.gray;
|
||||||
|
|||||||
Reference in New Issue
Block a user