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 }