2025-01-18 12:49:14 +00:00
|
|
|
using Godot;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
|
2025-01-21 20:58:56 +00:00
|
|
|
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/Interactor.svg")]
|
2025-01-18 12:49:14 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|