mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-12 00:58:16 +00:00
提交确定性AI案例
This commit is contained in:
@@ -89,7 +89,14 @@ namespace BehaviorTreeSlayer
|
||||
|
||||
public Entry Load()
|
||||
{
|
||||
if (Entry == null && config != null)
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (Entry == null && config != null)
|
||||
{
|
||||
Entry = XmlUtils.DeSerialize<Entry>(config.text);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Entry = XmlUtils.DeSerialize<Entry>(config.text);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,21 @@ namespace BehaviorTreeSlayer
|
||||
public virtual void Exit(object args)
|
||||
{
|
||||
}
|
||||
public virtual TaskResult Tick(LFloat dt, object args = null)
|
||||
{
|
||||
return TaskResult.OK;
|
||||
}
|
||||
public virtual void Reset()
|
||||
{
|
||||
state = TaskResult.None;
|
||||
}
|
||||
|
||||
public virtual void VisitTree(TreeNode node, System.Action<TreeNode> action)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public TreeNode Copy(TreeNode node)
|
||||
{
|
||||
TreeNode t = this.Clone() as TreeNode;
|
||||
@@ -38,24 +53,12 @@ namespace BehaviorTreeSlayer
|
||||
}
|
||||
return t;
|
||||
}
|
||||
public virtual TaskResult Tick(LFloat dt, object args = null)
|
||||
{
|
||||
return TaskResult.OK;
|
||||
}
|
||||
public virtual void Reset()
|
||||
{
|
||||
state = TaskResult.None;
|
||||
}
|
||||
|
||||
TreeNode Clone()
|
||||
{
|
||||
return Activator.CreateInstance(this.GetType()) as TreeNode;
|
||||
}
|
||||
|
||||
public virtual void VisitTree(TreeNode node, System.Action<TreeNode> action)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using JNGame.Runtime.Util;
|
||||
|
||||
namespace BehaviorTreeSlayer
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 运行时 行为
|
||||
/// </summary>
|
||||
@@ -40,7 +41,39 @@ namespace BehaviorTreeSlayer
|
||||
/// 事件
|
||||
/// </summary>
|
||||
Dictionary<string, Action<object>> actions = new Dictionary<string, Action<object>>();
|
||||
|
||||
/// <summary>
|
||||
/// 参数
|
||||
/// </summary>
|
||||
public Dictionary<string, object> Args = new Dictionary<string, object>();
|
||||
|
||||
|
||||
//------------------ 获取参数 ----------------------------------
|
||||
|
||||
public object this[string key]
|
||||
{
|
||||
get => Args.TryGetValue(key, out object v) ? v : null;
|
||||
set => Args[key] = value;
|
||||
}
|
||||
|
||||
public T Get<T>(string key)
|
||||
{
|
||||
return (T)this[key];
|
||||
}
|
||||
|
||||
public T Get<T>()
|
||||
{
|
||||
foreach (var keyValuePair in Args)
|
||||
{
|
||||
if (keyValuePair.Value is T value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
//------------------ 结束获取参数 ----------------------------------
|
||||
|
||||
public void OnInit(int seed,string config)
|
||||
{
|
||||
@@ -59,19 +92,10 @@ namespace BehaviorTreeSlayer
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Regist(string key, Action<object> onEvent)
|
||||
{
|
||||
if (actions.ContainsKey(key))
|
||||
{
|
||||
actions[key] = onEvent;
|
||||
}
|
||||
else
|
||||
{
|
||||
actions.Add(key, onEvent);
|
||||
}
|
||||
actions[key] = onEvent;
|
||||
}
|
||||
|
||||
public void UnRegist(string key)
|
||||
@@ -89,9 +113,12 @@ namespace BehaviorTreeSlayer
|
||||
return RandomFloat(LFloat.L0,LFloat.L1);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
public void Update(LFloat dt)
|
||||
{
|
||||
|
||||
if (IsInit)
|
||||
{
|
||||
Entry.Tick(dt,this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ namespace BehaviorTreeSlayer
|
||||
}
|
||||
|
||||
static Type[] types;
|
||||
|
||||
public static Type[] Types
|
||||
{
|
||||
get
|
||||
@@ -56,6 +55,7 @@ namespace BehaviorTreeSlayer
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public static string XmlSerialize<T>(T obj)
|
||||
|
||||
@@ -57,7 +57,13 @@ namespace GAS.Runtime
|
||||
public abstract void OnRemove(int frame,int startFrame,int endFrame);
|
||||
public abstract void OnGameplayEffectActivate();
|
||||
public abstract void OnGameplayEffectDeactivate();
|
||||
/// <summary>
|
||||
/// 只有Cue附加在实体中时会触发
|
||||
/// </summary>
|
||||
public abstract void OnTick(int frame,int startFrame,int endFrame);
|
||||
/// <summary>
|
||||
/// 如果不在实体中则自己主动调用
|
||||
/// </summary>
|
||||
public abstract void OnTick(int deltaTime);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user