Skip to content

Commit 820fa83

Browse files
committed
Made the handles pointing into the forward direction of the pathway
1 parent 9c04be5 commit 820fa83

File tree

5 files changed

+29
-53
lines changed

5 files changed

+29
-53
lines changed

UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ MonoBehaviour:
1515
_stopDuration: 0.5
1616
_speed: 1
1717
Waypoints:
18-
- {x: 3.4739745, y: 0.033730388, z: 0.6266351}
19-
- {x: 12.061079, y: 0.15954088, z: 9.731606}
20-
- {x: -6.2887483, y: 0.033730388, z: 7.971367}
21-
- {x: -15.76542, y: 0.033730388, z: -0.2936163}
22-
- {x: -11.600259, y: 0.033730388, z: -4.42002}
18+
- {x: 3.46387, y: 0.033730388, z: 0.55213976}
19+
- {x: 5.6019807, y: 0.052446984, z: 7.11369}
20+
- {x: -2.8645186, y: 0.033730388, z: 8.923655}
21+
- {x: -6.567141, y: 0.033730388, z: -5.250761}
22+
- {x: -9.866049, y: 0.033730388, z: -5.822654}
23+
- {x: -11.059804, y: 0.033730388, z: -2.8135128}
24+
- {x: -2.0687637, y: 0.033730388, z: 0.8148103}
2325
_pathwayEditorColor: {r: 0, g: 1, b: 1, a: 1}

UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ public class PathwayEditor : Editor
99
{
1010
private ReorderableList _reorderableList;
1111
private PathwayConfigSO _pathway;
12-
private PathwayHandles _pathwayHandles;
1312

1413
public void OnSceneGUI(SceneView sceneView)
1514
{
16-
_pathwayHandles.DispalyHandles();
1715
PathwayGizmos.DrawHandlesPath(_pathway);
1816
}
1917

@@ -36,7 +34,6 @@ private void OnEnable()
3634
_reorderableList.onSelectCallback += SelectItem;
3735
_reorderableList.onChangedCallback += ListModified;
3836
_pathway = (target as PathwayConfigSO);
39-
_pathwayHandles = new PathwayHandles(_pathway);
4037
if (CheckNavMeshExistence())
4138
{
4239
SceneView.duringSceneGui += this.OnSceneGUI;

UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@ public class PathwayGizmos
88
{
99
public static void DrawHandlesPath(PathwayConfigSO pathway)
1010
{
11-
if (pathway.Waypoints.Count != 0)
11+
EditorGUI.BeginChangeCheck();
12+
13+
// Snap the waypoints on the NavMesh
14+
for (int i = 0; i < pathway.Waypoints.Count; i++)
15+
{
16+
NavMesh.SamplePosition(pathway.Waypoints[i], out NavMeshHit hit, 99.0f, NavMesh.AllAreas);
17+
pathway.Waypoints[i] = hit.position;
18+
}
19+
20+
// Only one waypoint use case.
21+
if (pathway.Waypoints.Count == 1)
1222
{
13-
DrawElements(pathway, pathway.Waypoints, 0);
23+
DrawWaypointLabel(pathway, pathway.Waypoints, 0);
24+
pathway.Waypoints[0] = Handles.PositionHandle(pathway.Waypoints[0], Quaternion.identity);
1425
}
15-
if (pathway.Waypoints.Count > 1)
26+
// All the other use cases where a path exists.
27+
else if (pathway.Waypoints.Count > 1)
1628
{
1729
for (int index = 0; index < pathway.Waypoints.Count && pathway.Waypoints.Count > 1; index++)
1830
{
1931
int nextIndex = (index + 1) % pathway.Waypoints.Count;
20-
DrawElements(pathway, pathway.Waypoints, index);
32+
DrawWaypointLabel(pathway, pathway.Waypoints, index);
2133
List<Vector3> navMeshPath = new List<Vector3>();
2234
NavMeshPath navPath = new NavMeshPath();
2335
NavMesh.CalculatePath(pathway.Waypoints[index], pathway.Waypoints[nextIndex], NavMesh.AllAreas, navPath);
@@ -28,11 +40,16 @@ public static void DrawHandlesPath(PathwayConfigSO pathway)
2840
Handles.DrawDottedLine(navPath.corners[j], navPath.corners[j + 1], 2);
2941
}
3042
}
43+
// Display handles pointing into the path forward direction (Blue handle)
44+
if (navPath.corners.Length > 1)
45+
{
46+
pathway.Waypoints[index] = Handles.PositionHandle(pathway.Waypoints[index], Quaternion.LookRotation(navPath.corners[1] - navPath.corners[0]));
47+
}
3148
}
3249
}
3350
}
3451

35-
private static void DrawElements(PathwayConfigSO pathway, List<Vector3> path, int index)
52+
private static void DrawWaypointLabel(PathwayConfigSO pathway, List<Vector3> path, int index)
3653
{
3754
GUIStyle style = new GUIStyle();
3855
Vector3 textHeight = Vector3.up;

UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)