public void OnDragPointView(PointView pointView, PointerEventData eventData) { var point = pointView.point; var bridge = pointView.bridge; var position = GetPointOnBuildPlane(eventData); if (!position.HasValue) { Debug.LogWarning("No point on build plane"); return; } if (selectedTool == Tool.Move) { point.Move(position.Value); } if (selectedTool == Tool.Build) { var startPoint = point.StartPosition; var stress = Vector2.Distance(startPoint, position.Value) > bridge.maxLengths[selectedType] ? 1 : 0; ghostConnectionView.Setposition(startPoint, position.Value, stress); } }
public void OnClickPointView(PointView pointView, PointerEventData eventData) { if (selectedTool == Tool.Delete) { pointView.bridge.RemovePoint(pointView.point); } }
public void OnEndDragPointView(PointView pointView, PointerEventData eventData) { var point = pointView.point; var bridge = pointView.bridge; ghostConnectionView.transform.position = new Vector3(0, 0, -1000); if (selectedTool == Tool.Build) { var hit = GetPointViewAt(eventData, pointView); if (hit != null) { bridge.AddConnection(point, hit.point, selectedType); } else { var position = GetPointOnBuildPlane(eventData); if (position.HasValue) { if (Vector2.Distance(point.StartPosition, position.Value) > bridge.maxLengths[selectedType]) { return; } var newPoint = bridge.AddPoint(position.Value); bridge.AddConnection(point, newPoint, selectedType); } } } }
private PointView GetPointViewAt(PointerEventData eventData, PointView ignore) { var position = GetPointOnBuildPlane(eventData); if (!position.HasValue) { return(null); } foreach (var point in FindObjectsOfType <PointView>()) { if (point == ignore) { continue; } if (Vector2.Distance(position.Value, point.transform.position) <= 0.1) { return(point); } } return(null); }