53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.AI.States;
|
|
using BITKit;
|
|
using BITKit.AI.States;
|
|
using BITKit.Entities;
|
|
using BITKit.Sensors;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using UnityEngine.PlayerLoop;
|
|
|
|
namespace BITFALL.AI
|
|
{
|
|
/// <summary>
|
|
/// AI服务
|
|
/// </summary>
|
|
[CustomType(typeof(AIService))]
|
|
public class AIService : StateBasedBehavior<AI_Base>
|
|
{
|
|
[SerializeReference,SubclassSelector] private ITicker ticker;
|
|
[SerializeField] private NavMeshAgent agent;
|
|
[SerializeField] private RangeSensor rangeSensor;
|
|
[SerializeField] private AudioSensor audioSensor;
|
|
[SerializeField] private Tag selfTag;
|
|
[SerializeField] private Tag friendTag;
|
|
[SerializeField] private Tag enemyTag;
|
|
|
|
public IEntity CombatTarget { get; set; }
|
|
|
|
public RangeSensor RangeSensor => rangeSensor;
|
|
public AudioSensor AudioSensor => audioSensor;
|
|
public NavMeshAgent Agent => agent;
|
|
public ITag SelfTag => selfTag;
|
|
public ITag FriendTag => friendTag;
|
|
public ITag EnemyTag => enemyTag;
|
|
public override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
ticker.Add(OnTick);
|
|
TransitionState<Idle>();
|
|
}
|
|
private void OnTick(float obj)
|
|
{
|
|
UpdateState(obj);
|
|
}
|
|
public override void OnDestroyComponent()
|
|
{
|
|
base.OnDestroyComponent();
|
|
ticker.Remove(OnTick);
|
|
}
|
|
}
|
|
}
|