private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit result; if (Physics.Raycast(ray, out result)) { EditableThing thing = result.collider.GetComponent <EditableThing>(); if (thing != null) { currentDragging = thing; } } } else if (Input.GetMouseButton(0)) { if (currentDragging != null) { Vector3 mousePosition = Input.mousePosition; mousePosition.z = currentDragging.transform.position.z - Camera.main.transform.position.z; Vector3 desiredPosition = Camera.main.ScreenToWorldPoint(mousePosition); desiredPosition.z = currentDragging.transform.position.z; currentDragging.UpdatePosition(desiredPosition); } } if (Input.GetMouseButtonUp(0)) { currentDragging = null; } }
public override void ChangePinchState(int type, bool pinchStarted) { if (pinchStarted) { if (HandStateManager.Instance.state == HandState.Idle) { Vector3 point = (fingers[type, 0].position + fingers[type, 1].position) / 2f; Collider[] cols = Physics.OverlapSphere(point, editRadius, Values.EditableLayerMask); if (cols != null && cols.Length >= 1) { Collider col = null; float minMag = 99999f; foreach (var _col in cols) { float mag = Vector3.Magnitude(point - _col.transform.position); if (mag < minMag) { col = _col; minMag = mag; } } // Start edit currentHandType = type; currentEditing = col.GetComponent <EditableThing>(); currentEditing.SetOnSelected(true); HandStateManager.Instance.state = HandState.Editing; } } } else { if (currentHandType == type && currentEditing != null) { // Stop edit currentEditing.SetOnSelected(true); currentEditing = null; HandStateManager.Instance.state = HandState.Idle; } } }