2025-07-21 13:58:58 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace AI
|
|
|
|
|
{
|
|
|
|
|
public abstract class AIBase
|
|
|
|
|
{
|
|
|
|
|
public List<AIBase> children = new();
|
|
|
|
|
|
2025-07-25 19:16:58 +08:00
|
|
|
|
public abstract JobBase GetJob(Entity.Entity target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Selector : AIBase
|
|
|
|
|
{
|
|
|
|
|
public override JobBase GetJob(Entity.Entity target)
|
2025-07-21 13:58:58 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var aiBase in children)
|
|
|
|
|
{
|
|
|
|
|
var job = aiBase.GetJob(target);
|
|
|
|
|
if (job != null)
|
|
|
|
|
return job;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-25 19:16:58 +08:00
|
|
|
|
public class ConditionalAI : Selector
|
2025-07-21 13:58:58 +08:00
|
|
|
|
{
|
|
|
|
|
// 条件函数,返回 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-07 16:44:43 +08:00
|
|
|
|
public class SequenceAI : AIBase
|
2025-07-25 19:16:58 +08:00
|
|
|
|
{
|
|
|
|
|
public override JobBase GetJob(Entity.Entity target)
|
|
|
|
|
{
|
2025-08-07 16:44:43 +08:00
|
|
|
|
foreach (var aiBase in children)
|
2025-07-25 19:16:58 +08:00
|
|
|
|
{
|
2025-08-07 16:44:43 +08:00
|
|
|
|
var job = aiBase.GetJob(target);
|
|
|
|
|
if (job == null)
|
|
|
|
|
return null; // 如果某个子节点返回 null,则整个序列失败
|
2025-07-25 19:16:58 +08:00
|
|
|
|
}
|
2025-08-07 16:44:43 +08:00
|
|
|
|
return null; // 所有子节点完成时返回 null
|
2025-07-25 19:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class ContinuousMove : AIBase
|
|
|
|
|
{
|
|
|
|
|
public override JobBase GetJob(Entity.Entity target)
|
|
|
|
|
{
|
|
|
|
|
return new MoveJob();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TrackPlayer : AIBase
|
|
|
|
|
{
|
|
|
|
|
public override JobBase GetJob(Entity.Entity target)
|
|
|
|
|
{
|
2025-08-07 16:44:43 +08:00
|
|
|
|
return new TrackPlayerJob();
|
2025-07-25 19:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class RandomWander : AIBase
|
|
|
|
|
{
|
|
|
|
|
public override JobBase GetJob(Entity.Entity target)
|
|
|
|
|
{
|
|
|
|
|
return new WanderJob();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-07 16:44:43 +08:00
|
|
|
|
public class Idel : AIBase
|
|
|
|
|
{
|
|
|
|
|
public override JobBase GetJob(Entity.Entity target)
|
|
|
|
|
{
|
|
|
|
|
return new IdleJob();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-21 13:58:58 +08:00
|
|
|
|
}
|