修改arm

This commit is contained in:
2026-01-17 22:46:58 +08:00
parent f7d44f1f8d
commit a46436ae45
34 changed files with 47057 additions and 26303 deletions

View File

@@ -15,8 +15,23 @@ namespace NBF
public Transform NeckTransform;
public LookAtIK LookIk;
public PlayerArm LeftArm;
public PlayerArm RightArm;
public Transform RodRoot;
public Transform RodRoot
{
get
{
if (RightArm == null)
{
return transform;
}
return RightArm.RodContainer;
}
}
// public Transform RodRoot;
private void Awake()
@@ -28,5 +43,10 @@ namespace NBF
IK = GetComponent<PlayerIK>();
PlayerAnimator = GetComponent<PlayerAnimator>();
}
public void SetPlayer(FPlayer player)
{
LookIk.solver.target = player.FppLook;
}
}
}

View File

@@ -48,12 +48,11 @@ namespace NBF
{
_cameraAsset.fppVCam.LookAt = player.FppLook;
_cameraAsset.fppVCam.Follow = player.ModelAsset.NeckTransform;
player.ModelAsset.LookIk.solver.target = player.FppLook;
}
_cameraAsset.fppVCam.Priority = 10;
_cameraAsset.tppVCam.Priority = 0;
StartCoroutine(SnapToTarget());
// StartCoroutine(SnapToTarget());
}
public void SetFppLook(Transform fppCamLook)
@@ -65,22 +64,6 @@ namespace NBF
{
_cameraAsset.fppVCam.Follow = fppCamFollow;
}
IEnumerator SnapToTarget()
{
// 等 Cinemachine 先激活并跑一帧
yield return null;
Transform follow = _cameraAsset.fppVCam.Follow;
_cameraAsset.fppVCam.OnTargetObjectWarped(
follow,
follow.position - _cameraAsset.fppVCam.transform.position
);
// _cameraAsset.fppVCam.OnTargetObjectWarped(
// FPlayer.Instance.ModelAsset.NeckTransform,
// FPlayer.Instance.ModelAsset.NeckTransform.position - _cameraAsset.fppVCam.transform.position
// );
}
}
}

View File

@@ -185,6 +185,7 @@ namespace NBF
var actionName = context.action.name;
if (actionName == "Op1")
{
IsOp1 = true;
OnOp1Action?.Invoke(true);
}
else if (actionName == "Op2")
@@ -201,6 +202,7 @@ namespace NBF
var actionName = context.action.name;
if (actionName == "Op1")
{
IsOp1 = false;
OnOp1Action?.Invoke(false);
}
else if (actionName == "Op2")

View File

@@ -52,6 +52,7 @@ namespace NBF
private void Update()
{
UpdateMove();
Fsm?.Update();
}
private void OnDestroy()
@@ -82,6 +83,7 @@ namespace NBF
modelObject.transform.localPosition = Vector3.zero;
ModelGameObject = modelObject;
ModelAsset = modelObject.GetComponent<PlayerModelAsset>();
ModelAsset.SetPlayer(this);
}
#endregion

View File

@@ -102,7 +102,7 @@ namespace NBF
private void OnFishingSetUnequip()
{
_isRodLayerEnabled = false;
_IK.SetBipedLeftHandIK(enabled: false, null);
// _IK.SetBipedLeftHandIK(enabled: false, null);
}
@@ -284,6 +284,10 @@ namespace NBF
/// </summary>
public void OnRodThrowStart()
{
if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
{
playerStateThrow.OnRodThrowStart();
}
}
/// <summary>
@@ -291,6 +295,10 @@ namespace NBF
/// </summary>
public void OnRodThrownEnd()
{
if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
{
playerStateThrow.OnRodThrownEnd();
}
}
#endregion

View File

