void Update() { // Get mouse movement to orbit the camera. #if UNITY_IOS || UNITY_ANDROID //Mobile: // Touch: if (Input.touchCount > 0) { for (int i = 0; i < Input.touchCount; ++i) { if (Input.touches[i].phase == TouchPhase.Moved && Input.touches[i].position.x > Screen.width / 2 && !EventSystem.current.IsPointerOverGameObject(Input.touches[i].fingerId) && PlayerInputManager.getins().allowturning) { angleH += Input.touches[i].deltaPosition.x * MPlayerSetting.GetIns().horizontalAimingSpeed; angleV += Input.touches[i].deltaPosition.y * MPlayerSetting.GetIns().verticalAimingSpeed; break; } } } // Gyro: angleV += Input.gyro.rotationRateUnbiased.x * MPlayerSetting.GetIns().GyroMul; angleH -= Input.gyro.rotationRateUnbiased.y * MPlayerSetting.GetIns().GyroMul; #else // Mouse: angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * MPlayerSetting.GetIns().horizontalAimingSpeed; angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * MPlayerSetting.GetIns().verticalAimingSpeed; // Joystick: angleH += Mathf.Clamp(Input.GetAxis(XAxis), -1, 1) * 60 * MPlayerSetting.GetIns().horizontalAimingSpeed *Time.deltaTime; angleV += Mathf.Clamp(Input.GetAxis(YAxis), -1, 1) * 60 * MPlayerSetting.GetIns().verticalAimingSpeed *Time.deltaTime; #endif // Set vertical movement limit. angleV = Mathf.Clamp(angleV, minVerticalAngle, targetMaxVerticalAngle); // Set camera orientation. Quaternion camYRotation = Quaternion.Euler(0, angleH, 0); Quaternion aimRotation = Quaternion.Euler(-angleV, angleH, 0); cam.rotation = aimRotation; // Set FOV. cam.GetComponent <Camera>().fieldOfView = Mathf.Lerp(cam.GetComponent <Camera>().fieldOfView, targetFOV, Time.deltaTime); // Test for collision with the environment based on current camera position. Vector3 baseTempPosition = player.position + camYRotation * targetPivotOffset; Vector3 noCollisionOffset = targetCamOffset; for (float zOffset = targetCamOffset.z; zOffset <= 0; zOffset += 0.5f) //相机向前移动 { noCollisionOffset.z = zOffset; if (DoubleViewingPosCheck(baseTempPosition + aimRotation * noCollisionOffset, Mathf.Abs(zOffset)) || zOffset == 0) { break; } } // Repostition the camera. smoothPivotOffset = Vector3.Lerp(smoothPivotOffset, targetPivotOffset, smooth * Time.deltaTime); smoothCamOffset = Vector3.Lerp(smoothCamOffset, noCollisionOffset, smooth * Time.deltaTime); cam.position = player.position + camYRotation * smoothPivotOffset + aimRotation * smoothCamOffset; }
public static MPlayerSetting GetIns() { if (ins == null) { ins = new MPlayerSetting(); } return(ins); }
// Use this for initialization void Start() { setting = MPlayerSetting.GetIns(); }