(client) feat:添加行为树和工作类

This commit is contained in:
m0_75251201
2025-07-20 20:41:37 +08:00
parent 9dcc67d710
commit a48ccca5f4
12 changed files with 350 additions and 44 deletions

View File

@ -1,35 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
namespace Entity
{
public abstract class AIBase
{
public virtual bool Run(Entity target)
{
foreach (var aiBase in children)
{
if (aiBase.Run(target))
return true;
}
return false;
}
public List<AIBase> children=new();
}
public class ContinuousMove : AIBase
{
override public bool Run(Entity target)
{
target.gameObject.transform.position +=
Time.deltaTime * target.runtimeAttributes.moveSpeed * target.direction;
return true;
}
}
public class TrackPlayer : AIBase
{
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 7dba424df1b6411f91925da8288cb91f
timeCreated: 1752983113

View File

@ -1,22 +1,42 @@
using System.Collections.Generic;
using AI;
using Base;
using Data;
using UnityEngine;
namespace Entity
{
public abstract class Entity:MonoBehaviour,ITick
{
public string name;
public bool playerControlled = false;
public List<AIBase> aiTree=new();
public Data.AttributesDef runtimeAttributes;
public AIBase aiTree;
public JobBase currentJob;
public AttributesDef runtimeAttributes;
public Vector3 direction;
private const int WarningInterval = 5000;
private int warningTicks = 0;
public void Tick()
{
foreach (var aiBase in aiTree)
if (currentJob == null || !currentJob.Running)
{
if (aiBase.Run(this))
break;
currentJob = aiTree.GetJob(this);
if (currentJob == null)
{
if (warningTicks<=0)
{
Debug.LogWarning($"{GetType().Name}类型的{name}没有分配到任何工作,给行为树末尾添加等待行为,避免由于没有工作导致无意义的反复查找工作导致性能问题");
warningTicks += WarningInterval;
}
warningTicks--;
return;
}
}
currentJob.Update();
}
public virtual void TryAttck()