You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
using Babushka.scripts.CSharp.Common.Services;
|
|
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
|
|
|
/// <summary>
|
|
/// Defines an <see cref="Area2D"/> Node with a <see cref="CollisionShape2D"/> used for detecting <see cref="InteractionArea2D"/> nodes.
|
|
/// </summary>
|
|
public partial class Detector : Area2D
|
|
{
|
|
|
|
[Export] private bool _active = true;
|
|
|
|
/// <summary>
|
|
/// Called when entering an interactionArea node.
|
|
/// </summary>
|
|
[Signal] public delegate void InteractableEnteredEventHandler();
|
|
|
|
/// <summary>
|
|
/// Called when exiting an interactionArea node.
|
|
/// </summary>
|
|
[Signal] public delegate void InteractableExitedEventHandler();
|
|
|
|
public bool IsActive
|
|
{
|
|
get => _active;
|
|
set
|
|
{
|
|
Visible = value;
|
|
_active = value;
|
|
}
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
AreaEntered += OnEnteredInteractable;
|
|
AreaExited += OnExitedInteractable;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called every time this node enters an Area2D.
|
|
/// </summary>
|
|
/// <param name="area"></param>
|
|
public void OnEnteredInteractable(Node area)
|
|
{
|
|
if (!_active || !InputService.Instance.InputEnabled)
|
|
return;
|
|
|
|
if (area is DetectableInteractionArea interactionArea2D)
|
|
{
|
|
EmitSignal(SignalName.InteractableEntered);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called whenever this node exits an Area2D.
|
|
/// </summary>
|
|
/// <param name="area"></param>
|
|
public void OnExitedInteractable(Node area)
|
|
{
|
|
if (!_active || !InputService.Instance.InputEnabled)
|
|
return;
|
|
|
|
if (area is DetectableInteractionArea interactionArea2D)
|
|
{
|
|
EmitSignal(SignalName.InteractableExited);
|
|
}
|
|
}
|
|
} |