Skip to content

Commit 087f4b8

Browse files
committed
Update pathway config SO to work with the latest pathway editor changes
1 parent b59f217 commit 087f4b8

File tree

11 files changed

+104
-110
lines changed

11 files changed

+104
-110
lines changed

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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,35 @@ MonoBehaviour:
1414
m_EditorClassIdentifier:
1515
_stopDuration: 0.5
1616
_speed: 1
17+
waypoints:
18+
- {x: 0, y: 0.033730388, z: 0}
19+
- {x: 0, y: 0.033730388, z: 0}
20+
- {x: 0, y: 0.033730388, z: 0}
21+
- {x: 0, y: 0.033730388, z: 0}
22+
- {x: 0, y: 0.033730388, z: 0}
23+
- {x: 0, y: 0.033730388, z: 0}
24+
- {x: 0, y: 0.033730388, z: 0}
25+
HidePathway: 0
26+
_lineColor: {r: 0, g: 0.19270587, b: 1, a: 1}
27+
_textSize: 20
28+
_textColor: {r: 1, g: 1, b: 1, a: 1}
29+
_probeRadius: 13.2
30+
DisplayProbes: 0
31+
ToggledNavMeshDisplay: 0
32+
RealTimeEnabled: 1
1733
Waypoints:
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}
25-
_pathwayEditorColor: {r: 0, g: 1, b: 1, a: 1}
34+
- waypoint: {x: -8.50028, y: 0.033730388, z: 1.5602589}
35+
corners:
36+
- {x: -8.50028, y: 0.033730388, z: 1.5602589}
37+
- {x: 2.6641674, y: 0.033730388, z: -8.3147135}
38+
- waypoint: {x: 2.6641674, y: 0.033730388, z: -8.3147135}
39+
corners:
40+
- {x: 2.6641674, y: 0.033730388, z: -8.3147135}
41+
- {x: 4, y: 0.033730388, z: -6.799999}
42+
- {x: 10.939352, y: 0.15480933, z: -0.32895184}
43+
- waypoint: {x: 10.939352, y: 0.15480933, z: -0.32895184}
44+
corners:
45+
- {x: 10.939352, y: 0.15480933, z: -0.32895184}
46+
- {x: 5.6, y: 0.033730388, z: -0.8999996}
47+
- {x: 4.8, y: 0.033730388, z: -0.8999996}
48+
- {x: -8.50028, y: 0.033730388, z: 1.5602589}

UOP1_Project/Assets/Scripts/Characters/Config/PathwayConfigSO.cs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,62 @@
44
[CreateAssetMenu(fileName = "PathwayConfig", menuName = "EntityConfig/Pathway Config")]
55
public class PathwayConfigSO : NPCMovementConfigSO
66
{
7-
[HideInInspector] public List<Vector3> Waypoints;
7+
[HideInInspector]
8+
public Vector3[] waypoints;
89

910
#if UNITY_EDITOR
1011

12+
public bool HidePathway;
13+
14+
[SerializeField]
15+
private Color _lineColor = Color.black;
16+
17+
[SerializeField, Range(0, 100)]
18+
private int _textSize = 20;
19+
1120
[SerializeField]
12-
private Color _pathwayEditorColor = Color.cyan;
13-
private int _textSize = 10;
1421
private Color _textColor = Color.white;
1522

23+
[SerializeField, Range(0, 100)]
24+
[Tooltip("This function may reduce the frame rate if a large probe radius is specified. To avoid frame rate issues," +
25+
" it is recommended that you specify a max distance of twice the agent height.")]
26+
private float _probeRadius = 3;
27+
28+
[HideInInspector]
29+
public bool DisplayProbes;
30+
31+
[HideInInspector]
32+
public bool ToggledNavMeshDisplay;
33+
34+
private List<Vector3> _path;
35+
private List<bool> _hits;
36+
1637
public const string FIELD_LABEL = "Point ";
1738
public const string TITLE_LABEL = "Waypoints";
1839

19-
public Color LineColor { get => _pathwayEditorColor; }
40+
public Color LineColor { get => _lineColor; }
2041
public Color TextColor { get => _textColor; }
2142
public int TextSize { get => _textSize; }
43+
public float ProbeRadius { get => _probeRadius; }
44+
public List<Vector3> Path { get => _path; set => _path = value; }
45+
public List<bool> Hits { get => _hits; set => _hits = value; }
46+
47+
public bool RealTimeEnabled;
48+
49+
[HideInInspector]
50+
public List<WaypointData> Waypoints;
2251

2352
#endif
53+
2454
}
55+
56+
#if UNITY_EDITOR
57+
58+
[System.Serializable]
59+
public class WaypointData
60+
{
61+
public Vector3 waypoint;
62+
public List<Vector3> corners;
63+
}
64+
65+
#endif

UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/MovementActions/PathwayMovementAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class PathwayMovementAction : NPCMovementAction
66
{
77
private NavMeshAgent _agent;
88
private bool _isActiveAgent;
9-
private List<Vector3> _wayppoints;
9+
private List<WaypointData> _wayppoints;
1010
private int _wayPointIndex;
1111
private float _roamingSpeed;
1212

@@ -46,7 +46,7 @@ private Vector3 GetNextDestination()
4646
if (_wayppoints.Count > 0)
4747
{
4848
_wayPointIndex = (_wayPointIndex + 1) % _wayppoints.Count;
49-
result = _wayppoints[_wayPointIndex];
49+
result = _wayppoints[_wayPointIndex].waypoint;
5050
}
5151
return result;
5252
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
public class PathWayNavMeshUI
66
{
7-
private Pathway _pathway;
7+
private PathwayConfigSO _pathway;
88
private PathwayNavMesh _pathwayNavMesh;
99

10-
public PathWayNavMeshUI(Pathway pathway)
10+
public PathWayNavMeshUI(PathwayConfigSO pathway)
1111
{
1212
_pathway = pathway;
1313
_pathwayNavMesh = new PathwayNavMesh(pathway);

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
using UnityEditorInternal;
44
using System.Linq;
55

6-
[CustomEditor(typeof(Pathway))]
6+
[CustomEditor(typeof(PathwayConfigSO))]
77
public class PathwayEditor : Editor
88
{
99
private ReorderableList _reorderableList;
10-
private Pathway _pathway;
10+
private PathwayConfigSO _pathway;
1111
private PathwayHandles _pathwayHandles;
1212
private PathWayNavMeshUI _pathWayNavMeshUI;
1313
private enum LIST_MODIFICATION { ADD, SUPP, DRAG, OTHER };
1414
private LIST_MODIFICATION _currentListModification;
1515
private int _indexCurrentModification;
1616

17-
public void OnSceneGUI()
17+
public void OnSceneGUI(SceneView sceneView)
1818
{
1919
int index = _pathwayHandles.DisplayHandles();
2020
_pathWayNavMeshUI.RealTime(index);
21+
PathwayGizmos.DrawGizmosSelected(_pathway, GizmoType.Active);
2122
}
2223

2324
public override void OnInspectorGUI()
@@ -40,10 +41,11 @@ private void OnEnable()
4041
_reorderableList.onRemoveCallback += RemoveItem;
4142
_reorderableList.onChangedCallback += ListModified;
4243
_reorderableList.onMouseDragCallback += DragItem;
43-
_pathway = (target as Pathway);
44+
_pathway = (target as PathwayConfigSO);
4445
_pathWayNavMeshUI = new PathWayNavMeshUI(_pathway);
4546
_pathwayHandles = new PathwayHandles(_pathway);
4647
_currentListModification = LIST_MODIFICATION.OTHER;
48+
SceneView.duringSceneGui += this.OnSceneGUI;
4749
}
4850

4951
private void OnDisable()
@@ -56,17 +58,18 @@ private void OnDisable()
5658
_reorderableList.onChangedCallback -= ListModified;
5759
_reorderableList.onMouseDragCallback -= DragItem;
5860
_pathway.waypoints = _pathway.Waypoints.Select(x => x.waypoint).ToArray();
61+
SceneView.duringSceneGui -= this.OnSceneGUI;
5962
}
6063

6164
private void DrawHeader(Rect rect)
6265
{
63-
GUI.Label(rect, Pathway.TITLE_LABEL);
66+
GUI.Label(rect, PathwayConfigSO.TITLE_LABEL);
6467
}
6568

6669
private void DrawElement(Rect rect, int index, bool active, bool focused)
6770
{
6871
SerializedProperty item = _reorderableList.serializedProperty.GetArrayElementAtIndex(index).FindPropertyRelative("waypoint");
69-
item.vector3Value = EditorGUI.Vector3Field(rect, Pathway.FIELD_LABEL + index, item.vector3Value);
72+
item.vector3Value = EditorGUI.Vector3Field(rect, PathwayConfigSO.FIELD_LABEL + index, item.vector3Value);
7073
}
7174

7275
private void AddItem(ReorderableList list)
@@ -83,7 +86,7 @@ private void AddItem(ReorderableList list)
8386
else
8487
{
8588
list.serializedProperty.InsertArrayElementAtIndex(list.serializedProperty.arraySize);
86-
Vector3 previous = _pathway.transform.position;
89+
Vector3 previous = Vector3.zero;
8790
list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1).FindPropertyRelative("waypoint").vector3Value = new Vector3(previous.x + 2, previous.y, previous.z + 2);
8891
_indexCurrentModification = list.serializedProperty.arraySize - 1;
8992
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class PathwayGizmos
66
{
77
[DrawGizmo(GizmoType.Selected)]
8-
private static void DrawGizmosSelected(Pathway pathway, GizmoType gizmoType)
8+
public static void DrawGizmosSelected(PathwayConfigSO pathway, GizmoType gizmoType)
99
{
1010
if (!pathway.ToggledNavMeshDisplay)
1111
{
@@ -20,7 +20,7 @@ private static void DrawGizmosSelected(Pathway pathway, GizmoType gizmoType)
2020
}
2121

2222

23-
private static void DrawLabel(Pathway pathway, Vector3 path, int index)
23+
private static void DrawLabel(PathwayConfigSO pathway, Vector3 path, int index)
2424
{
2525
GUIStyle style = new GUIStyle();
2626
Vector3 textHeight = Vector3.up;
@@ -31,7 +31,7 @@ private static void DrawLabel(Pathway pathway, Vector3 path, int index)
3131
Handles.Label(path + textHeight, index.ToString(), style);
3232
}
3333

34-
private static void DrawHandlesPath(Pathway pathway)
34+
private static void DrawHandlesPath(PathwayConfigSO pathway)
3535
{
3636
Handles.color = pathway.LineColor;
3737

@@ -55,7 +55,7 @@ private static void DrawHandlesPath(Pathway pathway)
5555
}
5656
}
5757

58-
private static void DrawNavMeshPath(Pathway pathway)
58+
private static void DrawNavMeshPath(PathwayConfigSO pathway)
5959
{
6060
Handles.color = pathway.LineColor;
6161

@@ -70,7 +70,7 @@ private static void DrawNavMeshPath(Pathway pathway)
7070
}
7171
}
7272

73-
private static void DrawHitPoints(Pathway pathway)
73+
private static void DrawHitPoints(PathwayConfigSO pathway)
7474
{
7575
if (pathway.DisplayProbes)
7676
{
@@ -80,13 +80,13 @@ private static void DrawHitPoints(Pathway pathway)
8080
{
8181
if (pathway.Hits[i])
8282
{
83-
Gizmos.color = new Color(0, 255, 0, 0.5f);
84-
Gizmos.DrawSphere(pathway.Waypoints[i].waypoint, sphereRadius);
83+
Handles.color = new Color(0, 255, 0, 0.1f);
84+
Handles.SphereCap(0, pathway.Waypoints[i].waypoint, Quaternion.identity, sphereRadius);
8585
}
8686
else
8787
{
88-
Gizmos.color = new Color(255, 0, 0, 0.5f);
89-
Gizmos.DrawSphere(pathway.Waypoints[i].waypoint, sphereRadius);
88+
Handles.color = new Color(255, 0, 0, 0.1f);
89+
Handles.SphereCap(0, pathway.Waypoints[i].waypoint, Quaternion.identity, sphereRadius);
9090
}
9191
}
9292
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
public class PathwayHandles
66
{
7-
private Pathway _pathway;
7+
private PathwayConfigSO _pathway;
88
private Vector3 _tmp;
99

10-
public PathwayHandles(Pathway pathway)
10+
public PathwayHandles(PathwayConfigSO pathway)
1111
{
1212
_pathway = pathway;
1313
}

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
public class PathwayNavMesh
77
{
8-
private Pathway _pathway;
8+
private PathwayConfigSO _pathway;
99

10-
public PathwayNavMesh(Pathway pathway)
10+
public PathwayNavMesh(PathwayConfigSO pathway)
1111
{
1212
_pathway = pathway;
1313
_pathway.Hits = new List<bool>();

UOP1_Project/Assets/Scripts/Pathway.meta

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

0 commit comments

Comments
 (0)