71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
|
|
|
||
|
|
using Godot;
|
||
|
|
|
||
|
|
|
||
|
|
namespace Rokojori
|
||
|
|
{
|
||
|
|
[Tool]
|
||
|
|
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/WindManager.svg") ]
|
||
|
|
public partial class WindManager:Node
|
||
|
|
{
|
||
|
|
[Export]
|
||
|
|
public WindManagerData data;
|
||
|
|
|
||
|
|
|
||
|
|
public override void _Process( double delta )
|
||
|
|
{
|
||
|
|
var rm = Unique<RenderingManager>.Get();
|
||
|
|
|
||
|
|
if ( data == null || rm == null )
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
UpdatePosition( rm, (float) delta );
|
||
|
|
UpdateDirection( rm, (float) delta );
|
||
|
|
UpdateSpeed( rm, (float) delta );
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void UpdatePosition( RenderingManager rm, float delta )
|
||
|
|
{
|
||
|
|
var windPositionProperty = rm.data.GetGlobalPropertyByName( data.globalWindPositionPropertyName );
|
||
|
|
|
||
|
|
if ( windPositionProperty == null )
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var positionProperty = (Vector2Property) windPositionProperty;
|
||
|
|
var position = positionProperty.value;
|
||
|
|
position += -data.windSpeed.GetNormalizedWindSpeedOffset( delta, data.minimumScrollSpeedKMH, data.maximumScrollSpeedKMH ) * data.windDirection.Normalized();
|
||
|
|
positionProperty.value = position;
|
||
|
|
}
|
||
|
|
|
||
|
|
void UpdateDirection( RenderingManager rm, float delta )
|
||
|
|
{
|
||
|
|
var windDirectionProperty = rm.data.GetGlobalPropertyByName( data.globalWindDirectionPropertyName );
|
||
|
|
|
||
|
|
if ( windDirectionProperty == null )
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var directionProperty = (Vector2Property) windDirectionProperty;
|
||
|
|
directionProperty.value = data.windDirection.Normalized();
|
||
|
|
}
|
||
|
|
|
||
|
|
void UpdateSpeed( RenderingManager rm, float delta )
|
||
|
|
{
|
||
|
|
var windSpeedProperty = rm.data.GetGlobalPropertyByName( data.globalWindSpeeedPropertyName );
|
||
|
|
|
||
|
|
if ( windSpeedProperty == null )
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var speedProperty = (FloatProperty) windSpeedProperty;
|
||
|
|
speedProperty.value = data.windSpeed.GetKMH();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|