118 lines
2.6 KiB
C#
118 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Animancer;
|
|
using BITFALL.Entities.Inventory;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
// ReSharper disable ClassWithVirtualMembersNeverInherited.Global
|
|
|
|
namespace BITFALL.Entities.Equipment.Universal
|
|
{
|
|
public class AnimationBasedUniversalItemController : MonoBehaviour,IEquipBase
|
|
{
|
|
[SerializeField] protected AssetableItem referenceItem;
|
|
[SerializeField] protected AnimancerComponent animancerComponent;
|
|
[SerializeField] protected Renderer[] renderers;
|
|
|
|
[SerializeField] protected bool autoUse;
|
|
|
|
[SerializeField] protected AnimationClip entryClip;
|
|
[SerializeField] protected AnimationClip useClip;
|
|
[SerializeField] protected AnimationClip exitClip;
|
|
|
|
[Inject] protected IEntityInventory inventory;
|
|
[Inject] protected IPlayerEquipSelector playerEquipSelector;
|
|
|
|
public virtual bool IsEntered { get; set; }
|
|
public virtual void Entry()
|
|
{
|
|
foreach (var x in renderers)
|
|
{
|
|
x.enabled = true;
|
|
}
|
|
}
|
|
|
|
public virtual UniTask EntryAsync()
|
|
{
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
public virtual void Entered()
|
|
{
|
|
if (entryClip)
|
|
{
|
|
var state = animancerComponent.Play(entryClip);
|
|
state.Events.OnEnd = () =>
|
|
{
|
|
state.Events.OnEnd = null;
|
|
animancerComponent.Play(useClip);
|
|
};
|
|
}
|
|
else
|
|
{
|
|
var state =animancerComponent.Play(useClip);
|
|
state.Events.OnEnd = () =>
|
|
{
|
|
playerEquipSelector.Cancel();
|
|
inventory.UseItem(Item);
|
|
state.Events.OnEnd = null;
|
|
};
|
|
}
|
|
}
|
|
|
|
public virtual void Exit()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual async UniTask ExitAsync()
|
|
{
|
|
if (!exitClip) return;
|
|
var state = animancerComponent.Play(exitClip);
|
|
while (state.NormalizedTime < 1)
|
|
{
|
|
await UniTask.NextFrame();
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
}
|
|
}
|
|
|
|
public virtual void Exited()
|
|
{
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
foreach (var x in renderers)
|
|
{
|
|
x.enabled = false;
|
|
}
|
|
animancerComponent.Stop();
|
|
}
|
|
|
|
public virtual void OnAwake()
|
|
{
|
|
foreach (var x in renderers)
|
|
{
|
|
x.enabled = false;
|
|
}
|
|
}
|
|
|
|
public virtual void OnStart()
|
|
{
|
|
}
|
|
|
|
public virtual void OnUpdate(float deltaTime)
|
|
{
|
|
}
|
|
|
|
public virtual string AddressablePath => referenceItem.AddressablePath;
|
|
public virtual IEntity Entity { get; set; }
|
|
public virtual IBasicItem Item { get; set; }
|
|
public virtual bool IsSupportItem(IBasicItem item)=>item is not null && AddressablePath==item.AddressablePath;
|
|
|
|
public virtual void PlayAudio(string _name)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|