added: environment observer changes for grapple

This commit is contained in:
Chris
2025-08-01 11:36:19 -04:00
parent 80276fbdbf
commit 78498e5212
5 changed files with 62 additions and 14 deletions

View File

@@ -8,7 +8,12 @@ namespace NodeCanvas.Tasks.Conditions {
public BBParameter<string> observerLabel;
public BBParameter<RaycastHit> outputHitTo;
protected override string info{
get {
return $"Check Environment Observer, [\"{observerLabel.value}\"]";
}
}
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise

View File

@@ -6,6 +6,8 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NodeCanvas.Editor;
using UnityEditor;
namespace Reset {
[Category("Reset")]
@@ -19,14 +21,43 @@ namespace Reset {
public BBParameter<Vector3> offset;
public BBParameter<LayerMask> ignoreLayers;
[ShowIf("castType", ((int)EnvironmentObserver.CastType.SphereCast|(int)EnvironmentObserver.CastType.SphereOverlap))]
public BBParameter<float> width;
public BBParameter<Vector3> size;
public BBParameter<Vector3> rotation;
public bool drawGizmos;
public bool drawGizmosOnlyWhenActive;
private EnvironmentObserver observer;
protected override void OnTaskInspectorGUI(){
BBParameterEditor.ParameterField("Cast Type", castType);
BBParameterEditor.ParameterField("Length", length);
BBParameterEditor.ParameterField("Direction", direction);
BBParameterEditor.ParameterField("Offset", offset);
BBParameterEditor.ParameterField("Ignore Layers", ignoreLayers);
if (castType.value == EnvironmentObserver.CastType.SphereCast || castType.value == EnvironmentObserver.CastType.SphereOverlap) {
BBParameterEditor.ParameterField("Width", width);
}
if (castType.value == EnvironmentObserver.CastType.BoxCast || castType.value == EnvironmentObserver.CastType.BoxOverlap) {
BBParameterEditor.ParameterField("Size", size);
}
if (castType.value != EnvironmentObserver.CastType.Ray) {
BBParameterEditor.ParameterField("Rotation", rotation);
}
drawGizmos = EditorGUILayout.Toggle("Draw Gizmos", drawGizmos);
if (drawGizmos) {
drawGizmosOnlyWhenActive = EditorGUILayout.Toggle("Draw Gizmos Only When Active", drawGizmosOnlyWhenActive);
}
}
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
@@ -36,11 +67,13 @@ namespace Reset {
//Called whenever the condition gets enabled.
protected override void OnEnable() {
observer = new EnvironmentObserver(){
castType = EnvironmentObserver.CastType.SphereCast,
castType = castType.value,
active = true,
length = length.value,
direction = direction.value,
offset = offset.value,
ignoreLayers = ignoreLayers.value,
width = width.value,
@@ -57,7 +90,13 @@ namespace Reset {
//Called once per frame while the condition is active.
//Return whether the condition is success or failure.
protected override bool OnCheck() {
return observer.Evaluate(agent.gameObject);
bool check = observer.Evaluate(agent.gameObject);
if (drawGizmos) {
observer.DrawObserverGizmo(agent.gameObject, true);
}
return check;
}
}
}

View File

@@ -133,10 +133,11 @@ public class EnvironmentObserver{
return false;
}
public void DrawObserverGizmo(GameObject source){
if (gizmoDrawingCondition == ObserverGizmoDrawingCondition.Never ||
(gizmoDrawingCondition == ObserverGizmoDrawingCondition.OnlyActive ! & active)) {
return;
public void DrawObserverGizmo(GameObject source, bool drawAnyways = false){
if (!drawAnyways){
if (gizmoDrawingCondition == ObserverGizmoDrawingCondition.Never || (gizmoDrawingCondition == ObserverGizmoDrawingCondition.OnlyActive ! & active)) {
return;
}
}
Vector3 relativeStart = source.transform.position + offset;