BITKit/Src/Unity/Scripts/Sensor/Smart/SmartTargetSensor.cs

57 lines
1.5 KiB
C#
Raw Normal View History

2023-08-11 23:57:37 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2024-03-31 23:31:00 +08:00
using System.Text;
using System.Threading;
2024-04-16 04:06:46 +08:00
using BITKit.Sensors.States;
using BITKit.StateMachine;
2023-08-11 23:57:37 +08:00
using Cysharp.Threading.Tasks;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.UIElements;
#endif
using UnityEngine;
2024-03-31 23:31:00 +08:00
using UnityEngine.Accessibility;
2023-11-15 23:55:06 +08:00
using UnityEngine.Profiling;
2023-08-11 23:57:37 +08:00
using UnityEngine.UIElements;
2024-03-31 23:31:00 +08:00
// ReSharper disable PossibleMultipleEnumeration
2023-08-11 23:57:37 +08:00
namespace BITKit.Sensors
{
2024-04-16 04:06:46 +08:00
public interface ISmartTargetProperty{}
public interface ISmartTargetState:IState{}
2023-08-11 23:57:37 +08:00
/// <summary>
/// 智能目标传感器,根据条件,智能选择目标
/// </summary>
2024-04-16 04:06:46 +08:00
public class SmartTargetSensor :StateBasedMonoBehaviour<ISmartTargetState>,ISensor
2023-08-11 23:57:37 +08:00
{
2024-04-16 04:06:46 +08:00
[SerializeField] private float radius;
[SerializeField] private RangeSensor rangeSensor;
[SerializeField] private AudioSensor audioSensor;
public int Id { get; set; }
private readonly CacheList<Transform> _detected=new();
2024-05-31 01:23:15 +08:00
public HashSet<int> Ignores { get; } = new();
2024-04-16 04:06:46 +08:00
private void OnEnable()
2023-11-15 23:55:06 +08:00
{
2024-04-16 04:06:46 +08:00
Id = GetInstanceID();
SensorQueue.Register(Id,this);
2023-11-15 23:55:06 +08:00
}
2024-04-16 04:06:46 +08:00
private void Start()
2024-03-31 23:31:00 +08:00
{
2024-04-16 04:06:46 +08:00
TransitionState<Idle>();
2024-03-31 23:31:00 +08:00
}
private void OnDisable()
{
SensorQueue.UnRegister(Id);
}
2024-04-16 04:06:46 +08:00
public IEnumerable<Transform> Get() => _detected.ValueArray;
public bool IsValid(Collider _collider) => false;
public float GetDistance() => radius;
public UniTask Execute(float delta)
2024-03-31 23:31:00 +08:00
{
2024-04-16 04:06:46 +08:00
CurrentState?.OnStateUpdate(delta);
return UniTask.CompletedTask;
2023-08-11 23:57:37 +08:00
}
}
}