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

47 lines
861 B
C#
Raw Normal View History

2024-05-05 07:52:06 +00:00
using Godot;
namespace Rokojori
{
[GlobalClass,Icon("res://Scripts/Rokojori/Rokojori-Action-Library/Icons/RJSensor.svg")]
public partial class InputSensor : RJSensor
{
[Export]
public string inputActionName = "";
float _value = 0;
bool _wasActive = false;
bool _isActive = false;
public override float GetValue()
{
return _value;
}
public override bool IsActive()
{
return _isActive;
}
public override bool WasActive()
{
return _wasActive;
}
public override void UpdateValue( float value )
{
_value = value;
_wasActive = _isActive;
_isActive = _value > 0;
}
public override void _Process( double delta )
{
var inputValue = Input.GetActionRawStrength( inputActionName );
UpdateValue( inputValue );
}
}
}