Skip to content
This repository was archived by the owner on Apr 3, 2022. It is now read-only.

Commit ab30bda

Browse files
committed
Add AIDecisionDetectTargetLine3DNode.
1 parent 4c76324 commit ab30bda

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using UnityEngine;
2+
using MoreMountains.TopDownEngine;
3+
using MoreMountains.Tools;
4+
using TheBitCave.MMToolsExtensions.AI.Graph;
5+
6+
namespace TheBitCave.TopDownEngineExensions.AI.Graph
7+
{
8+
/// <summary>
9+
/// A node representing a TopDown Engine <see cref="MoreMountains.TopDownEngine.AIDecisionDetectTargetLine3D"/> decision.
10+
/// </summary>
11+
[CreateNodeMenu("AI/Decision/3D/Detect Target Line")]
12+
public class AIDecisionDetectTargetLine3DNode : AIDecisionNode
13+
{
14+
[NodeEnum] public AIDecisionDetectTargetLine3D.DetectMethods detectMethod = AIDecisionDetectTargetLine3D.DetectMethods.Ray;
15+
public float rayWidth = 1f;
16+
public float detectionDistance = 10f;
17+
public Vector3 detectionOriginOffset = new Vector3(0,0,0);
18+
public LayerMask targetLayer;
19+
public LayerMask obstaclesLayer;
20+
// public Transform referenceTransform;
21+
public bool forceAimToDetectionDirection = false;
22+
23+
public override AIDecision AddDecisionComponent(GameObject go)
24+
{
25+
var decision = go.AddComponent<AIDecisionDetectTargetLine3D>();
26+
decision.Label = label;
27+
decision.DetectMethod = detectMethod;
28+
decision.RayWidth = rayWidth;
29+
decision.DetectionDistance = detectionDistance;
30+
decision.DetectionOriginOffset = detectionOriginOffset;
31+
decision.TargetLayer = targetLayer;
32+
decision.ObstaclesLayer = obstaclesLayer;
33+
// decision.ReferenceTransform = referenceTransform;
34+
decision.ForceAimToDetectionDirection = forceAimToDetectionDirection;
35+
return decision;
36+
}
37+
}
38+
}

Common/Scripts/AI/Graph/Decisions/AIDecisionDetectTargetLine3DNode.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using TheBitCave.MMToolsExtensions.AI.Graph;
2+
using UnityEditor;
3+
using XNodeEditor;
4+
5+
namespace TheBitCave.TopDownEngineExensions.AI.Graph
6+
{
7+
[CustomNodeEditor(typeof(AIDecisionDetectTargetLine3DNode))]
8+
public class AIDecisionDetectTargetLine3DNodeEditor : AIDecisionNodeEditor
9+
{
10+
private SerializedProperty _detectMethod;
11+
private SerializedProperty _rayWidth;
12+
private SerializedProperty _detectionDistance;
13+
private SerializedProperty _detectionOriginOffset;
14+
private SerializedProperty _targetLayer;
15+
private SerializedProperty _obstaclesLayer;
16+
// private SerializedProperty _referenceTransform;
17+
private SerializedProperty _forceAimToDetectionDirection;
18+
19+
public override void OnBodyGUI()
20+
{
21+
base.OnBodyGUI();
22+
23+
_detectMethod = serializedObject.FindProperty("detectMethod");
24+
_rayWidth = serializedObject.FindProperty("rayWidth");
25+
_detectionDistance = serializedObject.FindProperty("detectionDistance");
26+
_detectionOriginOffset = serializedObject.FindProperty("detectionOriginOffset");
27+
_targetLayer = serializedObject.FindProperty("targetLayer");
28+
_obstaclesLayer = serializedObject.FindProperty("obstaclesLayer");
29+
// _referenceTransform = serializedObject.FindProperty("referenceTransform");
30+
_forceAimToDetectionDirection = serializedObject.FindProperty("forceAimToDetectionDirection");
31+
32+
serializedObject.Update();
33+
EditorGUIUtility.labelWidth = 120;
34+
NodeEditorGUILayout.PropertyField(_detectMethod);
35+
NodeEditorGUILayout.PropertyField(_rayWidth);
36+
NodeEditorGUILayout.PropertyField(_detectionDistance);
37+
NodeEditorGUILayout.PropertyField(_detectionOriginOffset);
38+
NodeEditorGUILayout.PropertyField(_targetLayer);
39+
NodeEditorGUILayout.PropertyField(_obstaclesLayer);
40+
// NodeEditorGUILayout.PropertyField(_referenceTransform);
41+
EditorGUIUtility.labelWidth = 250;
42+
NodeEditorGUILayout.PropertyField(_forceAimToDetectionDirection);
43+
44+
EditorGUILayout.HelpBox(
45+
"Reference Transform property is hidden. You will have to manually add it once the generator has been executed or assign it at runtime.",
46+
MessageType.Warning);
47+
48+
serializedObject.ApplyModifiedProperties();
49+
}
50+
}
51+
}

Common/Scripts/AI/Graph/Decisions/Editor/AIDecisionDetectTargetLine3DNodeEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)