Files
Gen_Hack-and-Slash-Roguelit…/Client/Assets/Scripts/AI/AIBase.cs

65 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using UnityEngine;
namespace AI
{
public abstract class AIBase
{
public List<AIBase> children = new();
public abstract JobBase GetJob(Entity.Entity target);
}
public class ThinkNode_Selector : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
foreach (var aiBase in children)
{
var job = aiBase.GetJob(target);
if (job != null)
return job;
}
return null;
}
}
public class ThinkNode_Conditional : ThinkNode_Selector
{
// 条件函数,返回 true 表示满足条件
private Func<Entity.Entity, bool> condition;
// 构造函数,传入条件函数
public ThinkNode_Conditional(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;
}
}
public class ThinkNode_Sequence : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
foreach (var aiBase in children)
{
var job = aiBase.GetJob(target);
if (job == null)
return null; // 如果某个子节点返回 null则整个序列失败
}
return null; // 所有子节点完成时返回 null
}
}
}