void DrawOnMouse() { if (!CanDraw) { return; } Vector3 mousePosition = arCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, lineSettings.distanceFromCamera)); if (Input.GetMouseButton(0)) { OnDraw?.Invoke(); if (Lines.Keys.Count == 0) { ARLine line = new ARLine(lineSettings); Lines.Add(0, line); line.AddNewLineRenderer(transform, null, mousePosition); } else { Lines[0].AddPoint(mousePosition); } } else if (Input.GetMouseButtonUp(0)) { Lines.Remove(0); } }
void DrawOnTouch() { if (!CanDraw) { return; } int tapCount = Input.touchCount > 1 && lineSettings.allowMultiTouch ? Input.touchCount : 1; for (int i = 0; i < tapCount; i++) { Touch touch = Input.GetTouch(i); Vector3 touchPosition = arCamera.ScreenToWorldPoint(new Vector3(Input.GetTouch(i).position.x, Input.GetTouch(i).position.y, lineSettings.distanceFromCamera)); ARDebugManager.Instance.LogInfo($"{touch.fingerId}"); if (touch.phase == TouchPhase.Began) { OnDraw?.Invoke(); ARAnchor anchor = anchorManager.AddAnchor(new Pose(touchPosition, Quaternion.identity)); if (anchor == null) { Debug.LogError("Error creating reference point"); } else { anchors.Add(anchor); ARDebugManager.Instance.LogInfo($"Anchor created & total of {anchors.Count} anchor(s)"); } ARLine line = new ARLine(lineSettings); Lines.Add(touch.fingerId, line); line.AddNewLineRenderer(transform, anchor, touchPosition); } else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { Lines[touch.fingerId].AddPoint(touchPosition); } else if (touch.phase == TouchPhase.Ended) { Lines.Remove(touch.fingerId); } } }