113 lines
3.8 KiB
C#
113 lines
3.8 KiB
C#
using Fantasy.Entitas;
|
|
using Fantasy.Entitas.Interface;
|
|
using NBC;
|
|
using UnityEngine;
|
|
|
|
namespace NBF.Fishing2
|
|
{
|
|
public class CharacterAnimatorComponent : Entity
|
|
{
|
|
#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 OnGround = Animator.StringToHash("OnGround");
|
|
|
|
public static readonly int RodRight = Animator.StringToHash("rod right");
|
|
|
|
public static readonly int RodForward = Animator.StringToHash("rod forward");
|
|
|
|
public static readonly int PreciseCast = Animator.StringToHash("Precise Cast");
|
|
|
|
public static readonly int PreciseIdle = Animator.StringToHash("Precise Idle");
|
|
|
|
|
|
public static readonly string Torso = "Torso";
|
|
|
|
#endregion
|
|
|
|
public Animator Animator { get; private set; }
|
|
public MapUnit MapUnit;
|
|
|
|
private bool _isTorsoLayerEnabled;
|
|
|
|
#region System
|
|
|
|
public class CharacterAnimatorComponentDestroySystem : DestroySystem<CharacterAnimatorComponent>
|
|
{
|
|
protected override void Destroy(CharacterAnimatorComponent self)
|
|
{
|
|
}
|
|
}
|
|
|
|
public class CharacterAnimatorComponentAwakeSystem : AwakeSystem<CharacterAnimatorComponent>
|
|
{
|
|
protected override void Awake(CharacterAnimatorComponent self)
|
|
{
|
|
self.MapUnit = self.Parent as MapUnit;
|
|
var unitUnityComponent = self.Parent.GetComponent<UnitUnityComponent>();
|
|
self.Animator = unitUnityComponent.ModelAsset.Animator;
|
|
}
|
|
}
|
|
|
|
// public class CharacterAnimatorComponentUpdateSystem : UpdateSystem<CharacterAnimatorComponent>
|
|
// {
|
|
// protected override void Update(CharacterAnimatorComponent self)
|
|
// {
|
|
// // self.UpdateAnimator();
|
|
// }
|
|
// }
|
|
|
|
public class CharacterAnimatorComponentLateUpdateSystem : LateUpdateSystem<CharacterAnimatorComponent>
|
|
{
|
|
protected override void LateUpdate(CharacterAnimatorComponent self)
|
|
{
|
|
self.UpdateAnimator();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
private void UpdateAnimator()
|
|
{
|
|
Animator.SetBool(OnGround, MapUnit.IsGrounded);
|
|
float value3 = Mathf.Lerp(Animator.GetFloat(Forward), MapUnit.Speed / 5f, Time.deltaTime * 20f);
|
|
Animator.SetFloat(Forward, value3);
|
|
|
|
// 平滑处理
|
|
// float smoothedTurn = Mathf.SmoothDamp(Animator.GetFloat(Turn),
|
|
// MapUnit.RotationSpeed,
|
|
// ref turnSmoothVelocity,
|
|
// smoothingTime
|
|
// );
|
|
|
|
float smoothedTurn = Mathf.Lerp(Animator.GetFloat(Turn), MapUnit.RotationSpeed, Time.deltaTime * 10f);
|
|
Animator.SetFloat(Turn, smoothedTurn);
|
|
|
|
|
|
float layerWeight = Animator.GetLayerWeight(Animator.GetLayerIndex(Torso));
|
|
SetLayerWeight(Torso,
|
|
Mathf.MoveTowards(layerWeight, _isTorsoLayerEnabled ? 1f : 0f, Time.deltaTime * 3f));
|
|
}
|
|
|
|
public void SetLayerWeight(string layer, float weight)
|
|
{
|
|
Animator.SetLayerWeight(Animator.GetLayerIndex(layer), weight);
|
|
}
|
|
}
|
|
} |