_xiaofang/xiaofang/Assets/Script/Character/CameraControl.cs

300 lines
11 KiB
C#
Raw Normal View History

2024-10-21 10:08:49 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour
{
public Transform Character; // <20><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>á<EFBFBD>
public Vector3 pivotOffset = new Vector3(0.0f, 1.7f, 0.0f); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ㡣
public Vector3 camOffset = new Vector3(0.4f, 0.0f, -2.0f); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>õ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float smooth = 10f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ƽ<EFBFBD><C6BD><EFBFBD>ٶȡ<D9B6>
public float horizontalAimingSpeed = 6f; // ˮƽת<C6BD><D7AA><EFBFBD>ٶȡ<D9B6>
public float verticalAimingSpeed = 6f; // <20><>ֱת<D6B1><D7AA><EFBFBD>ٶȡ<D9B6>
public float maxVerticalAngle = 30f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>нǡ<D0BD>
public float minVerticalAngle = -60f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ֱ<EFBFBD>нǡ<D0BD>
private float angleH = 0; // <20><><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD><EFBFBD>ˮƽ<CBAE>Ƕȵı<C8B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>
private float angleV = 0; // <20><><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>Ƕȵı<C8B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>
private Transform cam; // <20><><EFBFBD><EFBFBD><EFBFBD>ı<C4B1><E4BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private Vector3 smoothPivotOffset; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
private Vector3 smoothCamOffset; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
private Vector3 targetPivotOffset; // <20><><EFBFBD>ĵ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EAA3AC><EFBFBD>ڲ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
private Vector3 targetCamOffset; // <20><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EAA3AC><EFBFBD>ڲ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
private float defaultFOV; // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>ǣ<EFBFBD>FOV<4F><56><EFBFBD><EFBFBD>
private float targetFOV; // Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>ǡ<EFBFBD>
private float targetMaxVerticalAngle; // <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>нǡ<D0BD>
private bool isCustomOffset; // <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private float deltaH = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ˮƽ<CBAE><C6BD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private Vector3 firstDirection; // <20><><EFBFBD>ڵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>
private Vector3 directionToLock; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>
private float recoilAngle = 0f; // <20><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ĽǶȣ<C7B6><C8A3><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private Vector3 forwardHorizontalRef; // ˮƽƽ<C6BD><C6BD><EFBFBD>ϵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
private float leftRelHorizontalAngle, rightRelHorizontalAngle; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮƽ<CBAE><C6BD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԽǶȡ<C7B6>
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮƽ<CBAE>Ƕȡ<C7B6>
public float GetH => angleH;
void Awake()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<C4B1><E4BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cam = transform;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>λ<EFBFBD>á<EFBFBD>
cam.position = Character.position + Quaternion.identity * pivotOffset + Quaternion.identity * camOffset;
cam.rotation = Quaternion.identity;
// <20><><EFBFBD>òο<C3B2>ֵ<EFBFBD><D6B5>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>
smoothPivotOffset = pivotOffset;
smoothCamOffset = camOffset;
defaultFOV = cam.GetComponent<Camera>().fieldOfView;
angleH = Character.eulerAngles.y;
ResetTargetOffsets();
ResetFOV();
ResetMaxVerticalAngle();
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڴ<EFBFBD>ֱƫ<D6B1>ơ<EFBFBD>
if (camOffset.y > 0)
Debug.LogWarning("<22><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD> (Y) <20><><EFBFBD><EFBFBD>ײʱ<D7B2><EFBFBD><E1B1BB><EFBFBD>ԣ<EFBFBD>\n" +"<22><><EFBFBD><EFBFBD><E9BDAB><EFBFBD>д<EFBFBD>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Pivot Offset <20>С<EFBFBD>");
}
void Update()
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed;
angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * verticalAimingSpeed;
// <20><><EFBFBD>ô<EFBFBD>ֱ<EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ơ<EFBFBD>
angleV = Mathf.Clamp(angleV, minVerticalAngle, targetMaxVerticalAngle);
// <20><><EFBFBD>ô<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
angleV = Mathf.LerpAngle(angleV, angleV + recoilAngle, 10f * Time.deltaTime);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (firstDirection != Vector3.zero)
{
angleH -= deltaH;
UpdateLockAngle();
angleH += deltaH;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮƽ<CBAE><C6BD>ת<EFBFBD><D7AA><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD>
if (forwardHorizontalRef != default(Vector3))
{
ClampHorizontal();
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>
Quaternion camYRotation = Quaternion.Euler(0, angleH, 0);
Quaternion aimRotation = Quaternion.Euler(-angleV, angleH, 0);
cam.rotation = aimRotation;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>ǡ<EFBFBD>
cam.GetComponent<Camera>().fieldOfView = Mathf.Lerp(cam.GetComponent<Camera>().fieldOfView, targetFOV, Time.deltaTime);
// <20><><EFBFBD>ڵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
Vector3 baseTempPosition = Character.position + camYRotation * targetPivotOffset;
Vector3 noCollisionOffset = targetCamOffset;
while (noCollisionOffset.magnitude >= 0.2f)
{
if (DoubleViewingPosCheck(baseTempPosition + aimRotation * noCollisionOffset))
break;
noCollisionOffset -= noCollisionOffset.normalized * 0.2f;
}
if (noCollisionOffset.magnitude < 0.2f)
noCollisionOffset = Vector3.zero;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ƫ<EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>˳<EFBFBD>ģʽ<C4A3><CABD>
bool customOffsetCollision = isCustomOffset && noCollisionOffset.sqrMagnitude < targetCamOffset.sqrMagnitude;
// <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
smoothPivotOffset = Vector3.Lerp(smoothPivotOffset, customOffsetCollision ? pivotOffset : targetPivotOffset, smooth * Time.deltaTime);
smoothCamOffset = Vector3.Lerp(smoothCamOffset, customOffsetCollision ? Vector3.zero : noCollisionOffset, smooth * Time.deltaTime);
cam.position = Character.position + camYRotation * smoothPivotOffset + aimRotation * smoothCamOffset;
// ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (recoilAngle > 0)
recoilAngle -= 5 * Time.deltaTime;
else if (recoilAngle < 0)
recoilAngle += 5 * Time.deltaTime;
}
// <20><><EFBFBD><EFBFBD><><C8A1>ˮƽ<CBAE><C6BD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ơ<EFBFBD>
public void ToggleClampHorizontal(float LeftAngle = 0, float RightAngle = 0, Vector3 fwd = default(Vector3))
{
forwardHorizontalRef = fwd;
leftRelHorizontalAngle = LeftAngle;
rightRelHorizontalAngle = RightAngle;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮƽ<CBAE><C6BD>ת<EFBFBD><D7AA>
private void ClampHorizontal()
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ͳο<CDB2><CEBF><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>ĽǶȡ<C7B6>
Vector3 cam2dFwd = this.transform.forward;
cam2dFwd.y = 0;
float angleBetween = Vector3.Angle(cam2dFwd, forwardHorizontalRef);
float sign = Mathf.Sign(Vector3.Cross(cam2dFwd, forwardHorizontalRef).y);
angleBetween = angleBetween * sign;
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴﵽ<DAB4><EFB5BD><EFBFBD>ƽǶ<C6BD>ʱ<EFBFBD><CAB1><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>
float acc = Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed;
acc += Mathf.Clamp(Input.GetAxis("Analog X"), -1, 1) * 60 * horizontalAimingSpeed * Time.deltaTime;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕȡ<C7B6>
if (sign < 0 && angleBetween < leftRelHorizontalAngle)
{
if (acc > 0)
angleH -= acc;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>Ƕȡ<C7B6>
else if (angleBetween > rightRelHorizontalAngle)
{
if (acc < 0)
angleH -= acc;
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private void UpdateLockAngle()
{
directionToLock.y = 0f;
float centerLockAngle = Vector3.Angle(firstDirection, directionToLock);
Vector3 cross = Vector3.Cross(firstDirection, directionToLock);
if (cross.y < 0) centerLockAngle = -centerLockAngle;
deltaH = centerLockAngle;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6>ݵĶ<DDB5><C4B6><EFBFBD><EFBFBD><EFBFBD>
public void LockOnDirection(Vector3 direction)
{
if (firstDirection == Vector3.zero)
{
firstDirection = direction;
firstDirection.y = 0f;
}
directionToLock = Vector3.Lerp(directionToLock, direction, 0.15f * smooth * Time.deltaTime);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void UnlockOnDirection()
{
deltaH = 0;
firstDirection = directionToLock = Vector3.zero;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void SetTargetOffsets(Vector3 newPivotOffset, Vector3 newCamOffset)
{
targetPivotOffset = newPivotOffset;
targetCamOffset = newCamOffset;
isCustomOffset = true;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>ΪĬ<CEAA><C4AC>ֵ<EFBFBD><D6B5>
public void ResetTargetOffsets()
{
targetPivotOffset = pivotOffset;
targetCamOffset = camOffset;
isCustomOffset = false;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void ResetYCamOffset()
{
targetCamOffset.y = camOffset.y;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void SetYCamOffset(float y)
{
targetCamOffset.y = y;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void SetXCamOffset(float x)
{
targetCamOffset.x = x;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>ǣ<EFBFBD>FOV<4F><56><EFBFBD><EFBFBD>
public void SetFOV(float customFOV)
{
this.targetFOV = customFOV;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>ΪĬ<CEAA><C4AC>ֵ<EFBFBD><D6B5>
public void ResetFOV()
{
this.targetFOV = defaultFOV;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>Ƕȡ<C7B6>
public void SetMaxVerticalAngle(float angle)
{
this.targetMaxVerticalAngle = angle;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>Ƕ<EFBFBD>ΪĬ<CEAA><C4AC>ֵ<EFBFBD><D6B5>
public void ResetMaxVerticalAngle()
{
this.targetMaxVerticalAngle = maxVerticalAngle;
}
// ˫<>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>ijЩ<C4B3><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><E2B5BD><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC>
bool DoubleViewingPosCheck(Vector3 checkPos)
{
return ViewingPosCheck(checkPos) && ReverseViewingPosCheck(checkPos);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>ײ<EFBFBD><D7B2>
bool ViewingPosCheck(Vector3 checkPos)
{
// <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>
Vector3 target = Character.position + pivotOffset;
Vector3 direction = target - checkPos;
// <20><><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>λ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>߼<EFBFBD><DFBC><EFBFBD>ϰ<EFBFBD><CFB0><EFBFBD>...
if (Physics.SphereCast(checkPos, 0.2f, direction, out RaycastHit hit, direction.magnitude))
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
if (hit.transform != Character && !hit.transform.GetComponent<Collider>().isTrigger)
{
// <20><><EFBFBD><EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD>ʡ<EFBFBD>
return false;
}
}
// <20><><EFBFBD><EFBFBD>û<EFBFBD>м<EFBFBD><D0BC><EFBFBD>κ<EFBFBD><CEBA>ϰ<EFBFBD><CFB0><EFBFBD><EFA3AC><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><E2B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ú<EFBFBD><C3BA>ʡ<EFBFBD>
return true;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
bool ReverseViewingPosCheck(Vector3 checkPos)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>
Vector3 origin = Character.position + pivotOffset;
Vector3 direction = checkPos - origin;
if (Physics.SphereCast(origin, 0.2f, direction, out RaycastHit hit, direction.magnitude))
{
if (hit.transform != Character && hit.transform != transform && !hit.transform.GetComponent<Collider>().isTrigger)
{
return false;
}
}
return true;
}
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С<EFBFBD><D0A1>
public float GetCurrentPivotMagnitude(Vector3 finalPivotOffset)
{
return Mathf.Abs((finalPivotOffset - smoothPivotOffset).magnitude);
}
}