视角控制
This commit is contained in:
@@ -13,18 +13,10 @@ public partial class FPlayer : MonoBehaviour
|
||||
/// </summary>
|
||||
public Transform CameraRoot;
|
||||
|
||||
public Transform rHandRodJoiner => MainArm.RodContainer;
|
||||
|
||||
public FRod assignRod;
|
||||
|
||||
// [HideInInspector] public FRod currentRod;
|
||||
|
||||
private CCDIK interactionCCDIK;
|
||||
|
||||
private float interactionTargetWeight;
|
||||
|
||||
[HideInInspector] public float handPullUp;
|
||||
|
||||
public Fsm<FPlayer> Fsm { get; private set; }
|
||||
|
||||
private PlayerArm[] Arms;
|
||||
@@ -41,6 +33,8 @@ public partial class FPlayer : MonoBehaviour
|
||||
|
||||
public Transform Light;
|
||||
|
||||
public Transform BackSpine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
PlayerAnimatorCtrl = gameObject.GetComponent<PlayerAnimator>();
|
||||
@@ -78,14 +72,9 @@ public partial class FPlayer : MonoBehaviour
|
||||
|
||||
if (data.PlayerID == GameModel.RoleID)
|
||||
{
|
||||
// var mainSync = gameObject.AddComponent<FPlayerMainSync>();
|
||||
BaseCamera.Main.transform.SetParent(CameraRoot);
|
||||
BaseCamera.Main.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
// var otherSync = gameObject.AddComponent<FPlayerOtherSync>();
|
||||
}
|
||||
}
|
||||
|
||||
#region 初始化相关
|
||||
@@ -159,7 +148,6 @@ public partial class FPlayer : MonoBehaviour
|
||||
{
|
||||
if (Light)
|
||||
{
|
||||
Light.localRotation = BaseCamera.Main.transform.localRotation;
|
||||
if (Light.gameObject.activeSelf != Data.openLight)
|
||||
{
|
||||
Light.gameObject.SetActive(Data.openLight);
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace NBF
|
||||
{
|
||||
public class PlayerCharacter : Character
|
||||
{
|
||||
[Tooltip("The first person camera parent.")]
|
||||
public GameObject cameraParent;
|
||||
|
||||
private float _cameraPitch;
|
||||
@@ -15,20 +14,26 @@ namespace NBF
|
||||
|
||||
|
||||
[Space(15.0f)] public bool invertLook = true;
|
||||
[Tooltip("Look sensitivity")] public Vector2 sensitivity = new Vector2(0.05f, 0.05f);
|
||||
[Tooltip("视角旋转敏感度")] public Vector2 sensitivity = new Vector2(0.05f, 0.05f);
|
||||
|
||||
[Space(15.0f)] [Tooltip("How far in degrees can you move the camera down.")]
|
||||
public float minPitch = -80.0f;
|
||||
|
||||
[Tooltip("How far in degrees can you move the camera up.")]
|
||||
[Space(15.0f)] public float minPitch = -80.0f;
|
||||
public float maxPitch = 80.0f;
|
||||
|
||||
[Tooltip("手上下最大角度")] public Vector2 handMaxAngle = new Vector2(0, 0);
|
||||
|
||||
public bool IsSelf;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
camera = BaseCamera.Main;
|
||||
|
||||
_player = GetComponent<FPlayer>();
|
||||
IsSelf = _player.Data.PlayerID == GameModel.RoleID;
|
||||
cameraParent = _player.CameraRoot.gameObject;
|
||||
if (IsSelf)
|
||||
{
|
||||
camera = BaseCamera.Main;
|
||||
}
|
||||
|
||||
transform.position = _player.Data.position;
|
||||
transform.rotation = _player.Data.rotation;
|
||||
@@ -42,8 +47,77 @@ namespace NBF
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Move
|
||||
UpdatePlayerPositionAndRotation();
|
||||
UpdateGear();
|
||||
}
|
||||
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
UpdateCameraParentRotation();
|
||||
UpdatePlayerHandView();
|
||||
}
|
||||
|
||||
|
||||
protected override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
SetRotationMode(RotationMode.None);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
InputManager.OnQuickIndexAction -= OnQuickIndexAction;
|
||||
InputManager.OnUseTorchAction -= OnUseTorchAction;
|
||||
InputManager.OnUseTelescopeAction -= OnUseTelescopeAction;
|
||||
}
|
||||
|
||||
#region 肩膀控制
|
||||
|
||||
private void UpdatePlayerHandView()
|
||||
{
|
||||
// var backValue = 0f;
|
||||
|
||||
var angle = cameraParent.transform.localEulerAngles.x;
|
||||
angle = (angle > 180f) ? angle - 360f : angle;
|
||||
angle *= -1;
|
||||
if (angle > handMaxAngle.x)
|
||||
{
|
||||
angle = handMaxAngle.x;
|
||||
}
|
||||
else if (angle < handMaxAngle.y)
|
||||
{
|
||||
angle = handMaxAngle.y;
|
||||
}
|
||||
|
||||
Debug.Log(angle);
|
||||
_player.BackSpine.localRotation *= Quaternion.Euler(0, 0, angle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 钓组控制
|
||||
|
||||
private void UpdateGear()
|
||||
{
|
||||
if (_player.CanChangeGear())
|
||||
{
|
||||
if (nextShowSlotIndex > 0)
|
||||
{
|
||||
Debug.LogError("切换钓组=========");
|
||||
var data = Fishing.Inst.Datasource;
|
||||
data.SetSelfTestGear(nextShowSlotIndex);
|
||||
nextShowSlotIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 角色位移和旋转控制
|
||||
|
||||
private void UpdatePlayerPositionAndRotation()
|
||||
{
|
||||
// Move
|
||||
Vector2 movementInput = InputManager.GetMovementInput();
|
||||
|
||||
Vector3 movementDirection = Vector3.zero;
|
||||
@@ -57,32 +131,44 @@ namespace NBF
|
||||
SetMovementDirection(movementDirection);
|
||||
|
||||
// Look
|
||||
|
||||
Vector2 lookInput = InputManager.GetLookInput() * sensitivity;
|
||||
|
||||
AddControlYawInput(lookInput.x);
|
||||
AddControlPitchInput(invertLook ? -lookInput.y : lookInput.y, minPitch, maxPitch);
|
||||
|
||||
|
||||
if (_player.CanChangeGear())
|
||||
{
|
||||
if (nextShowSlotIndex > 0)
|
||||
{
|
||||
Debug.LogError("切换钓组=========");
|
||||
var data = Fishing.Inst.Datasource;
|
||||
data.SetSelfTestGear(nextShowSlotIndex);
|
||||
nextShowSlotIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
/// <summary>
|
||||
/// 添加输入(影响偏航)。
|
||||
/// 此操作应用于角色的旋转。
|
||||
/// </summary>
|
||||
public virtual void AddControlYawInput(float value)
|
||||
{
|
||||
InputManager.OnQuickIndexAction -= OnQuickIndexAction;
|
||||
InputManager.OnUseTorchAction -= OnUseTorchAction;
|
||||
InputManager.OnUseTelescopeAction -= OnUseTelescopeAction;
|
||||
if (value != 0.0f)
|
||||
AddYawInput(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加输入(影响俯仰)。
|
||||
/// 此操作应用于相机父级的本地旋转。
|
||||
/// </summary>
|
||||
public virtual void AddControlPitchInput(float value, float minPitch = -80.0f, float maxPitch = 80.0f)
|
||||
{
|
||||
if (value != 0.0f)
|
||||
_cameraPitch = MathLib.ClampAngle(_cameraPitch + value, minPitch, maxPitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据当前的 _cameraPitch 值更新 cameraParent 的本地旋转。
|
||||
/// </summary>
|
||||
protected virtual void UpdateCameraParentRotation()
|
||||
{
|
||||
cameraParent.transform.localRotation = Quaternion.Euler(_cameraPitch, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 按键输入事件
|
||||
|
||||
private void OnQuickIndexAction(int index)
|
||||
{
|
||||
nextShowSlotIndex = index;
|
||||
@@ -105,55 +191,6 @@ namespace NBF
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Yaw).
|
||||
/// This is applied to the Character's rotation.
|
||||
/// </summary>
|
||||
public virtual void AddControlYawInput(float value)
|
||||
{
|
||||
if (value != 0.0f)
|
||||
AddYawInput(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Pitch).
|
||||
/// This is applied to the cameraParent's local rotation.
|
||||
/// </summary>
|
||||
public virtual void AddControlPitchInput(float value, float minPitch = -80.0f, float maxPitch = 80.0f)
|
||||
{
|
||||
if (value != 0.0f)
|
||||
_cameraPitch = MathLib.ClampAngle(_cameraPitch + value, minPitch, maxPitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update cameraParent local rotation applying current _cameraPitch value.
|
||||
/// </summary>
|
||||
protected virtual void UpdateCameraParentRotation()
|
||||
{
|
||||
cameraParent.transform.localRotation = Quaternion.Euler(_cameraPitch, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If overriden, base method MUST be called.
|
||||
/// </summary>
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
UpdateCameraParentRotation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If overriden, base method MUST be called.
|
||||
/// </summary>
|
||||
protected override void Reset()
|
||||
{
|
||||
// Call base method implementation
|
||||
|
||||
base.Reset();
|
||||
|
||||
// Disable character's rotation,
|
||||
// it is handled by the AddControlYawInput method
|
||||
|
||||
SetRotationMode(RotationMode.None);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user