Files
ichni_Official/Assets/Scripts/Game/GameElements/Track/TrackSubmodules/TrackTimeSubmodule.cs

123 lines
3.9 KiB
C#
Raw Normal View History

2025-06-03 02:42:28 -04:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class TrackTimeSubmodule : TrackSubmodule
{
2026-03-14 03:13:10 -04:00
#region [] Config
2025-06-03 02:42:28 -04:00
public float headPercent, tailPercent;
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Initialization
2025-06-03 02:42:28 -04:00
public TrackTimeSubmodule(Track track) : base(track)
{
if (!HaveSameSubmodule)
{
this.track.trackTimeSubmodule = this;
}
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
}
2026-03-14 03:13:10 -04:00
#region [] Movable Submodule
2025-06-03 02:42:28 -04:00
public class TrackTimeSubmoduleMovable : TrackTimeSubmodule
{
2026-03-14 03:13:10 -04:00
#region [] Movable Configs
2025-06-03 02:42:28 -04:00
public float trackStartTime;
public float trackEndTime;
public float trackTotalTime;
public float visibleTrackTimeLength;
public AnimationCurveType animationCurveType;
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Initialization
2025-06-03 02:42:28 -04:00
public TrackTimeSubmoduleMovable(Track track, float trackStartTime, float trackEndTime,
float visibleTrackTimeLength, AnimationCurveType animationCurveType) : base(track)
{
this.trackStartTime = trackStartTime;
this.trackEndTime = trackEndTime;
this.trackTotalTime = trackEndTime - trackStartTime;
this.visibleTrackTimeLength = visibleTrackTimeLength;
this.animationCurveType = animationCurveType;
//timeDurationSubmodule 根据下辖Note的时间来设置
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Timing Calculation
public void UpdateTrackPart(float songTime)
2025-06-03 02:42:28 -04:00
{
headPercent = GetTrackPercent(songTime);
tailPercent = GetTrackPercent(songTime - visibleTrackTimeLength);
if (track.trackRendererSubmodule != null)
{
track.trackRendererSubmodule.meshGenerator.clipFrom = tailPercent;
track.trackRendererSubmodule.meshGenerator.clipTo = headPercent;
}
}
public float GetTrackPercent(float songTimeInTime)
{
float per = AnimationCurveEvaluator.Evaluate(animationCurveType, (songTimeInTime - trackStartTime) / trackTotalTime);
return Mathf.Clamp01(per);
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Behavior Overrides
2025-06-03 02:42:28 -04:00
public override void Refresh()
{
trackTotalTime = trackEndTime - trackStartTime;
2026-03-14 03:13:10 -04:00
UpdateTrackPart(CoreServices.TimeProvider.SongTime);
2025-06-03 02:42:28 -04:00
track.childElementList.ForEach(child =>
{
if (child is NoteBase note)
{
2026-03-14 03:13:10 -04:00
note.UpdateNoteInTrack(CoreServices.TimeProvider.SongTime);
2025-06-03 02:42:28 -04:00
}
});
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
}
#endregion
2026-03-14 03:13:10 -04:00
#region [] Static Submodule
2025-06-03 02:42:28 -04:00
public class TrackTimeSubmoduleStatic : TrackTimeSubmodule
{
2026-03-14 03:13:10 -04:00
#region [] Static Configs
2025-06-03 02:42:28 -04:00
public float trackTotalTime;
public AnimationCurveType animationCurveType;
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Initialization
2025-06-03 02:42:28 -04:00
public TrackTimeSubmoduleStatic(Track track, float trackTotalTime, AnimationCurveType animationCurveType) :
base(track)
{
this.trackTotalTime = trackTotalTime;
this.animationCurveType = animationCurveType;
this.headPercent = 0;
this.tailPercent = 1;
//timeDurationSubmodule 根据下辖Note的时间来设置
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Behavior Overrides
2025-06-03 02:42:28 -04:00
public override void Refresh()
{
track.childElementList.ForEach(child =>
{
if (child is NoteBase note)
{
2026-03-14 03:13:10 -04:00
note.UpdateNoteInTrack(CoreServices.TimeProvider.SongTime);
2025-06-03 02:42:28 -04:00
}
});
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
}
#endregion
}