92 lines
3.3 KiB
C#
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
|
|
}
|
|
|
|
} |