2D-Platformer/Assets/Scripts/StateMachine/PickupStateBehaviour.cs
2022-02-12 12:53:50 +02:00

34 lines
No EOL
999 B
C#

using DefaultNamespace;
using Unity.Entities;
using UnityEngine;
using UnityEngine.Animations;
namespace StateMachine
{
public class PickupStateBehaviour : StateMachineBehaviour
{
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller)
{
var gameObjectEntity = animator.GetComponent<GameObjectEntity>();
if (gameObjectEntity != null)
{
var entityManager = gameObjectEntity.EntityManager;
var entity = gameObjectEntity.Entity;
if (entityManager != null && entityManager.Exists(entity))
{
if (entityManager.HasComponent<ActorAnimationEventData>(entity))
{
var data = entityManager.GetComponentData<ActorAnimationEventData>(entity);
data.PickedCanceled = true;
entityManager.SetComponentData(entity, data);
}
else
{
entityManager.AddComponentData(entity, new ActorAnimationEventData { PickedCanceled = true });
}
}
}
}
}
}