Files
ichni_Official/Assets/Scripts/Game/GameElements/Track/TrackPoints/CrossTrackPoint.cs

92 lines
3.3 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;
2026-03-14 03:13:10 -04:00
using Lean.Pool;
2025-08-22 14:54:40 -04:00
using UniRx;
2025-08-11 14:04:06 -04:00
using UnityEngine;
2025-06-03 02:42:28 -04:00
namespace Ichni.RhythmGame
{
public partial class CrossTrackPoint : GameElement, IHaveTimeDurationSubmodule
{
2026-03-14 03:13:10 -04:00
#region [] Essential Configs
2025-06-03 02:42:28 -04:00
public ElementFolder trackListFolder;
2026-03-14 03:13:10 -04:00
public FlexibleInt trackSwitch;
public FlexibleFloat trackPercent;
#endregion
#region [] Calculated & Cached States
2025-06-03 02:42:28 -04:00
public Track nowAttachedTrack;
private int nowAttachedTrackIndex;
public SplinePositioner trackPositioner;
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 [] Submodules
2025-06-03 02:42:28 -04:00
public TimeDurationSubmodule timeDurationSubmodule { get; set; }
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 [] Lifecycle & Factory
2025-06-03 02:42:28 -04:00
public static CrossTrackPoint GenerateElement(string elementName, Guid id, List<string> tags,
bool isFirstGenerated, ElementFolder elementFolder, FlexibleInt trackSwitch, FlexibleFloat trackPercent)
{
2026-03-14 03:13:10 -04:00
CrossTrackPoint point =
LeanPool.Spawn(GameManager.Instance.basePrefabs.crossTrackPoint, elementFolder.transform).GetComponent<CrossTrackPoint>();
2025-06-03 02:42:28 -04:00
point.Initialize(elementName, id, tags, isFirstGenerated, elementFolder);
2026-03-14 03:13:10 -04:00
point.trackPositioner = point.gameObject.GetComponent<SplinePositioner>();
2025-06-03 02:42:28 -04:00
point.nowAttachedTrackIndex = -1;
point.trackListFolder = elementFolder;
point.trackSwitch = trackSwitch;
point.trackPercent = trackPercent;
2025-07-21 05:42:20 -04:00
point.trackPositioner.motion.applyRotation = false;
2025-06-03 02:42:28 -04:00
return point;
}
2026-03-14 03:13:10 -04:00
public override void AfterInitialize()
{
GameManager.Instance.trackManager.RegisterCrossPoint(this);
base.AfterInitialize();
}
2025-06-03 02:42:28 -04:00
public override void SetDefaultSubmodules()
{
timeDurationSubmodule = new TimeDurationSubmodule(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 [] Main Update
public void ManualUpdate(float currentSongTime)
2025-06-03 02:42:28 -04:00
{
if (trackPercent.animations.Count > 0)
{
2026-03-14 03:13:10 -04:00
trackSwitch.UpdateFlexibleInt(currentSongTime);
trackPercent.UpdateFlexibleFloat(currentSongTime);
2025-06-03 02:42:28 -04:00
SetPoint();
2026-03-14 03:13:10 -04:00
if(nowAttachedTrackIndex >= trackSwitch.animations.Count - 1 &&
trackPercent.returnType == FlexibleReturnType.After)
{
trackPositioner.SetPercent(1);
GameManager.Instance.trackManager.UnregisterCrossPoint(this);
}
2025-06-03 02:42:28 -04:00
}
}
2026-03-14 03:13:10 -04:00
2025-06-03 02:42:28 -04:00
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;
}
2026-03-14 03:13:10 -04:00
trackPositioner.SetPercent(trackPercent.value);
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
}
}