mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 06:15:53 +00:00
Elevators
This commit is contained in:
parent
929d993f99
commit
4fc136e5d7
39 changed files with 4471 additions and 264 deletions
72
Scripts/Interactables/AreaTrigger3D.cs
Normal file
72
Scripts/Interactables/AreaTrigger3D.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class AreaTrigger3D : Area3D
|
||||
{
|
||||
[Export] public Node3D Target { get; set; }
|
||||
|
||||
[Export] public ActivationType ActivationType { get; set; } = Scripts.ActivationType.Toggle;
|
||||
|
||||
[Export] public bool OneTime { get; set; }
|
||||
[Export] public bool DoNotActivateOnFirst { get; set; }
|
||||
|
||||
private int _activations = 0;
|
||||
|
||||
[Signal]
|
||||
public delegate void ActivatedEventHandler();
|
||||
|
||||
private IsoInteractionController _cachedPlayer;
|
||||
|
||||
private bool Activate()
|
||||
{
|
||||
if (_activations == 0 && DoNotActivateOnFirst)
|
||||
{
|
||||
_activations++;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OneTime && _activations > 0) return false;
|
||||
|
||||
if (Target != null)
|
||||
{
|
||||
if (Target is not IActivable target)
|
||||
{
|
||||
GD.PrintErr($"Target {Target.Name} is not activable");
|
||||
return false;
|
||||
}
|
||||
target.Activate(ActivationType);
|
||||
}
|
||||
|
||||
EmitSignal(nameof(Activated));
|
||||
|
||||
_activations++;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private void _on_area_entered(Area3D area)
|
||||
{
|
||||
if (area is not IsoInteractionController player) return;
|
||||
if (player.Enabled)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
_cachedPlayer = player;
|
||||
_cachedPlayer.InteractionStarted += PlayerOnInteractionStarted;
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayerOnInteractionStarted()
|
||||
{
|
||||
Activate();
|
||||
if (_cachedPlayer != null)
|
||||
{
|
||||
_cachedPlayer.InteractionStarted -= PlayerOnInteractionStarted;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Interactables/AreaTrigger3D.cs.uid
Normal file
1
Scripts/Interactables/AreaTrigger3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://btyooucm1g70g
|
||||
Loading…
Add table
Add a link
Reference in a new issue