This commit is contained in:
CortexCore
2023-10-24 23:38:22 +08:00
parent 2c4710bc5d
commit bd40165ade
152 changed files with 3681 additions and 1531 deletions

View File

@@ -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;
}
}