/// <summary> /// Find point under cursor and set variables currentPoint and cursorOverPoint. /// </summary> void HighlightVertexUnderCursor() { if (meshTransform != null && currentMeshVerises != null && MeshPointsTool.GetVisiblePointUnderCursor( currentMeshVerises.uniqueVertices, meshTransform, UnityEngine.Camera.main, Input.mousePosition, pointSelectAccuracy, out currentScreenPoint, out currentWorldPoint)) { cursorOverPoint = true; } else { cursorOverPoint = false; } if (cursorOverPoint) { MeasureToolVisualizer.instance.HighlighVertex(currentScreenPoint); } else { MeasureToolVisualizer.instance.ResetHighlight(); } }
/// <summary> /// Find mesh point under cursor and higlight it /// </summary> void HighlightPoint() { var ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.SphereCast(ray, 0.1f, out hit, 1000, 255, QueryTriggerInteraction.Collide)) { var obj = hit.collider.gameObject; var meshFilter = obj.GetComponentInChildren <MeshFilter>(); if (meshFilter != null) { var meshVertises = meshFilter.gameObject.GetComponent <Vertices>(); if (meshVertises == null) { meshVertises = meshFilter.gameObject.AddComponent <Vertices>(); } Vector2 currentScreenPoint; Vector3 currentWorldPoint; if (MeshPointsTool.GetVisiblePointUnderCursor( meshVertises.uniqueVertices, meshFilter.gameObject.transform, UnityEngine.Camera.main, Input.mousePosition, pointSelectAccuracy, out currentScreenPoint, out currentWorldPoint)) { MeasureToolVisualizer.instance.HighlighVertex(currentScreenPoint); if (Input.GetMouseButton(0)) { isPointJoining = true; pointJoinBrick = hit.collider; pointJointDragOffset = currentWorldPoint - obj.transform.position; //prepare undo nodes historyNodes = HistoryTool.PrepareTransformNodes(obj); } } else { MeasureToolVisualizer.instance.ResetHighlight(); } } } }
void MovePointToPoint() { pointJoinBrick.enabled = false; var ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.SphereCast(ray, 0.1f, out hit, 1000, 255, QueryTriggerInteraction.Collide)) { var obj = hit.collider.gameObject; var meshFilter = obj.GetComponentInChildren <MeshFilter>(); if (meshFilter != null) { var meshVertises = meshFilter.gameObject.GetComponent <Vertices>(); if (meshVertises == null) { meshVertises = meshFilter.gameObject.AddComponent <Vertices>(); } Vector2 currentScreenPoint; Vector3 currentWorldPoint; if (MeshPointsTool.GetVisiblePointUnderCursor( meshVertises.uniqueVertices, meshFilter.gameObject.transform, UnityEngine.Camera.main, Input.mousePosition, pointSelectAccuracy, out currentScreenPoint, out currentWorldPoint)) { //move brick to jointpoints var pos = currentWorldPoint - pointJointDragOffset; pointJoinBrick.transform.position = pos; } } } pointJoinBrick.enabled = true; }
void HandleStickyMove(PointerEventData eventData) { var selectioManager = SelectionManager.instance; var seleted = selectioManager.GetSelected(); //change temporary layer of selcted bricks (that are under movement) foreach (var sel in seleted) { sel.gameObject.layer = 9; } var ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000f, 1, QueryTriggerInteraction.Collide)) { var go = hit.collider.gameObject; var meshFilter = go.GetComponentInChildren <MeshFilter>(); if (meshFilter != null) { var currentMeshVerises = meshFilter.gameObject.GetComponent <Vertices>(); if (currentMeshVerises == null) { currentMeshVerises = meshFilter.gameObject.AddComponent <Vertices>(); } Vector2 currentScreenPoint; Vector3 currentWorldPoint; if (MeshPointsTool.GetVisiblePointUnderCursor( currentMeshVerises.uniqueVertices, meshFilter.gameObject.transform, UnityEngine.Camera.main, Input.mousePosition, pointSelectAccuracy, out currentScreenPoint, out currentWorldPoint)) { MeasureToolVisualizer.instance.HighlighVertex(currentScreenPoint); //move there Vector3 relPos = currentWorldPoint - cone.position; ChangePosition(relPos); } else { MeasureToolVisualizer.instance.ResetHighlight(); } } else { MeasureToolVisualizer.instance.ResetHighlight(); } } else { MeasureToolVisualizer.instance.ResetHighlight(); } //set back default layer mask for seleced foreach (var sel in seleted) { sel.gameObject.layer = 0; } }