// Update is called once per frame void Update() { Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hitInfo) && Input.GetMouseButtonDown(0)) { if (hitInfo.transform.name == "x" || hitInfo.transform.name == "y" || hitInfo.transform.name == "z") { CurrentAxis = hitInfo.transform.name; } } SwipeInfo swipeInfo = SwipeInfo.GetSwipeInfo(ref isClick); if (swipeInfo == null) { return; } TransfromWithCameraDegree(swipeInfo, CurrentAxis); FollowObject.transform.position = transform.position - followObjectOffset; }
// 在屏幕坐标下进行z方向的移动 void ZTransformInScreen() { SwipeInfo swipeInfo = SwipeInfo.GetSwipeInfo(ref isClickZ); if (swipeInfo == null) { return; } // 特殊处理 // 模型xyz均与世界坐标指向相同 // 1. 获取当前相机z轴与世界坐标z轴夹角(rotation.y),从而确定模型z轴相对于自身指向 // 2. 获取手指滑动的方向及距离 // 3. 根据1,2获取的数据进行平移 Vector3 angles = cam.transform.eulerAngles; //print("angles:" + angles); float zRotation = angles.y % 360; // 模型不动,相机顺时针旋转 // z轴指向相机前方 if ((zRotation <= 45 && zRotation >= 0) || zRotation >= 315 || (zRotation <= 0 && zRotation >= -45) || zRotation <= -315) { //print("z轴指向相机前方"); if (swipeInfo.UpDistance > 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + swipeInfo.UpDistance / zTransformSpeed); } else if (swipeInfo.DownDistance < 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + swipeInfo.DownDistance / zTransformSpeed); } } // z轴指向相机左侧, else if ((zRotation > 45 && zRotation <= 135) || (zRotation > -315 && zRotation <= -225)) { // print("z轴指向相机左侧"); if (swipeInfo.RightDistance > 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + swipeInfo.RightDistance / zTransformSpeed); } else if (swipeInfo.LeftDistance < 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + swipeInfo.LeftDistance / zTransformSpeed); } } // z轴指向相机后方 else if ((zRotation > 135 && zRotation <= 225) || (zRotation > -225 && zRotation <= -135)) { //print("z轴指向相机后方"); if (swipeInfo.UpDistance > 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - swipeInfo.UpDistance / zTransformSpeed); } else if (swipeInfo.DownDistance < 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - swipeInfo.DownDistance / zTransformSpeed); } } // z轴指向相机右侧 else if ((zRotation > 225 && zRotation < 315) || (zRotation > -135 && zRotation <= -45)) { //print("z轴指向相机右侧"); if (swipeInfo.RightDistance > 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - swipeInfo.RightDistance / zTransformSpeed); } else if (swipeInfo.LeftDistance < 0) { transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - swipeInfo.LeftDistance / zTransformSpeed); } } }