This commit is contained in:
CortexCore
2023-10-29 15:27:13 +08:00
parent c5f638d9d2
commit c7b6ddbf70
73 changed files with 2158 additions and 494 deletions

View File

@@ -1,12 +1,14 @@
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using BITKit.Animations;
namespace BITKit.Entities
{
public sealed class EntityAnimator : EntityComponent
{
[SerializeField] private Animator[] animators;
[SerializeField] private UnityAnimator[] animators;
[SerializeReference, SubclassSelector] private References[] animationKeyWords;
[SerializeReference, SubclassSelector] private References _rootVelocity;
[SerializeReference, SubclassSelector] private References[] boolParameters;
@@ -23,13 +25,13 @@ namespace BITKit.Entities
private void Play(string animationName)
{
if (enabled is false) return;
if (animationKeyWords.Length is 0 || keyWords.Contains(animationName))
{
animators.ForEach(x =>
{
if (!x.isActiveAndEnabled) return;
animationName = animationName.Replace(".", "_");
x.SetTrigger(animationName);
x.Play(animationName);
});
}
}
@@ -40,7 +42,7 @@ namespace BITKit.Entities
animators.ForEach(x =>
{
if (x.isActiveAndEnabled)
x.SetBool(boolPar, entity.Get<bool>(boolPar));
x.animator.SetBool(boolPar, entity.Get<bool>(boolPar));
});
}
foreach (var floatPar in floatParameters)
@@ -48,14 +50,18 @@ namespace BITKit.Entities
animators.ForEach(x =>
{
if (x.isActiveAndEnabled)
x.SetFloat(floatPar, entity.Get<float>(floatPar));
x.animator.SetFloat(floatPar, entity.Get<float>(floatPar));
});
}
}
private void OnAnimatorMove()
{
entity.Set(_rootVelocity, animators[0].velocity);
if (enabled is false) return;
if (_rootVelocity is not null && entity is not null)
entity.Set(_rootVelocity, animators[0].animator.velocity);
}
// ReSharper disable once UnusedMember.Local
private void AnimationEvent(string eventName)
{