1
This commit is contained in:
@@ -1,18 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITKit.Animations;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntitiesAnimationController : MonoBehaviour
|
||||
namespace BITKit.Entities.Animation
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
public sealed class EntitiesAnimationController : EntityComponent
|
||||
{
|
||||
[SerializeField] private UnityAnimator unityAnimator;
|
||||
[SerializeField] private SerializedDictionary<string, RuntimeAnimatorController> animatorControllers;
|
||||
[Inject]
|
||||
private IEntityEquipment _entityEquipment;
|
||||
|
||||
private RuntimeAnimatorController _initialRuntimeAnimatorController;
|
||||
|
||||
private readonly DoubleBuffer<RuntimeAnimatorController> _runtimeAnimatorControllerBuffer = new();
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_entityEquipment.OnEquip += OnEquip;
|
||||
_initialRuntimeAnimatorController = unityAnimator.animator.runtimeAnimatorController;
|
||||
}
|
||||
|
||||
public override void OnLateUpdate(float deltaTime)
|
||||
{
|
||||
if(_runtimeAnimatorControllerBuffer.TryGetRelease(out var controller))
|
||||
{
|
||||
unityAnimator.animator.runtimeAnimatorController = controller;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEquip(IBasicItem obj)
|
||||
{
|
||||
if(animatorControllers.TryGetValue(obj.AddressablePath, out var controller))
|
||||
{
|
||||
_runtimeAnimatorControllerBuffer.Release(controller);
|
||||
}
|
||||
else
|
||||
{
|
||||
_runtimeAnimatorControllerBuffer.Release(_initialRuntimeAnimatorController);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user