Files
SoulliesOfficial a1b831ecbf 更新
2026-03-19 14:14:28 -04:00

92 lines
3.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Dreamteck.Splines;
using Ichni.RhythmGame.Beatmap;
using Lean.Pool;
using UniRx;
using UnityEngine;
namespace Ichni.RhythmGame
{
public partial class CrossTrackPoint : GameElement, IHaveTimeDurationSubmodule
{
#region [] Essential Configs
public ElementFolder trackListFolder;
public FlexibleInt trackSwitch;
public FlexibleFloat trackPercent;
#endregion
#region [] Calculated & Cached States
public Track nowAttachedTrack;
private int nowAttachedTrackIndex;
public SplinePositioner trackPositioner;
#endregion
#region [] Submodules
public TimeDurationSubmodule timeDurationSubmodule { get; set; }
#endregion
#region [] Lifecycle & Factory
public static CrossTrackPoint GenerateElement(string elementName, Guid id, List<string> tags,
bool isFirstGenerated, ElementFolder elementFolder, FlexibleInt trackSwitch, FlexibleFloat trackPercent)
{
CrossTrackPoint point =
LeanPool.Spawn(GameManager.Instance.basePrefabs.crossTrackPoint, elementFolder.transform).GetComponent<CrossTrackPoint>();
point.Initialize(elementName, id, tags, isFirstGenerated, elementFolder);
point.trackPositioner = point.gameObject.GetComponent<SplinePositioner>();
point.nowAttachedTrackIndex = -1;
point.trackListFolder = elementFolder;
point.trackSwitch = trackSwitch;
point.trackPercent = trackPercent;
point.trackPositioner.motion.applyRotation = false;
return point;
}
public override void AfterInitialize()
{
GameManager.Instance.trackManager.RegisterCrossPoint(this);
base.AfterInitialize();
}
public override void SetDefaultSubmodules()
{
timeDurationSubmodule = new TimeDurationSubmodule(this);
}
#endregion
#region [] Main Update
public void ManualUpdate(float currentSongTime)
{
if (trackPercent.animations.Count > 0)
{
trackSwitch.UpdateFlexibleInt(currentSongTime);
trackPercent.UpdateFlexibleFloat(currentSongTime);
SetPoint();
if(nowAttachedTrackIndex >= trackSwitch.animations.Count - 1 &&
trackPercent.returnType == FlexibleReturnType.After)
{
trackPositioner.SetPercent(1);
GameManager.Instance.trackManager.UnregisterCrossPoint(this);
}
}
}
private void SetPoint()
{
if (nowAttachedTrackIndex != trackSwitch.value &&
trackSwitch.value >= 0 &&
trackSwitch.value < trackListFolder.trackList.Count)
{
nowAttachedTrack = trackListFolder.trackList[trackSwitch.value];
nowAttachedTrackIndex = trackSwitch.value;
trackPositioner.spline = trackListFolder.trackList[trackSwitch.value].trackPathSubmodule.path;
}
trackPositioner.SetPercent(trackPercent.value);
}
#endregion
}
}