using System; using System.Collections; using System.Collections.Generic; using Dreamteck.Splines; using Ichni.RhythmGame.Beatmap; using UniRx; using UnityEngine; namespace Ichni.RhythmGame { public partial class CrossTrackPoint : GameElement, IHaveTimeDurationSubmodule { public ElementFolder trackListFolder; public Track nowAttachedTrack; private int nowAttachedTrackIndex; public SplinePositioner trackPositioner; public FlexibleInt trackSwitch; public FlexibleFloat trackPercent; public TimeDurationSubmodule timeDurationSubmodule { get; set; } public static CrossTrackPoint GenerateElement(string elementName, Guid id, List tags, bool isFirstGenerated, ElementFolder elementFolder, FlexibleInt trackSwitch, FlexibleFloat trackPercent) { CrossTrackPoint point = Instantiate(GameManager.instance.basePrefabs.emptyObject, elementFolder.transform).AddComponent(); point.Initialize(elementName, id, tags, isFirstGenerated, elementFolder); point.trackPositioner = point.gameObject.AddComponent(); point.nowAttachedTrackIndex = -1; point.trackListFolder = elementFolder; point.trackSwitch = trackSwitch; point.trackPercent = trackPercent; point.trackPositioner.motion.applyRotation = false; return point; } public override void SetDefaultSubmodules() { timeDurationSubmodule = new TimeDurationSubmodule(this); } private void Update() { if (trackPercent.animations.Count > 0) { trackSwitch.UpdateFlexibleInt(GameManager.instance.songTime); trackPercent.UpdateFlexibleFloat(GameManager.instance.songTime); SetPoint(); } } 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); trackPositioner.RebuildImmediate(); /*Debug.Log(trackSwitch.value + " " + trackPercent.value + " " + nowAttachedTrack.trackPathSubmodule.path.EvaluatePosition(trackPercent.value) + " " + transform.position + " " + transform.eulerAngles);*/ } } public partial class CrossTrackPoint { public override void SaveBM() { matchedBM = new CrossTrackPoint_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM, trackSwitch, trackPercent); } } namespace Beatmap { public class CrossTrackPoint_BM : GameElement_BM { public FlexibleInt trackSwitch; public FlexibleFloat trackPercent; public CrossTrackPoint_BM() { } public CrossTrackPoint_BM(string elementName, Guid elementGuid, List tags, GameElement_BM attachedElement, FlexibleInt trackSwitch, FlexibleFloat trackPercent) : base(elementName, elementGuid, tags, attachedElement) { this.trackSwitch = trackSwitch; this.trackPercent = trackPercent; } public override void ExecuteBM() { matchedElement = CrossTrackPoint.GenerateElement(elementName, elementGuid, tags, false, GetElement(attachedElementGuid) as ElementFolder, trackSwitch, trackPercent); } } } }