private static bool IsTouchExisting(PickedPoint existingPoint, Vector2 touchPoint, Rect rect) { bool touched = false; try { double threshold = ((double)rect.width * TouchThresholdCoeff + rect.height * TouchThresholdCoeff) / 2; if (Vector2.Distance(existingPoint.Location, touchPoint) <= threshold) { touched = true; } } catch (UnityException exp) { Debug.LogError(exp.Message); } return(touched); }
private static Rect DrawPhotoBox(IWizardPage wizardPage, Texture2D texture) { var boxRect = new Rect(110, 70, 400, 400); try { GUI.Box(boxRect, ""); GUIUtils.TouchInfo touchInfo; lastTextureRect = GUIUtils.DrawTouchableTexture(boxRect, texture, out touchInfo); if (wizardPage is IWizardFeaturePointPage) { IWizardFeaturePointPage pointPage = (IWizardFeaturePointPage)wizardPage; if (touchInfo.isTouching && touchInfo.touchInside) { bool collidingExistingPoint = false; PickedPoint collidingPoint = new PickedPoint(); foreach (PickedPoint existingPoint in pointPage.Points) { Rect testRect = new Rect(boxRect); if (IsTouchExisting(existingPoint, touchInfo.textureTouchPosition, testRect)) { collidingExistingPoint = true; collidingPoint = existingPoint; break; } } if (!collidingExistingPoint && addingPoint) { PickedPoint pickedPt = new PickedPoint(touchInfo.textureTouchPosition, touchInfo.relativePercentageTouchPosition); pointPage.Points.Add(pickedPt); } else if (collidingExistingPoint && removingPoint) { pointPage.Points.Remove(collidingPoint); Debug.Log("Removing point at " + collidingPoint.Location); } } else if (touchInfo.isTouching && !touchInfo.touchInside) { } if (undoPoint) { int ptCnt = pointPage.Points.Count; if (1 <= ptCnt) { pointPage.Points.RemoveAt(ptCnt - 1); } undoPoint = false; } ActiveWindow.Repaint(); } } catch (UnityException exp) { Debug.LogError(exp.Message); } return(boxRect); }