rj-action-library/Runtime/Sensors/InputActionSensor.cs

42 lines
904 B
C#

using Godot;
using System.Collections.Generic;
namespace Rokojori
{
[Tool]
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/RJSensor.svg")]
public partial class InputActionSensor: Sensor
{
[Export]
public string inputActionName = "";
public enum PollMode
{
Button,
Half_Axis,
Release_Only_Button
}
[Export]
public PollMode pollMode = PollMode.Button;
protected override void UpdateValue()
{
if ( PollMode.Button == pollMode )
{
SetBoolValue( Input.IsActionPressed( inputActionName ) );
}
else if ( PollMode.Release_Only_Button == pollMode )
{
SetBoolValue( Input.IsActionJustReleased( inputActionName ) );
}
else if ( PollMode.Half_Axis == pollMode )
{
SetFloatValue( Input.GetActionRawStrength( inputActionName ) );
}
}
}
}