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

85 lines
1.6 KiB
C#
Raw Normal View History

2025-01-21 20:58:56 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
using System.Drawing;
2025-01-21 20:58:56 +00:00
namespace Rokojori
{
[Tool]
2025-01-21 20:58:56 +00:00
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/Grabbable.svg")]
public partial class Grabbable:Node3D, iEnablable
2025-01-21 20:58:56 +00:00
{
[Export]
public bool enabled = true;
public bool IsEnabled() => enabled;
public void SetEnabled( bool enabled ) { this.enabled = enabled; }
2025-01-21 20:58:56 +00:00
[Export]
public Action onGrab;
[Export]
public Action onRelease;
[Export]
public Node3D grabTarget;
2025-05-27 06:51:48 +00:00
[Export]
public RigidBody3D rigidBody3D;
[Export] Pointable pointable;
[Export]
public bool disablePointableDuringGrab = true;
2025-01-21 20:58:56 +00:00
[ExportGroup("Read Only")]
[Export]
public Grabber grabber;
protected bool enablePointableOnRelease = false;
2025-01-21 20:58:56 +00:00
public void SetGrabber( Grabber grabber )
{
this.grabber = grabber;
if ( grabber != null && ( disablePointableDuringGrab || grabber.disablePointableDuringGrab ) )
{
if ( pointable == null )
{
pointable = this.FindSibling<Pointable>();
}
if ( pointable != null )
{
pointable.enabled = false;
enablePointableOnRelease = true;
}
}
if ( grabber == null )
{
if ( pointable != null && enablePointableOnRelease )
{
pointable.enabled = true;
}
enablePointableOnRelease = false;
}
2025-01-21 20:58:56 +00:00
if ( this.grabber != null )
{
Action.Trigger( onGrab );
}
else
{
Action.Trigger( onRelease );
}
}
}
}