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

63 lines
1.2 KiB
C#
Raw Normal View History

2025-01-21 20:58:56 +00:00
using Godot;
using System.Collections.Generic;
2025-01-21 20:58:56 +00:00
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;
[Export]
public GamePadAxisType type;
2025-01-21 20:58:56 +00:00
public override string ToString()
{
return RJLog.GetInfo( this, axis, type );
}
2025-01-21 20:58:56 +00:00
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( (GamePadAxisType.Negative == type ? -1 : 1 ) * joypadAxisEvent.AxisValue, 0 );
UpdateSensorUsage( joypadAxisEvent.Device );
2025-01-21 20:58:56 +00:00
}
public override List<InputIcon> GetInputIcons()
{
var icon = new GamePadAxisIcon();
icon.axis = axis;
icon.type = type;
return new List<InputIcon>(){ icon };
}
2025-01-21 20:58:56 +00:00
}
}