// Detects input from the developer within the scene view void SceneInput() { Event currentEvent = Event.current; // Create a new road section if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0 && currentEvent.shift) { Undo.RecordObject(selectedRoad, "Create Road Section"); selectedRoad.CreateRoadSection(HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition), selectedNode, selectedRoad.RoadWidth * .5f); GenerateMesh(); } // Create a new road section if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0 && currentEvent.control) { selectedRoad = network.CreateNewRoad(defaultMaterial); Undo.RecordObject(network, "Create new road"); GenerateMesh(); } // Delete an anchor, removing a road section if (currentEvent.type == EventType.MouseDown && currentEvent.button == 1) { Undo.RecordObject(network, "Remove Road Section"); selectedRoad.RemoveRoadSection(HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition), anchorNodeSize * .5f, controlNodeSize * .5f); GenerateMesh(); } // Select/deselect an anchor node if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { // Attempt to select a node and assign it to newSelectedNode int newSelectedNode = selectedRoad.SelectNode(HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition), anchorNodeSize * .5f, controlNodeSize * .5f); // If there was a node selected and now there isn't, deselect the node if (selectedNode != -1 && newSelectedNode == -1) { Undo.RecordObject(selectedRoad, "Deselect Anchor Node"); selectedNode = -1; } // If a node has been selected other than itself, select the node if (selectedNode != newSelectedNode && newSelectedNode != -1) { GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive); // Stops the road network object losing focus when the mouse is left-clicked Undo.RecordObject(selectedRoad, "Select Anchor Node"); selectedNode = newSelectedNode; currentEvent.Use(); } } // Delete the selected road when pressing DEL if (currentEvent.type == EventType.KeyDown && currentEvent.keyCode == KeyCode.Delete) { DeleteRoad(); currentEvent.Use(); } }