private void Update() { if (!isDragging) { return; } // todo: skips points, should check if next point is in close proximity etc. // todo: does not work well with self-intersecting paths var newPosition = (Vector2)Input.mousePosition - new Vector2(Screen.width / 2f, Screen.height / 2f) - dragOffset; var distances = evenlySpacedPoints.Select(p => Vector2.Distance(p, newPosition)).ToArray(); var distance = distances.Min(); var accuracy = 1f - distance / accuracyThreshold; if (accuracy <= 0) { isDragging = false; OnDragStopped?.Invoke(false, startPointIndex, evenlySpacedPoints.Count); return; } var index = Array.IndexOf(distances, distance); switch (dragDirection) { case DragDirection.OnlyForward when index <= startPointIndex: case DragDirection.OnlyBackward when index >= startPointIndex: return; } startPointIndex = index; UpdatePosition(); UpdateRotation(); OnDragProgress?.Invoke(accuracy, startPointIndex, evenlySpacedPoints.Count); // todo: works only if dragDirection = forward if (startPointIndex == evenlySpacedPoints.Count - 1) { OnDragStopped?.Invoke(true, startPointIndex, evenlySpacedPoints.Count); } }
public void OnPointerUp(PointerEventData eventData) { isDragging = false; OnDragStopped?.Invoke(false, startPointIndex, evenlySpacedPoints.Count); }