|
|
|
|
@ -14,7 +14,7 @@ public partial class Detector : Area2D
|
|
|
|
|
[Export] private ShapeCast2D _shapeCast2D;
|
|
|
|
|
[Export] private VariableResource _itemToTriggerResource;
|
|
|
|
|
|
|
|
|
|
private readonly List<ulong> _areasInDetector = new();
|
|
|
|
|
private List<ulong> _areasInDetector = new();
|
|
|
|
|
|
|
|
|
|
public bool IsActive
|
|
|
|
|
{
|
|
|
|
|
@ -41,12 +41,8 @@ public partial class Detector : Area2D
|
|
|
|
|
if (!_active || !InputService.Instance.InputEnabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (area is DetectableInteractionArea detectable)
|
|
|
|
|
{
|
|
|
|
|
ulong id = detectable.GetInstanceId();
|
|
|
|
|
_areasInDetector.Add(id);
|
|
|
|
|
CalculateClosestInteractable();
|
|
|
|
|
}
|
|
|
|
|
PopulateList();
|
|
|
|
|
CalculateClosestInteractable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -58,12 +54,23 @@ public partial class Detector : Area2D
|
|
|
|
|
if (!_active || !InputService.Instance.InputEnabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (area is DetectableInteractionArea detectable)
|
|
|
|
|
PopulateList();
|
|
|
|
|
CalculateClosestInteractable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateList()
|
|
|
|
|
{
|
|
|
|
|
// repopulate the list of areas in the detector to account for enabled / disabled areas
|
|
|
|
|
var currentOverlap = GetOverlappingAreas();
|
|
|
|
|
_areasInDetector = new List<ulong>();
|
|
|
|
|
|
|
|
|
|
foreach (var area2D in currentOverlap)
|
|
|
|
|
{
|
|
|
|
|
ulong id = detectable.GetInstanceId();
|
|
|
|
|
if( _areasInDetector.Contains(id))
|
|
|
|
|
_areasInDetector.Remove(id);
|
|
|
|
|
CalculateClosestInteractable();
|
|
|
|
|
if (area2D is DetectableInteractionArea detectable)
|
|
|
|
|
{
|
|
|
|
|
ulong id = detectable.GetInstanceId();
|
|
|
|
|
_areasInDetector.Add(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|