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

55 lines
993 B
C#

using Godot;
namespace Rokojori
{
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/RJSensor.svg")]
public partial class CombineSensor : RJSensor
{
[Export]
public RJSensor[] sensors;
[Export]
public float axisActivationTreshold = 0.75f;
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 > axisActivationTreshold;
}
public override void _Process( double delta )
{
var value = 0f;
for ( int i = 0; i < sensors.Length; i++ )
{
value = Mathf.Max( value, sensors[ i ].GetValue() );
}
UpdateValue( value );
}
}
}