rokojori_action_library/Runtime/Animation/Driver/FloatDriver.cs

85 lines
1.5 KiB
C#
Raw Normal View History

2026-01-05 21:14:39 +00:00
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
using Godot;
namespace Rokojori
{
2026-01-10 18:35:50 +00:00
public interface IFloatDriver
{
public float GetDriverFloatValue();
}
2026-01-05 21:14:39 +00:00
[Tool]
[GlobalClass]
2026-01-10 18:35:50 +00:00
public partial class FloatDriver:Node, IFloatDriver
2026-01-05 21:14:39 +00:00
{
float _driverValue = 0f;
[Export( PropertyHint.Range, "0,1" )]
public float value
{
get => _driverValue;
set
{
_driverValue = value;
UpdateValue();
}
}
2026-01-10 18:35:50 +00:00
public float GetDriverFloatValue()
{ return _driverValue; }
2026-01-05 21:14:39 +00:00
[ExportToolButton( "Update Value")]
public Callable updateValueButton => Callable.From( ()=> UpdateValue() ) ;
void UpdateValue()
2026-01-10 18:35:50 +00:00
{
for ( int i = 0; targets != null && i < targets.Length; i++ )
2026-01-05 21:14:39 +00:00
{
if ( targets[ i ] == null || targets[ i ].GetGodotObject( this ) == null )
{
continue;
}
targets[ i ].Update( this );
}
2026-01-10 18:35:50 +00:00
onChange?.Trigger();
if ( value == 0 )
{
onZero?.Trigger();
}
else if ( value == 1 )
{
onOne?.Trigger();
}
else
{
onIntermediate?.Trigger();
}
2026-01-05 21:14:39 +00:00
}
[Export]
public FloatDriverTarget[] targets = [];
2026-01-10 18:35:50 +00:00
[Export]
public Action onChange;
[Export]
public Action onZero;
[Export]
public Action onOne;
[Export]
public Action onIntermediate;
2026-01-05 21:14:39 +00:00
}
}