void TransformSelected() { if (Input.GetMouseButtonDown(0)) { axis = selectedObj.Direction; previousMousePosition = Vector3.zero; } if (Input.GetMouseButton(0)) { if (selectedObj.Started) { ray = viewCamera.ScreenPointToRay(Input.mousePosition); Vector3 mousePosition = GeometryUtil.LinePlaneIntersect(ray.origin, ray.direction, selectedObj.transform.position, axis); if (previousMousePosition != Vector3.zero && mousePosition != Vector3.zero) { var vec1 = previousMousePosition - selectedObj.transform.position; var vec2 = mousePosition - selectedObj.transform.position; float rotateAmount = (Vector3.Angle(Vector3.Cross(vec1, vec2), axis) < 180f ? 1 : -1) * Vector3.Angle(vec1, vec2) * 1; selectedObj.Rotate(rotateAmount); } previousMousePosition = mousePosition; } } if (Input.GetMouseButtonUp(0)) { selectedObj.Clamp(); selectedObj = null; } }
private void TrySelectRotateObj() { if (viewCamera == null) { return; } ray = viewCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, distence, rotateItemLayerMask)) { selectedObj = hit.collider.GetComponentInParent <RotObj>(); } }