1
This commit is contained in:
@@ -38,6 +38,32 @@ namespace BITKit.Sensors
|
||||
/// <returns></returns>
|
||||
UniTask Execute();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UnitySensor : ISensor
|
||||
{
|
||||
[SerializeField] private GameObject gameObject;
|
||||
private ISensor _sensorImplementation => gameObject.GetComponent<ISensor>();
|
||||
public IEnumerable<Transform> Get()
|
||||
{
|
||||
return _sensorImplementation.Get();
|
||||
}
|
||||
|
||||
public bool IsValid(Collider _collider)
|
||||
{
|
||||
return _sensorImplementation.IsValid(_collider);
|
||||
}
|
||||
|
||||
public float GetDistance()
|
||||
{
|
||||
return _sensorImplementation.GetDistance();
|
||||
}
|
||||
|
||||
public UniTask Execute()
|
||||
{
|
||||
return _sensorImplementation.Execute();
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public class SensorMonoProxy:ISensor
|
||||
{
|
||||
|
@@ -80,8 +80,15 @@ namespace BITKit.Sensors
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (CurrentTarget is null) return;
|
||||
Gizmos.DrawLine(sensorTransform.position,CurrentTarget.position);
|
||||
try
|
||||
{
|
||||
if (CurrentTarget is null || sensorTransform is null) return;
|
||||
Gizmos.DrawLine(sensorTransform.position,CurrentTarget.position);
|
||||
}
|
||||
catch (UnassignedReferenceException)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Pool;
|
||||
using UnityEngine.UIElements;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
@@ -60,7 +61,26 @@ namespace BITKit.Sensors
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Transform> Get() => detected.Select(x => x.transform).ToArray();
|
||||
public IEnumerable<Transform> Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
return detected.Select(x => x.transform).ToArray();
|
||||
}
|
||||
catch (MissingReferenceException)
|
||||
{
|
||||
List<Transform> list = new();
|
||||
foreach (var x in detected)
|
||||
{
|
||||
try
|
||||
{
|
||||
list.Add(x.transform);
|
||||
}
|
||||
catch (MissingReferenceException){}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
//public bool IsValid(Collider _collider) => ignores.Contains(_collider.gameObject) is false;
|
||||
public bool IsValid(Collider _collider)
|
||||
@@ -100,19 +120,43 @@ namespace BITKit.Sensors
|
||||
{
|
||||
if (IsValid(_collider) is false) return;
|
||||
if (detected.Contains(_collider))continue;
|
||||
onDetected.Invoke(_collider);
|
||||
detected.Add(_collider);
|
||||
}
|
||||
while (triggerExitQueue.TryDequeue(out var _collider))
|
||||
{
|
||||
if (IsValid(_collider) is false) return;
|
||||
onLost.Invoke(_collider);
|
||||
detected.Remove(_collider);
|
||||
}
|
||||
|
||||
diagnosisNextFrame = detected.Any(x =>x is not null &&x.enabled is false);
|
||||
try
|
||||
{
|
||||
diagnosisNextFrame = detected.Any(x =>x is not null &&x.enabled is false);
|
||||
}
|
||||
catch (MissingReferenceException)
|
||||
{
|
||||
diagnosisNextFrame = true;
|
||||
}
|
||||
|
||||
|
||||
if (diagnosisNextFrame)
|
||||
{
|
||||
detected = detected.Where(x => x.enabled).ToList();
|
||||
var list = ListPool<Collider>.Get();
|
||||
foreach (var VARIABLE in detected)
|
||||
{
|
||||
try
|
||||
{
|
||||
list.Add(VARIABLE);
|
||||
}
|
||||
catch (MissingReferenceException e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
detected.Clear();
|
||||
detected.AddRange(list);
|
||||
ListPool<Collider>.Release(list);
|
||||
diagnosisNextFrame = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user