54 lines
901 B
C#
54 lines
901 B
C#
|
|
using Godot;
|
|
|
|
|
|
namespace Rokojori
|
|
{
|
|
[Tool]
|
|
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/AxisSensor.svg")]
|
|
public partial class GamePadAxisSensor : Sensor, iOnInputSensor
|
|
{
|
|
[Export]
|
|
public JoyAxis axis;
|
|
|
|
public override bool isMultiDevice => true;
|
|
|
|
public enum AxisType
|
|
{
|
|
Negative,
|
|
Positive
|
|
}
|
|
|
|
|
|
[Export]
|
|
public AxisType type;
|
|
|
|
|
|
float _lastInput = 0;
|
|
|
|
protected override void UpdateValue()
|
|
{
|
|
SetFloatValue( _lastInput );
|
|
}
|
|
|
|
public void _Input( InputEvent ev )
|
|
{
|
|
var joypadAxisEvent = ev as InputEventJoypadMotion;
|
|
|
|
if ( joypadAxisEvent == null )
|
|
{
|
|
return;
|
|
}
|
|
|
|
if ( joypadAxisEvent.Axis != axis )
|
|
{
|
|
return;
|
|
}
|
|
|
|
_lastInput = Mathf.Max( (AxisType.Negative == type ? -1 : 1 ) * joypadAxisEvent.AxisValue, 0 );
|
|
|
|
}
|
|
|
|
|
|
}
|
|
} |