Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
using Base;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
namespace AI
|
|
{
|
|
public abstract class JobBase
|
|
{
|
|
public Entity.Entity entity;
|
|
private int timeoutTicks = 100;
|
|
public bool Running=>timeoutTicks > 0;
|
|
|
|
public virtual void StartJob(Entity.Entity target)
|
|
{
|
|
entity = target;
|
|
}
|
|
|
|
protected abstract void UpdateJob();
|
|
|
|
public bool Update()
|
|
{
|
|
if(!Running)
|
|
return false;
|
|
UpdateJob();
|
|
timeoutTicks--;
|
|
if (timeoutTicks <= 0)
|
|
{
|
|
StopJob();
|
|
}
|
|
return true;
|
|
}
|
|
public virtual void StopJob()
|
|
{
|
|
timeoutTicks = 0;
|
|
}
|
|
}
|
|
public class WanderJob : JobBase
|
|
{
|
|
public override void StartJob(Entity.Entity target)
|
|
{
|
|
base.StartJob(target);
|
|
Vector3 move=new(Random.Range(-10,10), Random.Range(-10,10));
|
|
var targetPosition=entity.transform.position+move;
|
|
entity.SetTarget(targetPosition);
|
|
entity.IsChase = false;
|
|
}
|
|
|
|
protected override void UpdateJob()
|
|
{
|
|
entity.TryMove();
|
|
}
|
|
|
|
override public void StopJob()
|
|
{
|
|
base.StopJob();
|
|
entity.IsChase = true;
|
|
}
|
|
|
|
}
|
|
|
|
} |