Files
SoulliesOfficial 7580c4d87c 大更
2026-03-14 03:13:10 -04:00

123 lines
3.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class TrackTimeSubmodule : TrackSubmodule
{
#region [] Config
public float headPercent, tailPercent;
#endregion
#region [] Initialization
public TrackTimeSubmodule(Track track) : base(track)
{
if (!HaveSameSubmodule)
{
this.track.trackTimeSubmodule = this;
}
}
#endregion
}
#region [] Movable Submodule
public class TrackTimeSubmoduleMovable : TrackTimeSubmodule
{
#region [] Movable Configs
public float trackStartTime;
public float trackEndTime;
public float trackTotalTime;
public float visibleTrackTimeLength;
public AnimationCurveType animationCurveType;
#endregion
#region [] Initialization
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的时间来设置
}
#endregion
#region [] Timing Calculation
public void UpdateTrackPart(float songTime)
{
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);
}
#endregion
#region [] Behavior Overrides
public override void Refresh()
{
trackTotalTime = trackEndTime - trackStartTime;
UpdateTrackPart(CoreServices.TimeProvider.SongTime);
track.childElementList.ForEach(child =>
{
if (child is NoteBase note)
{
note.UpdateNoteInTrack(CoreServices.TimeProvider.SongTime);
}
});
}
#endregion
}
#endregion
#region [] Static Submodule
public class TrackTimeSubmoduleStatic : TrackTimeSubmodule
{
#region [] Static Configs
public float trackTotalTime;
public AnimationCurveType animationCurveType;
#endregion
#region [] Initialization
public TrackTimeSubmoduleStatic(Track track, float trackTotalTime, AnimationCurveType animationCurveType) :
base(track)
{
this.trackTotalTime = trackTotalTime;
this.animationCurveType = animationCurveType;
this.headPercent = 0;
this.tailPercent = 1;
//timeDurationSubmodule 根据下辖Note的时间来设置
}
#endregion
#region [] Behavior Overrides
public override void Refresh()
{
track.childElementList.ForEach(child =>
{
if (child is NoteBase note)
{
note.UpdateNoteInTrack(CoreServices.TimeProvider.SongTime);
}
});
}
#endregion
}
#endregion
}