修改
This commit is contained in:
174
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerAnimator.cs
Normal file
174
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerAnimator.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using KINEMATION.MagicBlend.Runtime;
|
||||
using NBC;
|
||||
using NBF.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerAnimator : PlayerMonoBehaviour
|
||||
{
|
||||
public Animator _Animator;
|
||||
|
||||
private bool _isRodLayerEnabled;
|
||||
private bool _isInit;
|
||||
private PlayerIK _IK;
|
||||
private MagicBlending _magicBlending;
|
||||
private bool _IsInVehicle;
|
||||
|
||||
#region 参数定义
|
||||
|
||||
// public static readonly int IsSwiming = Animator.StringToHash("Swim");
|
||||
//
|
||||
// public static readonly int ThrowFar = Animator.StringToHash("ThrowFar");
|
||||
//
|
||||
// public static readonly int BoatDriving = Animator.StringToHash("BoatDriving");
|
||||
//
|
||||
// public static readonly int BaitInWater = Animator.StringToHash("BaitInWater");
|
||||
//
|
||||
// public static readonly int HeldRod = Animator.StringToHash("HeldRod");
|
||||
//
|
||||
// public static readonly int RodArming = Animator.StringToHash("RodArming");
|
||||
|
||||
public static readonly int Forward = Animator.StringToHash("Forward");
|
||||
|
||||
public static readonly int Turn = Animator.StringToHash("Turn");
|
||||
|
||||
public static readonly int OnGroundHash = Animator.StringToHash("OnGround");
|
||||
public static readonly int PrepareThrowHash = Animator.StringToHash("PrepareThrow");
|
||||
public static readonly int StartThrowHash = Animator.StringToHash("StartThrow");
|
||||
public static readonly int BaitThrownHash = Animator.StringToHash("BaitThrown");
|
||||
private static readonly int FishingUpHash = Animator.StringToHash("FishingUp");
|
||||
|
||||
public static readonly string LureRodLayer = "LureRod";
|
||||
public static readonly string HandRodLayer = "HandRod";
|
||||
|
||||
|
||||
public float FishingUp
|
||||
{
|
||||
get => _Animator.GetFloat(FishingUpHash);
|
||||
set => _Animator.SetFloat(FishingUpHash, value);
|
||||
}
|
||||
|
||||
public bool OnGround
|
||||
{
|
||||
get => _Animator.GetBool(OnGroundHash);
|
||||
set => _Animator.SetBool(OnGroundHash, value);
|
||||
}
|
||||
|
||||
public bool StartThrow
|
||||
{
|
||||
get => _Animator.GetBool(StartThrowHash);
|
||||
set => _Animator.SetBool(StartThrowHash, value);
|
||||
}
|
||||
|
||||
public bool BaitThrown
|
||||
{
|
||||
get => _Animator.GetBool(BaitThrownHash);
|
||||
set => _Animator.SetBool(BaitThrownHash, value);
|
||||
}
|
||||
|
||||
public bool PrepareThrow
|
||||
{
|
||||
get => _Animator.GetBool(PrepareThrowHash);
|
||||
set => _Animator.SetBool(PrepareThrowHash, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_magicBlending = GetComponent<MagicBlending>();
|
||||
_Animator = GetComponent<Animator>();
|
||||
_Animator.keepAnimatorStateOnDisable = true;
|
||||
_IK = GetComponent<PlayerIK>();
|
||||
_isInit = true;
|
||||
}
|
||||
|
||||
|
||||
public void OnUnUseItem()
|
||||
{
|
||||
_isRodLayerEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
public void OnUseItem(PlayerItemView item)
|
||||
{
|
||||
var itemType = item.Item.ConfigID.GetItemType();
|
||||
if (itemType == ItemType.Rod)
|
||||
{
|
||||
_isRodLayerEnabled = true;
|
||||
// _IK.SetBipedLeftHandIK(enabled: false, reel.FingersIKAnchor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetLayerWeight(string layer, float weight)
|
||||
{
|
||||
_Animator.SetLayerWeight(_Animator.GetLayerIndex(layer), weight);
|
||||
}
|
||||
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
{
|
||||
float value3 = Mathf.Lerp(_Animator.GetFloat(Forward), Player.Speed / 5f,
|
||||
Time.deltaTime * 20f);
|
||||
float value4 = Mathf.Lerp(_Animator.GetFloat(Turn), Player.RotationSpeed,
|
||||
Time.deltaTime * 15f);
|
||||
_Animator.SetFloat(Forward, Mathf.Clamp01(value3));
|
||||
_Animator.SetFloat(Turn, Mathf.Clamp(value4, -1f, 1f));
|
||||
}
|
||||
|
||||
|
||||
_Animator.SetBool(OnGroundHash, _IsInVehicle || Player.IsGrounded);
|
||||
|
||||
|
||||
var isHandRodLayerEnabled = _isRodLayerEnabled && !Player.IsLureRod ? 1 : 0;
|
||||
|
||||
float handRodLayerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex(HandRodLayer));
|
||||
SetLayerWeight(HandRodLayer,
|
||||
Mathf.MoveTowards(handRodLayerWeight, isHandRodLayerEnabled, Time.deltaTime * 3f));
|
||||
|
||||
|
||||
var isLureRodLayerEnabled = _isRodLayerEnabled && Player.IsLureRod ? 1 : 0;
|
||||
float lureRodLayerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex(LureRodLayer));
|
||||
SetLayerWeight(LureRodLayer,
|
||||
Mathf.MoveTowards(lureRodLayerWeight, isLureRodLayerEnabled, Time.deltaTime * 3f));
|
||||
}
|
||||
|
||||
#region 动画事件
|
||||
|
||||
/// <summary>
|
||||
/// 抬杆到底动画事件
|
||||
/// </summary>
|
||||
public void OnRodPowerUp()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始抛出动画事件
|
||||
/// </summary>
|
||||
public void OnRodThrowStart()
|
||||
{
|
||||
// if (Player.State is PlayerStateThrow playerStateThrow)
|
||||
// {
|
||||
// playerStateThrow.OnRodThrowStart();
|
||||
// }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛竿结束动画事件
|
||||
/// </summary>
|
||||
public void OnRodThrownEnd()
|
||||
{
|
||||
// if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
|
||||
// {
|
||||
// playerStateThrow.OnRodThrownEnd();
|
||||
// }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fc336a939c4416db623f3b4ae855265
|
||||
timeCreated: 1766470716
|
||||
29
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerArm.cs
Normal file
29
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerArm.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerArm : PlayerMonoBehaviour
|
||||
{
|
||||
public bool FixLowerArm;
|
||||
public bool IsLeft;
|
||||
public LimbIK IK;
|
||||
public Transform LowerArm;
|
||||
public Transform RodContainer;
|
||||
public FingerRig FingerRig;
|
||||
|
||||
|
||||
[HideInInspector] public float interactionTargetWeight;
|
||||
|
||||
private const int MaxFixEyeAngle = 15;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01ef40348d8b4d4da250acf0a921fc2a
|
||||
timeCreated: 1768660096
|
||||
24
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerChest.cs
Normal file
24
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerChest.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerChest : PlayerMonoBehaviour
|
||||
{
|
||||
private const int MaxFixEyeAngle = 15;
|
||||
private const int MinFixEyeAngle = -10;
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
FixArmAngle();
|
||||
}
|
||||
|
||||
private void FixArmAngle()
|
||||
{
|
||||
var angle = Player.EyeAngle;
|
||||
if (angle > MaxFixEyeAngle) angle = MaxFixEyeAngle;
|
||||
else if (angle < MinFixEyeAngle) angle = MinFixEyeAngle;
|
||||
var val = transform.localEulerAngles;
|
||||
transform.localEulerAngles = new Vector3(val.x, val.y, val.z - angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e152a74e74b54d17ace5403a1570e12a
|
||||
timeCreated: 1768668096
|
||||
58
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerIK.cs
Normal file
58
Assets/Scripts/Fishing/New/View/Player/Mono/PlayerIK.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerIK : PlayerMonoBehaviour
|
||||
{
|
||||
public enum UpdateType
|
||||
{
|
||||
Update = 0,
|
||||
FixedUpdate = 1,
|
||||
LateUpdate = 2,
|
||||
Default = 3
|
||||
}
|
||||
|
||||
public UpdateType UpdateSelected;
|
||||
|
||||
private LookAtIK _LookAtIK;
|
||||
|
||||
[SerializeField] private float transitionWeightTimeScale = 1f;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_LookAtIK = GetComponent<LookAtIK>();
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.Update)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.FixedUpdate)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.LateUpdate)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void IKUpdateHandler()
|
||||
{
|
||||
_LookAtIK.UpdateSolverExternal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb36ecc5b1784d948837600cf18808cd
|
||||
timeCreated: 1765121426
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public abstract class PlayerMonoBehaviour : MonoBehaviour
|
||||
{
|
||||
public Player Player { get; private set; }
|
||||
|
||||
public PlayerUnityComponent UnityComponent { get; private set; }
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
UnityComponent = GetComponentInParent<PlayerUnityComponent>();
|
||||
Player = UnityComponent.Player;
|
||||
OnAwake();
|
||||
}
|
||||
|
||||
protected virtual void OnAwake()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fbde40efe5345cd8c05ea6c1f1914cf
|
||||
timeCreated: 1773040970
|
||||
@@ -0,0 +1,25 @@
|
||||
using ECM2;
|
||||
using ECM2.Examples.FirstPerson;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerUnityComponent : MonoBehaviour
|
||||
{
|
||||
public Player Player { get; set; }
|
||||
public Transform Root;
|
||||
public Transform Eye;
|
||||
public Transform FppLook;
|
||||
public Transform IK;
|
||||
public PlayerModelAsset ModelAsset;
|
||||
public CharacterMovement Character;
|
||||
public FirstPersonCharacter FirstPerson;
|
||||
|
||||
[Header("视角相关")] public float MouseSensitivity = 0.1f;
|
||||
[Space(15f)] public bool invertLook = true;
|
||||
|
||||
public float minPitch = -60f;
|
||||
|
||||
public float maxPitch = 60f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a25908f34e4e4464a922b88337a5b733
|
||||
timeCreated: 1773038189
|
||||
Reference in New Issue
Block a user