Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace AI
|
|
{
|
|
public abstract class AIBase
|
|
{
|
|
public List<AIBase> children = new();
|
|
|
|
public virtual JobBase GetJob(Entity.Entity target)
|
|
{
|
|
foreach (var aiBase in children)
|
|
{
|
|
var job = aiBase.GetJob(target);
|
|
if (job != null)
|
|
return job;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public class ContinuousMove : AIBase
|
|
{
|
|
override public JobBase GetJob(Entity.Entity target)
|
|
{
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public class TrackPlayer : AIBase
|
|
{
|
|
|
|
}
|
|
public class RandomWander : AIBase
|
|
{
|
|
public override JobBase GetJob(Entity.Entity target)
|
|
{
|
|
return new WanderJob();
|
|
}
|
|
}
|
|
public class ConditionalAI : AIBase
|
|
{
|
|
// 条件函数,返回 true 表示满足条件
|
|
private Func<Entity.Entity, bool> condition;
|
|
|
|
// 构造函数,传入条件函数
|
|
public ConditionalAI(Func<Entity.Entity, bool> conditionFunc)
|
|
{
|
|
condition = conditionFunc;
|
|
}
|
|
|
|
public override JobBase GetJob(Entity.Entity target)
|
|
{
|
|
// 检查条件是否满足
|
|
if (condition != null && condition(target))
|
|
{
|
|
// 如果条件满足,继续查找子节点的任务
|
|
return base.GetJob(target);
|
|
}
|
|
|
|
// 条件不满足,直接返回 null
|
|
return null;
|
|
}
|
|
}
|
|
} |