mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
56 lines
No EOL
1.1 KiB
C#
56 lines
No EOL
1.1 KiB
C#
using Godot;
|
|
|
|
namespace Cirno.Scripts.Actors;
|
|
|
|
[Tool]
|
|
public partial class Elevator3D : PathFollow3D, IActivable
|
|
{
|
|
[Export] public float Speed { get; set; }
|
|
|
|
private bool _isMoving = false;
|
|
private float _multiplier = 1f;
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (Engine.IsEditorHint()) return;
|
|
if (!_isMoving) return;
|
|
|
|
ProgressRatio += (Speed * (float)delta) * _multiplier;
|
|
|
|
if (ProgressRatio is >= 1 or <= 0)
|
|
{
|
|
_isMoving = false;
|
|
}
|
|
|
|
}
|
|
|
|
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
|
{
|
|
if (Engine.IsEditorHint()) return false;
|
|
if (_isMoving) return false;
|
|
|
|
StartMoving();
|
|
|
|
return true;
|
|
}
|
|
|
|
public void Toggle()
|
|
{
|
|
this.Activate();
|
|
}
|
|
|
|
public void StartMoving()
|
|
{
|
|
if (_isMoving) return;
|
|
_isMoving = true;
|
|
|
|
if (ProgressRatio <= 0)
|
|
{
|
|
_multiplier = 1f;
|
|
}
|
|
else if (ProgressRatio >= 1)
|
|
{
|
|
_multiplier = -1f;
|
|
}
|
|
}
|
|
} |