rokojori_action_library/Runtime/Time/Timeline.cs

81 lines
1.5 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;
2026-05-22 12:25:02 +00:00
using Rokojori.Extensions;
2025-01-08 18:46:17 +00:00
namespace Rokojori
{
2026-05-22 12:25:02 +00:00
[RokojoriActionCoreExport]
[Tool][GlobalClass]
public partial class Timeline:Resource
2025-01-08 18:46:17 +00:00
{
2026-05-22 12:25:02 +00:00
[Export]
public bool executesInPause = false;
[Export]
public bool isModulatedByTimeScale = false;
[ExportGroup("Start")]
[Export]
public bool autoStart = true;
[Export]
public float startSpeed = 1;
[ExportGroup("Looping")]
2025-01-08 18:46:17 +00:00
[Export]
public bool isLooping = false;
[Export]
public float loopStart = 0;
[Export]
public float loopEnd = 100000;
2025-10-31 12:09:03 +00:00
2025-01-08 18:46:17 +00:00
2026-05-22 12:25:02 +00:00
public static float osTime => (float)(Godot.Time.GetTicksMsec() / 1000.0 );
public TimelineRunner runner
2025-01-08 18:46:17 +00:00
{
get
{
2026-05-22 12:25:02 +00:00
var tm = TimelineManager.Get();
2025-01-19 20:35:51 +00:00
if ( tm == null )
{
return null;
}
2025-01-21 20:58:56 +00:00
2026-05-22 12:25:02 +00:00
return tm.GetRunnerByTimeline( 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
2026-05-22 12:25:02 +00:00
public float position => runner == null ? Godot.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
}
}