Files
Gen_Hack-and-Slash-Roguelit…/Client/Assets/Scripts/AI/AIBase.cs
m0_75251201 6a222d82b2 (client) feat:实现摄像机跟踪,柏林噪声改为单例,角色渲染树支持指定像素密度
chore:将UI的Tick进行了显示时显式添加并作为预制体
2025-08-05 14:54:30 +08:00

93 lines
2.4 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 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 ConditionalAI : Selector
{
// 条件函数,返回 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;
}
}
public class SequenceAI : 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
}
}
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)
{
return new TrackPlayerJob();
}
}
public class RandomWander : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
return new WanderJob();
}
}
public class Idel : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
return new IdleJob();
}
}
}