rj-action-library/Runtime/Interactions/Interactor.cs

52 lines
899 B
C#
Raw Normal View History

2025-01-18 12:49:14 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
[GlobalClass]
public partial class Interactor:Node3D, SensorInputHandler
{
[Export]
public Pointer pointer;
[Export]
public Sensor button;
2025-01-18 20:02:20 +00:00
public override void _Ready()
{
SensorManager.Register( this, button );
}
public override void _ExitTree()
{
SensorManager.Unregister( this, button );
}
2025-01-18 12:49:14 +00:00
public void _OnSensor( SensorEvent se )
{
2025-01-18 20:02:20 +00:00
2025-01-18 12:49:14 +00:00
if ( pointer == null || pointer.pointable == null )
{
return;
}
2025-01-18 20:02:20 +00:00
if ( ! se.isDown )
{
return;
}
2025-01-18 12:49:14 +00:00
var interactable = Nodes.Find<Interactable>( pointer.pointable.GetParent() );
if ( interactable == null )
{
2025-01-18 20:02:20 +00:00
2025-01-18 12:49:14 +00:00
return;
}
Action.Trigger( interactable.onInteraction );
}
}
}