174 lines
5.4 KiB
C#
174 lines
5.4 KiB
C#
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
|
|
}
|
|
} |