public Waypoint CreateNextWaypoint(Waypoint waypoint) { Waypoint wp = CreateWaypoint(waypoint.transform.position + (Vector3.forward * 5), GetParent()); waypoint.AddNext(wp); return(wp); }
private void DrawNavigationSection() { DrawHeadline("Navigation"); // If no or an invalid object is selected display some information if (Selection.activeGameObject == null) { GUILayout.Label("Select a waypoint or road to begin"); } // If a waypoint is selected display the actions available for working with waypoints else if (Selection.activeGameObject.GetComponent <Waypoint>() != null) { Waypoint selectedWaypoint = Selection.activeGameObject.GetComponent <Waypoint>(); // If we are in build mode show relevant actions if (editorState == State.Building) { if (GUILayout.Button("Create next waypoint")) { Waypoint newWaypoint = navigationEditor.CreateNextWaypoint(selectedWaypoint); Selection.objects = new Object[] { newWaypoint.gameObject }; } // If the user clicks connect waypoint we switch to connecting mode and switch actions if (GUILayout.Button("Connect waypoint")) { startWaypoint = selectedWaypoint; editorState = State.Connecting; } } // When in connecting mode we display the relevant options else if (editorState == State.Connecting) { // Terminate connecting mode and switch back to build mode if (GUILayout.Button("Stop connecting")) { editorState = State.Building; } // If the user selects a new waypoint and this waypoint is not the same we // create a connection between the two waypoints and switch back to build mode if (!startWaypoint.Equals(selectedWaypoint)) { if (GUILayout.Button("Create connection")) { startWaypoint.AddNext(selectedWaypoint); startWaypoint = null; editorState = State.Building; } } else { GUILayout.Label("Select a different waypoint to connect"); } } } // If a road is selected assume the user wants to create a new waypoint to start from else if (Selection.activeGameObject.GetComponent <Road>() != null) { if (GUILayout.Button("Create new waypoint")) { Road road = Selection.activeGameObject.GetComponent <Road>(); Waypoint waypoint = navigationEditor.CreateWaypoint(road); Selection.objects = new Object[] { waypoint.gameObject }; } } }