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

103 lines
3.2 KiB
C#
Raw Normal View History

2025-06-03 02:42:28 -04:00
using System;
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using Ichni.RhythmGame.Beatmap;
namespace Ichni.RhythmGame
{
public partial class TrackPathSubmodule : TrackSubmodule
{
2026-03-14 03:13:10 -04:00
#region [] Essential Configs
public SplineComputer path;
2025-06-03 02:42:28 -04:00
public List<PathNode> pathNodeList;
public Track.TrackSpaceType trackSpaceType;
public Track.TrackSamplingType trackSamplingType;
public bool isClosed;
2026-03-14 03:13:10 -04:00
public bool isShowingDisplay;
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Calculated & Cached States
2026-01-21 00:31:23 -05:00
public bool refreshedThisFrame = false;
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 TrackPathSubmodule(Track track, Track.TrackSpaceType trackSpaceType,
Track.TrackSamplingType trackSamplingType, bool isClosed, bool isShowingDisplay) : base(track)
{
2026-03-14 03:13:10 -04:00
this.path = track.GetComponent<SplineComputer>();
2026-02-27 08:21:00 -05:00
2025-06-03 02:42:28 -04:00
this.pathNodeList = new List<PathNode>();
this.trackSpaceType = trackSpaceType;
this.trackSamplingType = trackSamplingType;
this.isClosed = isClosed;
2026-02-27 08:21:00 -05:00
this.path.sampleRate = 8;
2025-06-03 02:42:28 -04:00
this.path.updateMode = SplineComputer.UpdateMode.LateUpdate;
SetUpSplineComputer(this.trackSpaceType, this.trackSamplingType);
//闭合路径在PathNode生成时执行在初始化的情况下PathNode数量为0不会执行闭合操作
this.isShowingDisplay = isShowingDisplay;
if (!HaveSameSubmodule)
{
this.track.trackPathSubmodule = 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 [] Path Setting Logic
2025-06-03 02:42:28 -04:00
public partial class TrackPathSubmodule
{
private void SetUpSplineComputer(Track.TrackSpaceType trackSpaceType, Track.TrackSamplingType trackSamplingType)
{
path.type = (Spline.Type)trackSpaceType;
path.sampleMode = (SplineComputer.SampleMode)(int)trackSamplingType;
path.space = SplineComputer.Space.Local;
}
public void ClosePath()
{
if (isClosed)
{
path.Close();
}
else
{
path.Break();
}
}
public void SetTrackSpaceType(int spaceType)
{
int SpaceType = spaceType;
if (spaceType == 2) SpaceType++;
trackSpaceType = (Track.TrackSpaceType)SpaceType;
path.type = (Spline.Type)SpaceType;
}
public void SetPathNode(PathNode point)
{
path.SetPoint(point.index, point.node, SplineComputer.Space.Local);
}
public override void Refresh()
{
2026-01-21 00:31:23 -05:00
if(refreshedThisFrame) return;
refreshedThisFrame = true;
2025-06-03 02:42:28 -04:00
SetTrackSpaceType((int)trackSpaceType);
SetUpSplineComputer(trackSpaceType, trackSamplingType);
foreach (var pathNode in pathNodeList)
{
SetPathNode(pathNode);
}
ClosePath();
2026-01-21 00:31:23 -05:00
path.RebuildImmediate(true, true);
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
}