@@ -0,0 +1,15 @@
using RootMotion.FinalIK;
using UnityEngine;
namespace NBF
{
public class PlayerArm : MonoBehaviour
{
public bool IsLeft;
public LimbIK IK;
public Transform RodContainer;
public FingerRig FingerRig;
[HideInInspector] public float interactionTargetWeight;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 01ef40348d8b4d4da250acf0a921fc2a
timeCreated: 1768660096

View File

@@ -1,4 +1,5 @@
using RootMotion.FinalIK;
using System;
using RootMotion.FinalIK;
using UnityEngine;
namespace NBF
@@ -15,39 +16,41 @@ namespace NBF
public UpdateType UpdateSelected;
[SerializeField] private Transform _LeftHandTransform;
// [SerializeField] private Transform _LeftHandTransform;
private LookAtIK _LookAtIK;
private AimIK _AimIK;
// private AimIK _AimIK;
private FullBodyBipedIK _FullBodyIK;
// private FullBodyBipedIK _FullBodyIK;
private ArmIK _ArmIK;
// private ArmIK _ArmIK;
private bool _isLeftHandEnabled;
// private bool _isLeftHandEnabled;
private bool _isRightHandEnabled;
// private bool _isRightHandEnabled;
public bool isAimEnabled;
// public bool isAimEnabled;
private bool _isFishingLeftArmEnabled;
[SerializeField] private float transitionWeightTimeScale = 1f;
public Transform CurrentTarget => _FullBodyIK.solver.leftHandEffector.target;
// public Transform CurrentTarget => _FullBodyIK.solver.leftHandEffector.target;
public Transform LeftHandTransform => _LeftHandTransform;
// public Transform LeftHandTransform => _LeftHandTransform;
private void Awake()
{
_LookAtIK = GetComponent<LookAtIK>();
_AimIK = GetComponent<AimIK>();
_FullBodyIK = GetComponent<FullBodyBipedIK>();
_ArmIK = GetComponent<ArmIK>();
SetAimIK(enabled: false);
// _AimIK = GetComponent<AimIK>();
// _FullBodyIK = GetComponent<FullBodyBipedIK>();
// _ArmIK = GetComponent<ArmIK>();
// SetAimIK(enabled: false);
}
public void SetBipedIK(bool enabled)
{
}
@@ -57,54 +60,54 @@ namespace NBF
_isFishingLeftArmEnabled = enabled;
}
public void SetFishingLeftArm(bool enabled, Transform target)
{
_isFishingLeftArmEnabled = enabled;
_ArmIK.solver.arm.target = target;
}
// public void SetFishingLeftArm(bool enabled, Transform target)
// {
// _isFishingLeftArmEnabled = enabled;
// _ArmIK.solver.arm.target = target;
// }
public void SetBipedLeftHandIK(bool enabled, bool instant = false)
{
_isLeftHandEnabled = enabled;
if (instant)
{
_FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
}
}
// public void SetBipedLeftHandIK(bool enabled, bool instant = false)
// {
// _isLeftHandEnabled = enabled;
// if (instant)
// {
// _FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
// }
// }
public void SetBipedRightHandIK(bool enabled, bool instant = false)
{
_isRightHandEnabled = enabled;
if (instant)
{
_FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
}
}
// public void SetBipedRightHandIK(bool enabled, bool instant = false)
// {
// _isRightHandEnabled = enabled;
// if (instant)
// {
// _FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
// }
// }
public void SetBipedLeftHandIK(bool enabled, Transform target, bool instant = false)
{
_isLeftHandEnabled = enabled;
_FullBodyIK.solver.leftHandEffector.target = target;
if (instant)
{
_FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
}
}
// public void SetBipedLeftHandIK(bool enabled, Transform target, bool instant = false)
// {
// _isLeftHandEnabled = enabled;
// _FullBodyIK.solver.leftHandEffector.target = target;
// if (instant)
// {
// _FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
// }
// }
public void SetBipedRightHandIK(bool enabled, Transform target, bool instant = false)
{
_isRightHandEnabled = enabled;
_FullBodyIK.solver.rightHandEffector.target = target;
if (instant)
{
_FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
}
}
// public void SetBipedRightHandIK(bool enabled, Transform target, bool instant = false)
// {
// _isRightHandEnabled = enabled;
// _FullBodyIK.solver.rightHandEffector.target = target;
// if (instant)
// {
// _FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
// }
// }
public void SetAimIK(bool enabled)
{
isAimEnabled = enabled;
}
// public void SetAimIK(bool enabled)
// {
// isAimEnabled = enabled;
// }
private void Update()
{
@@ -132,22 +135,22 @@ namespace NBF
private void IKUpdateHandler()
{
_AimIK.UpdateSolverExternal();
// _AimIK.UpdateSolverExternal();
_LookAtIK.UpdateSolverExternal();
_FullBodyIK.UpdateSolverExternal();
_FullBodyIK.solver.Update();
_AimIK.solver.IKPositionWeight = Mathf.MoveTowards(_AimIK.solver.IKPositionWeight, isAimEnabled ? 1f : 0f,
Time.deltaTime * transitionWeightTimeScale);
_FullBodyIK.solver.leftArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.leftArmMapping.weight,
_isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_FullBodyIK.solver.rightArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.rightArmMapping.weight,
_isRightHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_FullBodyIK.solver.IKPositionWeight = Mathf.MoveTowards(_FullBodyIK.solver.IKPositionWeight,
_isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_ArmIK.solver.IKPositionWeight = Mathf.MoveTowards(_ArmIK.solver.IKPositionWeight,
_isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
_ArmIK.solver.IKRotationWeight = Mathf.MoveTowards(_ArmIK.solver.IKRotationWeight,
_isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
// _FullBodyIK.UpdateSolverExternal();
// _FullBodyIK.solver.Update();
// _AimIK.solver.IKPositionWeight = Mathf.MoveTowards(_AimIK.solver.IKPositionWeight, isAimEnabled ? 1f : 0f,
// Time.deltaTime * transitionWeightTimeScale);
// _FullBodyIK.solver.leftArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.leftArmMapping.weight,
// _isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
// _FullBodyIK.solver.rightArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.rightArmMapping.weight,
// _isRightHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
// _FullBodyIK.solver.IKPositionWeight = Mathf.MoveTowards(_FullBodyIK.solver.IKPositionWeight,
// _isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
// _ArmIK.solver.IKPositionWeight = Mathf.MoveTowards(_ArmIK.solver.IKPositionWeight,
// _isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
// _ArmIK.solver.IKRotationWeight = Mathf.MoveTowards(_ArmIK.solver.IKRotationWeight,
// _isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
}
}
}

View File

@@ -2,7 +2,7 @@
{
public class PlayerStateFight : PlayerStateBase
{
public override uint StateId => (uint)PlayerState.Fishing;
public override uint StateId => (uint)PlayerState.Fight;
protected override void onEnter()
{

View File

@@ -1,4 +1,7 @@
namespace NBF
using NBC;
using UnityEngine;
namespace NBF
{
/// <summary>
/// 钓鱼中
@@ -9,10 +12,13 @@
protected override void onEnter()
{
Debug.LogError("enter PlayerStateFishing");
_owner.ModelAsset.PlayerAnimator.BaitThrown = true;
}
protected override void onExit()
{
_owner.ModelAsset.PlayerAnimator.BaitThrown = false;
}
protected override uint onUpdate()

View File

@@ -1,4 +1,6 @@
namespace NBF
using NBC;
namespace NBF
{
/// <summary>
/// 闲置中
@@ -10,6 +12,7 @@
protected override void onEnter()
{
Log.Info("enter PlayerStateIdle");
_nextState = false;
InputManager.OnOp1Action += OnOp1Action;
}

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using NBC;
using UnityEngine;
namespace NBF
{
@@ -27,6 +28,7 @@ namespace NBF
protected override void onEnter()
{
Log.Info("enter PlayerStatePrepare");
Stage = Phase.Charged;
Player.ModelAsset.PlayerAnimator.PrepareThrow = true;
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
@@ -62,7 +64,7 @@ namespace NBF
{
ChargedProgress = 1;
}
if (!InputManager.IsOp1)
{
Stage = Phase.Confirm;

View File

@@ -10,41 +10,43 @@ namespace NBF
{
public override uint StateId => (uint)PlayerState.Throw;
public enum Phase
{
/// <summary>
/// 等待动画事件回调
/// </summary>
Waiting,
/// <summary>
/// 前摇动画
/// </summary>
AnimBegin,
/// <summary>
/// 抛线动画
/// </summary>
ThrowAnim,
/// <summary>
/// 结束
/// </summary>
Done,
ErrorDone
}
public Phase Stage = Phase.Waiting;
// public enum Phase
// {
// /// <summary>
// /// 等待动画事件回调
// /// </summary>
// Waiting,
//
// /// <summary>
// /// 前摇动画
// /// </summary>
// AnimBegin,
//
// /// <summary>
// /// 抛线动画
// /// </summary>
// ThrowAnim,
//
// /// <summary>
// /// 结束
// /// </summary>
// Done,
// ErrorDone
// }
//
// public Phase Stage = Phase.Waiting;
private bool _nextState = false;
public float ChargedProgress;
protected override void onEnter()
{
Log.Info("enter PlayerStateThrow");
_owner.ModelAsset.PlayerAnimator.StartThrow = true;
ChargedProgress = (float)Params.Get(0);
Debug.Log($"PlayerThrow ChargedProgress={ChargedProgress}");
Stage = Phase.Waiting;
_nextState = false;
// Stage = Phase.Waiting;
// _owner.Gears.Reel?.Unlock();
}
@@ -52,23 +54,10 @@ namespace NBF
protected override uint onUpdate()
{
CheckStateTimeout(10);
if (Stage == Phase.AnimBegin)
{
AnimBegin();
ThrowPosition();
}
else if (Stage == Phase.ThrowAnim)
{
ThrowAnim();
}
else if (Stage == Phase.Done)
if (_nextState)
{
return (uint)PlayerState.Fishing;
}
else if (Stage == Phase.ErrorDone)
{
return (uint)PlayerState.Idle;
}
return base.onUpdate();
}
@@ -78,66 +67,17 @@ namespace NBF
/// <summary>
/// 抛竿动画事件
/// </summary>
public void RodForceThrowStart()
public void OnRodThrowStart()
{
// Debug.LogError($"RodForceThrowStart==");
Debug.LogError("OnRodThrowStart");
_owner.ModelAsset.PlayerAnimator.PrepareThrow = false;
_owner.ModelAsset.PlayerAnimator.StartThrow = false;
Stage = Phase.AnimBegin;
}
#endregion
#region 线
private void AnimBegin()
public void OnRodThrownEnd()
{
_owner.ModelAsset.PlayerAnimator.PrepareThrow = false;
_owner.ModelAsset.PlayerAnimator.StartThrow = false;
_owner.ModelAsset.PlayerAnimator.BaitThrown = true;
Stage = Phase.ThrowAnim;
}
#endregion
#region 竿线
private NTask _throwAnim;
private void ThrowPosition()
{
// if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Float)
// {
// _owner.Gears.Rod.lineHandler.pinchController?.ReleasePinch();
// _throwAnim = new BobThrowAnim(_owner);
// _throwAnim.Run(DefRunner.Scheduler);
// }
// else
// {
// _throwAnim = new LureThrowAnim(_owner);
// _throwAnim.Run(DefRunner.Scheduler);
// }
}
private void ThrowAnim()
{
if (_throwAnim.IsDone)
{
// if (_throwAnim.Status == NTaskStatus.Success)
// {
// if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Spin)
// {
// SetArm();
// }
//
// Stage = Phase.Done;
// Debug.LogError($"抛线后,线长度={_owner.Data.lineLength}");
// }
// else
// {
// Stage = Phase.ErrorDone;
// }
}
Debug.LogError("OnRodThrownEnd");
_nextState = true;
}
#endregion

View File

@@ -178,6 +178,7 @@ namespace NBF
}
yield return 2; //等待1帧
transform.SetParent(Player.ModelAsset.RodRoot);
transform.localPosition = Vector3.zero;
transform.rotation = Player.ModelAsset.RodRoot.rotation;