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

117 lines
3.7 KiB
C#
Raw Normal View History

2025-06-03 02:42:28 -04:00
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame.Beatmap;
2026-03-14 03:13:10 -04:00
using Lean.Pool;
2026-02-27 08:21:00 -05:00
using Sirenix.OdinInspector;
2025-07-21 05:42:20 -04:00
using UniRx;
2026-03-14 03:13:10 -04:00
using UnityEngine;
using UnityEngine.Serialization;
2025-06-03 02:42:28 -04:00
namespace Ichni.RhythmGame
{
public partial class Track : GameElement, IHaveTransformSubmodule, IHaveTimeDurationSubmodule
{
2026-03-14 03:13:10 -04:00
#region [] Essential Configs
public GameObject trackRenderer;
#endregion
#region [] Submodules
2025-06-03 02:42:28 -04:00
public TransformSubmodule transformSubmodule { get; set; }
public TimeDurationSubmodule timeDurationSubmodule { get; set; }
public TrackPathSubmodule trackPathSubmodule { get; set; }
public TrackTimeSubmodule trackTimeSubmodule { get; set; }
public TrackRendererSubmodule trackRendererSubmodule { 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 Track GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated, GameElement parentElement)
{
2026-03-14 03:13:10 -04:00
Track track = LeanPool.Spawn(GameManager.Instance.basePrefabs.track, parentElement.transform).GetComponent<Track>();
2025-06-03 02:42:28 -04:00
track.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
if (parentElement is ElementFolder folder)
{
folder.trackList.Add(track);
}
return track;
}
2026-03-14 03:13:10 -04:00
2025-06-03 02:42:28 -04:00
public override void SetDefaultSubmodules()
{
transformSubmodule = new TransformSubmodule(this);
timeDurationSubmodule = new TimeDurationSubmodule(this);
trackPathSubmodule = new TrackPathSubmodule(this, TrackSpaceType.CatmullRom, TrackSamplingType.TimeDistributed, false, false);
trackTimeSubmodule = null;
trackRendererSubmodule = null;
}
2026-02-27 08:21:00 -05:00
2025-06-03 02:42:28 -04:00
public override void AfterInitialize()
{
base.AfterInitialize();
2026-02-27 08:21:00 -05:00
2026-03-14 03:13:10 -04:00
GameManager.Instance.trackManager.RegisterTrack(this);
2025-06-03 02:42:28 -04:00
if (trackPathSubmodule != null && trackPathSubmodule.pathNodeList.Count > 3)
{
trackPathSubmodule.ClosePath();
}
2026-01-21 00:31:23 -05:00
if(trackRendererSubmodule != null)
{
trackRendererSubmodule.meshGenerator.autoUpdate = false;
}
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
2026-03-14 03:13:10 -04:00
#region [] Main Update
public void ManualUpdate(float currentSongTime)
2026-02-27 08:21:00 -05:00
{
2026-03-14 03:13:10 -04:00
if (timeDurationSubmodule.CheckTimeInDuration(currentSongTime))
2026-02-27 08:21:00 -05:00
{
2026-03-14 03:13:10 -04:00
(trackTimeSubmodule as TrackTimeSubmoduleMovable)?.UpdateTrackPart(currentSongTime);
2026-02-27 08:21:00 -05:00
}
}
2026-03-14 03:13:10 -04:00
public void ManualLateUpdate()
{
if(trackPathSubmodule != null) trackPathSubmodule.refreshedThisFrame = false;
}
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Behavior Overrides
2025-06-03 02:42:28 -04:00
public override void Refresh()
{
base.Refresh();
trackPathSubmodule?.Refresh();
trackTimeSubmodule?.Refresh();
trackRendererSubmodule?.Refresh();
}
public override void OnDelete()
{
2026-03-14 03:13:10 -04:00
GameManager.Instance.trackManager.UnregisterTrack(this);
2025-06-03 02:42:28 -04:00
if (parentElement is ElementFolder folder) folder.trackList.Remove(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 [] Enums
2025-06-03 02:42:28 -04:00
public partial class Track
{
public enum TrackSpaceType
{
CatmullRom = 0,
BSpline = 1,
Linear = 3
}
public enum TrackSamplingType
{
TimeDistributed = 0,
DistanceDistributed = 1
}
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
}