private void CheckTouch(Touch touch) { Vector3 v3; #if UNITY_EDITOR var pos = Input.mousePosition; #else var pos = touch.position; #endif //UNITY_EDITOR if (EditorInput.GetState(touch, EditorInput.InputState.Began)) { Dragging = false; _prisonerTransform = null; RaycastHit hit; var ray = Camera.main.ScreenPointToRay(pos); if (Physics.Raycast(ray, out hit)) { _prisonerAi = hit.collider.GetComponent <PrisonerAi>(); if (_prisonerAi == null) { return; } _prisonerTransform = hit.transform; _prisonerAi.Rigidbody.isKinematic = true; _dist = hit.transform.position.z - Camera.main.transform.position.z; v3 = new Vector3(pos.x, pos.y, _dist); v3 = Camera.main.ScreenToWorldPoint(v3); _offset = _prisonerTransform.position - v3; Dragging = true; } } if (Dragging && EditorInput.GetState(touch, EditorInput.InputState.Moving)) { v3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, _dist); v3 = Camera.main.ScreenToWorldPoint(v3); if (_prisonerTransform != null) { _prisonerTransform.position = v3 + _offset; } } if (Dragging && (EditorInput.GetState(touch, EditorInput.InputState.Ended) || EditorInput.GetState(touch, EditorInput.InputState.Canceled))) { Dragging = false; _objectPool.SetAllFree(); } }
private void CheckTouch(Touch touch) { Vector3 v3; #if UNITY_EDITOR var pos = Input.mousePosition; #else var pos = touch.position; #endif //UNITY_EDITOR if (EditorInput.GetState(touch, EditorInput.InputState.Began)) { Dragging = false; _prisonerTransform = null; RaycastHit hit; var ray = Camera.main.ScreenPointToRay(pos); if (Physics.Raycast(ray, out hit)) { _prisonerAi = hit.collider.GetComponent<PrisonerAi>(); if (_prisonerAi == null) return; _prisonerTransform = hit.transform; _prisonerAi.Rigidbody.isKinematic = true; _dist = hit.transform.position.z - Camera.main.transform.position.z; v3 = new Vector3(pos.x, pos.y, _dist); v3 = Camera.main.ScreenToWorldPoint(v3); _offset = _prisonerTransform.position - v3; Dragging = true; } } if (Dragging && EditorInput.GetState(touch, EditorInput.InputState.Moving)) { v3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, _dist); v3 = Camera.main.ScreenToWorldPoint(v3); if (_prisonerTransform != null) _prisonerTransform.position = v3 + _offset; } if (Dragging && (EditorInput.GetState(touch, EditorInput.InputState.Ended) || EditorInput.GetState(touch, EditorInput.InputState.Canceled))) { Dragging = false; _objectPool.SetAllFree(); } }