Files
Gen_Hack-and-Slash-Roguelit…/Client/Assets/Scripts/AI/AIBase.cs
2025-07-20 20:41:37 +08:00

63 lines
1.4 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 WanderNode : AIBase
{
}
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;
}
}
}