private static void _EditRoad_Create_DrawNextPathPreview(RoadRoot root, Event e, int controlID) { RoadCreateOperation op = root.currentOperation as RoadCreateOperation; if (op == null) { return; } Ray r = HandleUtility.GUIPointToWorldRay(e.mousePosition); RaycastHit hit; if (Physics.Raycast(r, out hit)) { Waypoint from = op.lastWaypoint; Vector3 curPos = hit.point; Vector3 tangent = Vector3.Lerp(from.transform.position, curPos, 0.5f); Handles.DrawBezier(from.transform.position, // start pos curPos, // end pos tangent, // start tangent tangent, // end tangent Color.magenta, // color null, // Texture 3.0f); // width } }
public Operation BeginCreateRoadOperation(Vector3 position) { RoadCreateOperation r = new RoadCreateOperation(this); r.Begin(position); currentOperation = r; return(r); }
/// <summary> /// HACK: force invoke Repaint Event in SceneView. /// OnSceneGUI() will not be redrawn unless Repaint Event is kicked, /// so moving last waypoint by zero to force make repaint happen. /// </summary> private static void _EditRoad_Create_ForceInvokeRepaint(RoadRoot root) { RoadCreateOperation op = root.currentOperation as RoadCreateOperation; if (op != null) { op.lastWaypoint.transform.Translate(new Vector3(0, 0, 0)); } }
private static void _EditRoad_Create(RoadRoot root, Event e, int controlID) { switch (e.GetTypeForControl(controlID)) { case EventType.mouseMove: // to draw preview line in scene, invoke repaint event when mouse is moved. _EditRoad_Create_ForceInvokeRepaint(root); break; case EventType.Repaint: _EditRoad_Create_DrawNextPathPreview(root, e, controlID); break; case EventType.MouseDown: GUIUtility.hotControl = controlID; if (e.clickCount == 2) { RoadCreateOperation op = root.currentOperation as RoadCreateOperation; if (op != null) { Selection.activeGameObject = op.End(); } } Event.current.Use(); break; case EventType.MouseUp: GUIUtility.hotControl = 0; Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { RoadCreateOperation op = root.currentOperation as RoadCreateOperation; if (op == null) { root.BeginCreateRoadOperation(hit.point); } else { op.Continue(hit.point); } } Event.current.Use(); break; } }