83 lines
2.9 KiB
C#
83 lines
2.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Dreamteck.Splines;
|
|
using Ichni.RhythmGame.Beatmap;
|
|
using Lean.Pool;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace Ichni.RhythmGame
|
|
{
|
|
/// <summary>
|
|
/// 在轨道上根据百分比进行运动的点
|
|
/// </summary>
|
|
public partial class TrackPercentPoint : GameElement, IHaveTimeDurationSubmodule
|
|
{
|
|
#region [暴露属性字段] Essential Configs
|
|
public Track track;
|
|
public FlexibleFloat trackPercent;
|
|
#endregion
|
|
|
|
#region [计算与状态缓存] Calculated & Cached States
|
|
public SplinePositioner trackPositioner;
|
|
#endregion
|
|
|
|
#region [子模块接口] Submodules
|
|
public TimeDurationSubmodule timeDurationSubmodule { get; set; }
|
|
#endregion
|
|
|
|
#region [生命周期] Lifecycle & Factory
|
|
public static TrackPercentPoint GenerateElement(string elementName, Guid id, List<string> tags,
|
|
bool isFirstGenerated, Track track, FlexibleFloat trackPercent)
|
|
{
|
|
TrackPercentPoint point =
|
|
LeanPool.Spawn(GameManager.Instance.basePrefabs.trackPercentPoint, track.transform).GetComponent<TrackPercentPoint>();
|
|
|
|
point.Initialize(elementName, id, tags, isFirstGenerated, track);
|
|
point.track = track;
|
|
point.trackPositioner = point.gameObject.GetComponent<SplinePositioner>();
|
|
point.trackPositioner.spline = track.trackPathSubmodule.path;
|
|
point.trackPercent = trackPercent;
|
|
|
|
point.trackPositioner.motion.applyRotation = false;
|
|
return point;
|
|
}
|
|
|
|
public override void SetDefaultSubmodules()
|
|
{
|
|
timeDurationSubmodule = new TimeDurationSubmodule(this);
|
|
}
|
|
|
|
public override void AfterInitialize()
|
|
{
|
|
GameManager.Instance.trackManager.RegisterPercentPoint(this);
|
|
base.AfterInitialize();
|
|
}
|
|
#endregion
|
|
|
|
#region [轮询更新] Main Update
|
|
public void ManualUpdate(float currentSongTime)
|
|
{
|
|
if (trackPercent.animations.Count > 0)
|
|
{
|
|
trackPercent.UpdateFlexibleFloat(currentSongTime);
|
|
if (trackPercent.returnType == FlexibleReturnType.MiddleExecuting)
|
|
{
|
|
float finalValue = trackPercent.value;
|
|
if (finalValue > 1 && finalValue > Mathf.Floor(finalValue)) finalValue -= Mathf.Floor(finalValue);
|
|
trackPositioner.SetPercent(finalValue);
|
|
}
|
|
|
|
if (trackPercent.returnType == FlexibleReturnType.After)
|
|
{
|
|
trackPositioner.SetPercent(1);
|
|
GameManager.Instance.trackManager.UnregisterPercentPoint(this);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
} |