2025-01-21 20:58:56 +00:00
|
|
|
|
|
|
|
using Godot;
|
2025-02-12 16:48:15 +00:00
|
|
|
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]
|
2025-02-12 16:48:15 +00:00
|
|
|
public GamePadAxisType type;
|
2025-01-21 20:58:56 +00:00
|
|
|
|
2025-02-12 16:48:15 +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;
|
|
|
|
}
|
|
|
|
|
2025-02-12 16:48:15 +00:00
|
|
|
_lastInput = Mathf.Max( (GamePadAxisType.Negative == type ? -1 : 1 ) * joypadAxisEvent.AxisValue, 0 );
|
|
|
|
|
|
|
|
UpdateSensorUsage( joypadAxisEvent.Device );
|
2025-01-21 20:58:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-02-12 16:48:15 +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
|
|
|
|
|
|
|
}
|
|
|
|
}
|