95 lines
1.8 KiB
C#
95 lines
1.8 KiB
C#
|
|
using Godot;
|
|
|
|
|
|
namespace Rokojori
|
|
{
|
|
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/RJSensor.svg")]
|
|
public partial class MouseMotionDelta : RJSensor
|
|
{
|
|
public enum MouseMotionType
|
|
{
|
|
Right,
|
|
Left,
|
|
Up,
|
|
Down
|
|
}
|
|
|
|
[Export]
|
|
public MouseMotionType motionType;
|
|
|
|
[Export]
|
|
public float speedMultiply = 1;
|
|
|
|
bool _isActive = false;
|
|
bool _wasActive = false;
|
|
float _value = 0;
|
|
float axisActivationTreshold = 0.5f;
|
|
float _lastInput = 0;
|
|
|
|
public override void _Process( double delta )
|
|
{
|
|
UpdateValue( _lastInput );
|
|
_lastInput = 0;
|
|
}
|
|
|
|
public override void _Input( InputEvent ev )
|
|
{
|
|
var mouseEvent = ev as InputEventMouseMotion ;
|
|
|
|
if ( mouseEvent == null )
|
|
{
|
|
return;
|
|
}
|
|
|
|
var delta = mouseEvent.ScreenRelative;
|
|
var motion = 0f;
|
|
|
|
if ( MouseMotionType.Left == motionType)
|
|
{
|
|
motion = Mathf.Max( 0, -delta.X );
|
|
}
|
|
else if ( MouseMotionType.Right == motionType)
|
|
{
|
|
motion = Mathf.Max( 0, delta.X );
|
|
}
|
|
else if ( MouseMotionType.Up == motionType)
|
|
{
|
|
motion = Mathf.Max( 0, delta.Y );
|
|
}
|
|
if ( MouseMotionType.Down == motionType)
|
|
{
|
|
motion = Mathf.Max( 0, -delta.Y );
|
|
}
|
|
|
|
// RJLog.Log( "Motion:", motionType, motion * speedMultiply );
|
|
|
|
_lastInput = motion * speedMultiply;
|
|
|
|
}
|
|
|
|
public override bool IsActive()
|
|
{
|
|
return _isActive;
|
|
}
|
|
|
|
public override bool WasActive()
|
|
{
|
|
return _wasActive;
|
|
}
|
|
|
|
public override float GetValue()
|
|
{
|
|
return _value;
|
|
}
|
|
|
|
public override void UpdateValue( float value )
|
|
{
|
|
_value = value;
|
|
|
|
_wasActive = _isActive;
|
|
_isActive = _value > axisActivationTreshold;
|
|
}
|
|
|
|
}
|
|
} |