@@ -10,11 +10,13 @@ public static void DrawHandlesPath(PathwayConfigSO pathway)
10
10
{
11
11
EditorGUI . BeginChangeCheck ( ) ;
12
12
13
+ List < Vector3 > pathwayEditorDisplay = new List < Vector3 > ( ) ;
14
+
13
15
// Snap the waypoints on the NavMesh
14
16
for ( int i = 0 ; i < pathway . Waypoints . Count ; i ++ )
15
17
{
16
18
NavMesh . SamplePosition ( pathway . Waypoints [ i ] , out NavMeshHit hit , 99.0f , NavMesh . AllAreas ) ;
17
- pathway . Waypoints [ i ] = hit . position ;
19
+ pathwayEditorDisplay . Add ( hit . position ) ;
18
20
}
19
21
20
22
// Only one waypoint use case.
@@ -24,28 +26,29 @@ public static void DrawHandlesPath(PathwayConfigSO pathway)
24
26
pathway . Waypoints [ 0 ] = Handles . PositionHandle ( pathway . Waypoints [ 0 ] , Quaternion . identity ) ;
25
27
}
26
28
// 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 ++ )
28
30
{
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 ) )
30
37
{
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 ++ )
45
39
{
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 ) ;
47
41
}
48
42
}
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
+ }
49
52
}
50
53
}
51
54
0 commit comments