|
@@ -21,6 +21,10 @@ public class RoutesEditor : Editor
|
|
|
private SceneView sceneView;
|
|
|
private readonly List<Turn> selectedTurns = new List<Turn>();
|
|
|
|
|
|
+ private Route route;
|
|
|
+
|
|
|
+ private static float length = 0;
|
|
|
+
|
|
|
private static readonly Dictionary<RoadDirection, int> roadDirectionIndexes = new Dictionary<RoadDirection, int>
|
|
|
{
|
|
|
{RoadDirection.West, 0},
|
|
@@ -36,10 +40,16 @@ public class RoutesEditor : Editor
|
|
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("start"));
|
|
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("finish"));
|
|
|
RoutesList(serializedObject.FindProperty("items"));
|
|
|
+ EditorGUILayout.LabelField($"Current length: {length}");
|
|
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
}
|
|
|
|
|
|
+ private void OnEnable()
|
|
|
+ {
|
|
|
+ route = (Route) target;
|
|
|
+ }
|
|
|
+
|
|
|
private void OnSceneGUI()
|
|
|
{
|
|
|
if (inSelectionMode)
|
|
@@ -205,32 +215,48 @@ public class RoutesEditor : Editor
|
|
|
|
|
|
return roadDirectionIndexes[direction];
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
[DrawGizmo(GizmoType.Selected)]
|
|
|
private static void DrawRoutePreview(Route route, GizmoType gizmoType)
|
|
|
{
|
|
|
+ length = 0f;
|
|
|
if (route.items == null) return;
|
|
|
Gizmos.color = Color.red;
|
|
|
Turn previousTurn = null;
|
|
|
+
|
|
|
+ Vector3 from;
|
|
|
+ Vector3 to;
|
|
|
+
|
|
|
+ if (route.start != null && route.items.Count > 0)
|
|
|
+ {
|
|
|
+ from = route.start.transform.position;
|
|
|
+ to = route.items[0].turn.transform.position;
|
|
|
+ length += (to - from).magnitude;
|
|
|
+ Helpers.DrawLine(from, to, 3);
|
|
|
+ }
|
|
|
+
|
|
|
foreach (var item in route.items)
|
|
|
{
|
|
|
var turn = item.turn;
|
|
|
|
|
|
if (previousTurn != null)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Helpers.DrawLine(previousTurn.transform.position, turn.transform.position, 3);
|
|
|
+ from = previousTurn.transform.position;
|
|
|
+ to = turn.transform.position;
|
|
|
+ length += (to - from).magnitude;
|
|
|
+ Helpers.DrawLine(from, to, 3);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
previousTurn = turn;
|
|
|
}
|
|
|
|
|
|
+ if (route.finish != null && route.items.Count > 0)
|
|
|
+ {
|
|
|
+ from = route.items.Last().turn.transform.position;
|
|
|
+ to = route.finish.transform.position;
|
|
|
+ length += (to - from).magnitude;
|
|
|
+ Helpers.DrawLine(from, to, 3);
|
|
|
+ }
|
|
|
}
|
|
|
}
|