Files
ichni_Official/Assets/Scripts/Game/GameElements/Track/TrackSubmodules/TrackPathSubmodule.cs
SoulliesOfficial 1bc9af280b 同步
2026-04-03 10:53:11 -04:00

109 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using Ichni.RhythmGame.Beatmap;
namespace Ichni.RhythmGame
{
public partial class TrackPathSubmodule : TrackSubmodule
{
#region [] Essential Configs
public SplineComputer path;
public List<PathNode> pathNodeList;
public Track.TrackSpaceType trackSpaceType;
public Track.TrackSamplingType trackSamplingType;
public bool isClosed;
public bool isShowingDisplay;
#endregion
#region [] Calculated & Cached States
public bool refreshedThisFrame = false;
#endregion
#region [] Initialization
public TrackPathSubmodule(Track track, Track.TrackSpaceType trackSpaceType,
Track.TrackSamplingType trackSamplingType, bool isClosed, bool isShowingDisplay) : base(track)
{
this.path = track.GetComponent<SplineComputer>();
this.pathNodeList = new List<PathNode>();
this.trackSpaceType = trackSpaceType;
this.trackSamplingType = trackSamplingType;
this.isClosed = isClosed;
this.path.sampleRate = 8;
this.path.updateMode = SplineComputer.UpdateMode.LateUpdate;
SetUpSplineComputer(this.trackSpaceType, this.trackSamplingType);
//闭合路径在PathNode生成时执行在初始化的情况下PathNode数量为0不会执行闭合操作
this.isShowingDisplay = isShowingDisplay;
if (!HaveSameSubmodule)
{
this.track.trackPathSubmodule = this;
}
}
#endregion
}
#region [] Path Setting Logic
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 (pathNodeList.Count == 2)
{
path.type = Spline.Type.Linear;
path.sampleRate = 1;
}
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()
{
if(refreshedThisFrame) return;
refreshedThisFrame = true;
SetTrackSpaceType((int)trackSpaceType);
SetUpSplineComputer(trackSpaceType, trackSamplingType);
foreach (var pathNode in pathNodeList)
{
SetPathNode(pathNode);
}
ClosePath();
path.RebuildImmediate();
}
}
#endregion
}