(client) feat:实现热重载,实现多维度,实现武器,实现掉落物,实现状态UI,实现攻击AI (#44)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI
|
||||
@ -9,6 +12,10 @@ namespace AI
|
||||
public List<AIBase> children = new();
|
||||
|
||||
public abstract JobBase GetJob(Entity.Entity target);
|
||||
|
||||
public virtual void Init(BehaviorTreeDef def)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ThinkNode_Selector : AIBase
|
||||
@ -28,13 +35,7 @@ namespace AI
|
||||
{
|
||||
// 条件函数,返回 true 表示满足条件
|
||||
private Func<Entity.Entity, bool> condition;
|
||||
|
||||
// 构造函数,传入条件函数
|
||||
public ThinkNode_Conditional(Func<Entity.Entity, bool> conditionFunc)
|
||||
{
|
||||
condition = conditionFunc;
|
||||
}
|
||||
|
||||
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
// 检查条件是否满足
|
||||
@ -47,19 +48,32 @@ namespace AI
|
||||
// 条件不满足,直接返回 null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public class ThinkNode_Sequence : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
|
||||
public override void Init(BehaviorTreeDef def)
|
||||
{
|
||||
foreach (var aiBase in children)
|
||||
base.Init(def); // 调用基类的Init方法
|
||||
|
||||
if (!string.IsNullOrEmpty(def.value))
|
||||
{
|
||||
var job = aiBase.GetJob(target);
|
||||
if (job == null)
|
||||
return null; // 如果某个子节点返回 null,则整个序列失败
|
||||
try
|
||||
{
|
||||
// 使用 ConditionDelegateFactory 来解析 def.value 并创建条件委托
|
||||
this.condition = ConditionDelegateFactory.CreateConditionDelegate(
|
||||
def.value,
|
||||
typeof(Entity.Entity),
|
||||
typeof(ConditionFunctions) // 指定查找条件函数的类
|
||||
);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.condition = (e) => false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.condition = (e) => false; // 如果没有指定条件,则条件始终不满足
|
||||
}
|
||||
return null; // 所有子节点完成时返回 null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user