diff options
author | chai <chaifix@163.com> | 2022-07-02 18:23:46 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-07-02 18:23:46 +0800 |
commit | f0f1d830651f3737030e258dc86b42a37baa1bca (patch) | |
tree | 386946c608ec02094c81253872e890615e0c3807 /JamHelper/Assets/JamHelper/JamUtils/LiteBehaviorTree/BehaviorTree.cs | |
parent | e7e9156b0e4d180f8f9e291eb5ccfb08847e6269 (diff) |
* change directory
Diffstat (limited to 'JamHelper/Assets/JamHelper/JamUtils/LiteBehaviorTree/BehaviorTree.cs')
-rw-r--r-- | JamHelper/Assets/JamHelper/JamUtils/LiteBehaviorTree/BehaviorTree.cs | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/JamHelper/Assets/JamHelper/JamUtils/LiteBehaviorTree/BehaviorTree.cs b/JamHelper/Assets/JamHelper/JamUtils/LiteBehaviorTree/BehaviorTree.cs new file mode 100644 index 0000000..90ff0c1 --- /dev/null +++ b/JamHelper/Assets/JamHelper/JamUtils/LiteBehaviorTree/BehaviorTree.cs @@ -0,0 +1,156 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 简单的有限状态机实现 + +namespace LiteBehaviorTree +{ + + public class BehaviorTree : MonoBehaviour + { + } + + public enum Status + { + Failed, + Running, + Success + } + + public abstract class BehaviorNode + { + /// <summary> + /// 节点名,如果不重写,默认是节点类型名 + /// </summary> + public virtual string name { get; } + + /// <summary> + /// 节点颜色,用于Profiler + /// </summary> + public virtual Color color { get; } + + /// <summary> + /// 节点图标,用于Profiler + /// </summary> + public virtual string icon { get; } + + /// <summary> + /// 父节点,根节点为null + /// </summary> + protected BehaviorNode m_Parent; + + /// <summary> + /// 子节点 + /// </summary> + protected List<BehaviorNode> m_Children; + + /// <summary> + /// 节点状态 + /// </summary> + protected Status m_Status; + + /// <summary> + /// 当前状态的上一个状态 + /// </summary> + protected Status m_LastResult; + + /// <summary> + /// 下次执行的时间 + /// </summary> + protected float m_NextUpdateTime; + + /// <summary> + /// 结束时回调 + /// </summary> + public System.Action onStop; + + public virtual string ToString() + { + return "<BehaviorNode>"; + } + + /// <summary> + /// 休眠 + /// </summary> + /// <param name="timeInSec"></param> + public void Sleep(float timeInSec) + { + } + + public int GetSleepTime() + { + return 0; + } + + public virtual void Visit() + { + } + + public virtual void Step() + { + } + + public virtual void Reset() + { + } + + public virtual void Stop() + { + } + + } + + public abstract class CompositeNode : BehaviorNode + { + + } + + public abstract class DecoratorNode : BehaviorNode + { + + } + + public abstract class ActionNode : BehaviorNode + { + protected System.Action action; + + public override void Visit() + { + action(); + m_Status = Status.Success; + } + } + + public abstract class ConditionNode : BehaviorNode + { + protected System.Func<bool> checker; + + public override void Visit() + { + if (checker()) + { + m_Status = Status.Success; + } + else + { + m_Status = Status.Failed; + } + } + + } + + ////////////////// Default Composites ////////////////// + + + + ////////////////// Default Decorators ////////////////// + + + ////////////////// Default Conditions ////////////////// + + + ////////////////// Default Actions ////////////////// + + +}
\ No newline at end of file |