51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Code.OfficeGame.BattleMode.Timeline;
|
|
using Cysharp.Threading.Tasks;
|
|
using R3;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.BattleMode.Actions
|
|
{
|
|
public abstract class EntityTimelineActor : MonoBehaviour
|
|
{
|
|
public BattleAction CurrentAction { get; protected set;}
|
|
public bool Finished => CurrentAction == null || CurrentAction.Finished;
|
|
|
|
private readonly Subject<TimelineBattleAction> _onActionSet = new();
|
|
public Observable<TimelineBattleAction> OnActionSet => _onActionSet;
|
|
|
|
protected void SetCurrentAction(BattleAction action, int durationInFrames)
|
|
{
|
|
CurrentAction = action;
|
|
|
|
_onActionSet.OnNext(new TimelineBattleAction
|
|
{
|
|
EntityId = gameObject.GetEntityId(),
|
|
Frame = durationInFrames
|
|
});
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
_onActionSet.Dispose();
|
|
}
|
|
|
|
public abstract UniTask DecideAction(CancellationToken ctx);
|
|
public abstract UniTaskVoid ForceDecideAction(BattleActionType actionType);
|
|
|
|
[DoNotSerialize] public Animator animator;
|
|
|
|
protected readonly Dictionary<BattleActionType, BattleAction> BattleActions = new();
|
|
|
|
private void Awake()
|
|
{
|
|
animator = GetComponentInChildren<Animator>();
|
|
|
|
foreach (var action in GetComponents<BattleAction>())
|
|
{
|
|
BattleActions.Add(action.ActionType, action);
|
|
}
|
|
}
|
|
}
|
|
} |