using System;
namespace SK.Framework
{
///
/// 抽象状态类
///
public class State : IState
{
///
/// 状态名称
///
public string Name { get; set; }
///
/// 所属状态机
///
public StateMachine machine;
///
/// 状态初始化事件
///
public Action onInitialization;
///
/// 状态进入事件
///
public Action onEnter;
///
/// 状态停留事件
///
public Action onStay;
///
/// 状态退出事件
///
public Action onExit;
///
/// 状态终止事件
///
public Action onTermination;
///
/// 状态初始化事件
///
public virtual void OnInitialization()
{
onInitialization?.Invoke();
}
///
/// 状态进入事件
///
public virtual void OnEnter()
{
onEnter?.Invoke();
}
///
/// 状态停留事件
///
public virtual void OnStay()
{
onStay?.Invoke();
}
///
/// 状态退出事件
///
public virtual void OnExit()
{
onExit?.Invoke();
}
///
/// 状态终止事件
///
public virtual void OnTermination()
{
onTermination?.Invoke();
}
///
/// 设置状态切换条件
///
/// 切换条件
/// 目标状态名称
public void SwitchWhen(Func predicate, string targetStateName)
{
machine.SwitchWhen(predicate, Name, targetStateName);
}
}
}