更改文件架构
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine.Events;
|
||||
using System.Linq;
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
|
||||
public class EntityAnimator : EntityComponent
|
||||
{
|
||||
public Animator[] animators;
|
||||
[SerializeReference, SubclassSelector] public References[] animationKeyWords;
|
||||
[SerializeReference, SubclassSelector] public References _rootVelocity;
|
||||
[SerializeReference, SubclassSelector] public References[] boolParameters;
|
||||
[SerializeReference, SubclassSelector] public References[] floatParameters;
|
||||
List<string> keyWords;
|
||||
public override void OnAwake()
|
||||
{
|
||||
keyWords = animationKeyWords.Select(x => x.Get()).ToList();
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
entity.AddListener<string>(Constant.Animation.Play, Play);
|
||||
}
|
||||
protected virtual void Play(string name)
|
||||
{
|
||||
if (animationKeyWords.Length is 0 || keyWords.Contains(name))
|
||||
{
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (x.isActiveAndEnabled)
|
||||
{
|
||||
name = name.Replace(".", "_");
|
||||
x.SetTrigger(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
public override void OnFixedUpdate(float deltaTime)
|
||||
{
|
||||
foreach (var boolPar in boolParameters)
|
||||
{
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (x.isActiveAndEnabled)
|
||||
x.SetBool(boolPar, entity.Get<bool>(boolPar));
|
||||
});
|
||||
}
|
||||
foreach (var floatPar in floatParameters)
|
||||
{
|
||||
animators.ForEach(x =>
|
||||
{
|
||||
if (x.isActiveAndEnabled)
|
||||
x.SetFloat(floatPar, entity.Get<float>(floatPar));
|
||||
});
|
||||
}
|
||||
}
|
||||
void OnAnimatorMove()
|
||||
{
|
||||
entity.Set(_rootVelocity, animators[0].velocity);
|
||||
}
|
||||
void AnimationEvent(string name)
|
||||
{
|
||||
entity.Invoke(Constant.Animation.OnEvent, name);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ac2d465b526bc94fa8ecba1c434c884
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user