Skip to content

Commit 914f05a

Browse files
committed
Cleaned up + Protect waypoint inputs from updated by NavMesh
1 parent 820fa83 commit 914f05a

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ private void OnEnable()
3131
_reorderableList.drawElementCallback += DrawElement;
3232
_reorderableList.onAddCallback += AddItem;
3333
_reorderableList.onRemoveCallback += RemoveItem;
34-
_reorderableList.onSelectCallback += SelectItem;
3534
_reorderableList.onChangedCallback += ListModified;
3635
_pathway = (target as PathwayConfigSO);
3736
if (CheckNavMeshExistence())
@@ -51,7 +50,6 @@ private void OnDisable()
5150
_reorderableList.drawElementCallback -= DrawElement;
5251
_reorderableList.onAddCallback -= AddItem;
5352
_reorderableList.onRemoveCallback -= RemoveItem;
54-
_reorderableList.onSelectCallback -= SelectItem;
5553
_reorderableList.onChangedCallback -= ListModified;
5654
SceneView.duringSceneGui -= this.OnSceneGUI;
5755
}
@@ -105,11 +103,6 @@ private void RemoveItem(ReorderableList list)
105103

106104
}
107105

108-
private void SelectItem(ReorderableList list)
109-
{
110-
InternalEditorUtility.RepaintAllViews();
111-
}
112-
113106
private void ListModified(ReorderableList list)
114107
{
115108
list.serializedProperty.serializedObject.ApplyModifiedProperties();

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ public static void DrawHandlesPath(PathwayConfigSO pathway)
1010
{
1111
EditorGUI.BeginChangeCheck();
1212

13+
List<Vector3> pathwayEditorDisplay = new List<Vector3>();
14+
1315
// Snap the waypoints on the NavMesh
1416
for (int i = 0; i < pathway.Waypoints.Count; i++)
1517
{
1618
NavMesh.SamplePosition(pathway.Waypoints[i], out NavMeshHit hit, 99.0f, NavMesh.AllAreas);
17-
pathway.Waypoints[i] = hit.position;
19+
pathwayEditorDisplay.Add(hit.position);
1820
}
1921

2022
// Only one waypoint use case.
@@ -24,28 +26,29 @@ public static void DrawHandlesPath(PathwayConfigSO pathway)
2426
pathway.Waypoints[0] = Handles.PositionHandle(pathway.Waypoints[0], Quaternion.identity);
2527
}
2628
// All the other use cases where a path exists.
27-
else if (pathway.Waypoints.Count > 1)
29+
for (int index = 0; index < pathway.Waypoints.Count && pathway.Waypoints.Count > 1; index++)
2830
{
29-
for (int index = 0; index < pathway.Waypoints.Count && pathway.Waypoints.Count > 1; index++)
31+
int nextIndex = (index + 1) % pathway.Waypoints.Count;
32+
DrawWaypointLabel(pathway, pathway.Waypoints, index);
33+
List<Vector3> navMeshPath = new List<Vector3>();
34+
NavMeshPath navPath = new NavMeshPath();
35+
NavMesh.CalculatePath(pathwayEditorDisplay[index], pathwayEditorDisplay[nextIndex], NavMesh.AllAreas, navPath);
36+
using (new Handles.DrawingScope(pathway.LineColor))
3037
{
31-
int nextIndex = (index + 1) % pathway.Waypoints.Count;
32-
DrawWaypointLabel(pathway, pathway.Waypoints, index);
33-
List<Vector3> navMeshPath = new List<Vector3>();
34-
NavMeshPath navPath = new NavMeshPath();
35-
NavMesh.CalculatePath(pathway.Waypoints[index], pathway.Waypoints[nextIndex], NavMesh.AllAreas, navPath);
36-
using (new Handles.DrawingScope(pathway.LineColor))
37-
{
38-
for (int j = 0; j < navPath.corners.Length - 1; j++)
39-
{
40-
Handles.DrawDottedLine(navPath.corners[j], navPath.corners[j + 1], 2);
41-
}
42-
}
43-
// Display handles pointing into the path forward direction (Blue handle)
44-
if (navPath.corners.Length > 1)
38+
for (int j = 0; j < navPath.corners.Length - 1; j++)
4539
{
46-
pathway.Waypoints[index] = Handles.PositionHandle(pathway.Waypoints[index], Quaternion.LookRotation(navPath.corners[1] - navPath.corners[0]));
40+
Handles.DrawDottedLine(navPath.corners[j], navPath.corners[j + 1], 2);
4741
}
4842
}
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+
}
48+
else
49+
{
50+
pathway.Waypoints[index] = Handles.PositionHandle(pathway.Waypoints[index], Quaternion.identity);
51+
}
4952
}
5053
}
5154

0 commit comments

Comments
 (0)