rj-action-library/Runtime/Time/TimeLine.cs

65 lines
1.2 KiB
C#
Raw Normal View History

2025-01-08 18:46:17 +00:00
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System;
using Godot;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class TimeLine:Resource
{
[Export]
public bool isLooping = false;
[Export]
public float loopStart = 0;
[Export]
public float loopEnd = 100000;
[Export]
public float startSpeed = 1;
[Export]
public bool autoStart = true;
2025-01-19 20:35:51 +00:00
public TimeLineRunner runner
2025-01-08 18:46:17 +00:00
{
get
{
2025-01-19 20:35:51 +00:00
var tm = TimeLineManager.Get();
if ( tm == null )
{
return null;
}
2025-01-21 20:58:56 +00:00
2025-01-19 20:35:51 +00:00
return tm.GetRunner( this );
2025-01-08 18:46:17 +00:00
}
}
2025-01-19 20:35:51 +00:00
2025-01-21 20:58:56 +00:00
public float delta => runner == null ? ( (float)( (SceneTree)Engine.GetMainLoop()).Root.GetProcessDeltaTime() ): runner.currentDelta;
2025-01-08 18:46:17 +00:00
2025-01-21 20:58:56 +00:00
public float position => runner == null ? Time.GetTicksMsec() / 1000f : runner.position;
2025-01-19 20:35:51 +00:00
public float ComputePhase( float duration, float offset = 0 )
2025-01-13 18:11:12 +00:00
{
2025-01-19 20:35:51 +00:00
var time = position + offset;
2025-01-13 18:11:12 +00:00
2025-01-19 20:35:51 +00:00
return ( time % duration ) / duration;
2025-01-13 18:11:12 +00:00
}
2025-01-19 20:35:51 +00:00
public float ComputeRange( float start, float end )
2025-01-13 18:11:12 +00:00
{
2025-01-19 20:35:51 +00:00
return MathX.Normalize( position, start, end );
2025-01-13 18:11:12 +00:00
}
2025-01-19 20:35:51 +00:00
2025-01-08 18:46:17 +00:00
}
}