导入资源
This commit is contained in:
@@ -9,7 +9,6 @@ namespace NBF
|
||||
{
|
||||
private float _cameraPitch;
|
||||
private FPlayer _player;
|
||||
private float _defBackSpineZ;
|
||||
|
||||
|
||||
[Space(10.0f)] public float maxSprintSpeed = 10.0f;
|
||||
@@ -25,8 +24,6 @@ namespace NBF
|
||||
[HideInInspector] public int nextShowSlotIndex = -1;
|
||||
public bool IsSelf;
|
||||
|
||||
private Quaternion spineInitialLocalRotation;
|
||||
|
||||
|
||||
public LookAtIK lookAtIK; // 挂在背部上的 LookAtIK 脚本
|
||||
public float aimDistance = 1.5f; // 目标点离相机多远
|
||||
@@ -35,6 +32,8 @@ namespace NBF
|
||||
[Header("限制角度(单位:度)")] public float maxUpAngle = 20f; // 相机抬头最多20°
|
||||
public float maxDownAngle = 40f; // 相机低头最多40°
|
||||
|
||||
public LayerMask interactableLayer;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
@@ -53,8 +52,6 @@ namespace NBF
|
||||
lookTarget = new GameObject("SpineLookTarget").transform;
|
||||
lookTarget.SetParent(_player.transform);
|
||||
|
||||
spineInitialLocalRotation = _player.BackSpine.localRotation;
|
||||
_defBackSpineZ = -AnglesChange(_player.BackSpine.localEulerAngles.z);
|
||||
transform.position = _player.Data.position;
|
||||
transform.rotation = _player.Data.rotation;
|
||||
|
||||
@@ -63,10 +60,13 @@ namespace NBF
|
||||
InputManager.OnQuickIndexAction += OnQuickIndexAction;
|
||||
InputManager.OnUseTorchAction += OnUseTorchAction;
|
||||
InputManager.OnUseTelescopeAction += OnUseTelescopeAction;
|
||||
|
||||
interactableLayer = LayerMask.GetMask("Interactive");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
InteractiveCheck();
|
||||
UpdatePlayerPositionAndRotation();
|
||||
UpdateGear();
|
||||
}
|
||||
@@ -98,6 +98,48 @@ namespace NBF
|
||||
InputManager.OnUseTelescopeAction -= OnUseTelescopeAction;
|
||||
}
|
||||
|
||||
#region 交互检测
|
||||
|
||||
private RaycastHit hitInfo;
|
||||
private bool isHit;
|
||||
private readonly float _interactionDistance = 8f;
|
||||
private InteractiveObject _lastInteractiveObject;
|
||||
|
||||
private void InteractiveCheck()
|
||||
{
|
||||
if (IsSelf && _player && _player.Fsm.CurrentStateId == States.Player.Idle)
|
||||
{
|
||||
// 从屏幕中心发射射线
|
||||
Ray ray = BaseCamera.Main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
|
||||
isHit = Physics.Raycast(ray, out hitInfo, _interactionDistance, interactableLayer);
|
||||
|
||||
// 检测到可交互物体时
|
||||
if (isHit)
|
||||
{
|
||||
var interactiveObject = hitInfo.transform.gameObject.GetComponent<InteractiveObject>();
|
||||
if (interactiveObject != null)
|
||||
{
|
||||
SetInteractiveObject(interactiveObject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SetInteractiveObject(null);
|
||||
}
|
||||
|
||||
private void SetInteractiveObject(InteractiveObject interactiveObject)
|
||||
{
|
||||
if (_lastInteractiveObject != interactiveObject)
|
||||
{
|
||||
_lastInteractiveObject = interactiveObject;
|
||||
InputManager.Instance.OnInteractiveObject(_lastInteractiveObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 肩膀控制
|
||||
|
||||
private void UpdatePlayerHandView()
|
||||
@@ -270,23 +312,5 @@ namespace NBF
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 工具方法
|
||||
|
||||
float GetCameraPitch()
|
||||
{
|
||||
Vector3 camForward = cameraParent.transform.forward;
|
||||
camForward.y = 0;
|
||||
camForward.Normalize();
|
||||
float pitch = Vector3.SignedAngle(camForward, cameraParent.transform.forward, cameraParent.transform.right);
|
||||
return pitch;
|
||||
}
|
||||
|
||||
private float AnglesChange(float angle)
|
||||
{
|
||||
return (angle > 180f) ? angle - 360f : angle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user