Files
ichni_Official/Assets/ThemeBundles/DepartureToMultiverse/Scripts/NoteVisual/DTMNoteVisualHold.cs

161 lines
5.9 KiB
C#
Raw Normal View History

2025-08-22 14:54:40 -04:00
using System;
2025-07-21 05:42:20 -04:00
using System.Collections.Generic;
using System.Linq;
using Dreamteck.Splines;
using Ichni.RhythmGame.Beatmap;
using Ichni.RhythmGame.ThemeBundles.DepartureToMultiverse.Beatmap;
using UniRx;
using UnityEngine;
namespace Ichni.RhythmGame.ThemeBundles.DepartureToMultiverse
{
public partial class DTMNoteVisualHold : DTMNoteVisual, INoteVisualHold, IHaveTransformSubmodule
{
public Hold hold { get; set; }
2025-08-11 14:04:06 -04:00
public override Vector3 noteVisualPosition => headPoint.transform.position;
2025-07-21 05:42:20 -04:00
public MeshGenerator meshGenerator;
public SplinePositioner headPoint, tailPoint;
2025-10-02 23:49:18 -04:00
public new static DTMNoteVisualHold GenerateElement(string elementName, Guid id, List<string> tags,
bool isFirstGenerated, string themeBundleName, string objectName, GameElement parentElement, bool isHighlighted)
2025-07-21 05:42:20 -04:00
{
2025-10-02 23:49:18 -04:00
DTMNoteVisualHold noteVisualHold = NoteVisualBase.GenerateElement(elementName, id, tags,
isFirstGenerated, themeBundleName, objectName, parentElement, isHighlighted).GetComponent<DTMNoteVisualHold>();
2025-07-21 05:42:20 -04:00
return noteVisualHold;
}
public override void FirstSetUpObject(bool isFirstGenerated)
{
NoteBase note = parentElement as NoteBase;
if(note == null) throw new System.Exception("NoteVisual只能生成在Note下。");
if(!note.isOnTrack) throw new System.Exception("这种HoldNoteVisual只能生成在Track上。");
this.note = note;
note.noteVisual = this;
this.hold = note as Hold;
this.headPoint = notePartList[0].GetComponent<SplinePositioner>();
this.meshGenerator = notePartList[1].GetComponent<MeshGenerator>();
this.tailPoint = notePartList[2].GetComponent<SplinePositioner>();
this.hold.trackPositioner.autoUpdate = false;
headPoint.spline = hold.track.trackPathSubmodule.path;
meshGenerator.spline = hold.track.trackPathSubmodule.path;
tailPoint.spline = hold.track.trackPathSubmodule.path;
}
public override void AfterInitialize()
{
base.AfterInitialize();
Recover();
}
public override void Recover()
{
foreach (GameObject part in notePartList)
{
Renderer rend = part.GetComponent<Renderer>();
if (rend != null)
{
2025-09-14 14:53:45 -04:00
rend.materials[0].SetFloat("_MainAlpha", 1f);
rend.materials[1].SetFloat("_MainAlpha", 1f);
note.track.trackPathSubmodule.path.RebuildImmediate();
2025-07-21 05:42:20 -04:00
}
}
foreach (EffectBase effect in effectSubmodule.effectCollection["Generate"])
{
effect.Recover();
}
}
}
public partial class DTMNoteVisualHold
{
public override void SaveBM()
{
2025-10-02 23:49:18 -04:00
matchedBM = new DTMNoteVisualHold_BM(elementName, elementGuid, tags,
themeBundleName, objectName,parentElement.matchedBM as GameElement_BM, isHighlighted);
2025-07-21 05:42:20 -04:00
}
private float startPercent, endPercent;
public void UpdateHoldInMovableTrack()
{
if (effectSubmodule.effectCollection["Generate"].Any(e => e.nowEffectState == EffectBase.EffectState.Middle))
{
return;
}
TrackTimeSubmoduleMovable trackTimeSubmoduleMovable = hold.track.trackTimeSubmodule as TrackTimeSubmoduleMovable;
startPercent = trackTimeSubmoduleMovable.GetTrackPercent(hold.exactJudgeTime + hold.holdingTime);
endPercent = trackTimeSubmoduleMovable.GetTrackPercent(hold.holdEndTime);
hold.trackPositioner.SetPercent(startPercent);
meshGenerator.SetClipRange(startPercent, endPercent);
headPoint.SetPercent(startPercent);
tailPoint.SetPercent(endPercent);
}
public void UpdateHoldInStaticTrack()
{
//throw new NotImplementedException();
}
2025-07-26 04:20:25 -04:00
public void UpdateTransform(bool refreshAll = true)
2025-07-21 05:42:20 -04:00
{
2025-07-26 04:20:25 -04:00
bool willRefresh = false;
2025-07-21 05:42:20 -04:00
2025-07-26 04:20:25 -04:00
if (transformSubmodule.positionDirtyMark)
{
transformSubmodule.currentPosition = transformSubmodule.originalPosition + transformSubmodule.positionOffset;
transformSubmodule.positionDirtyMark = false;
willRefresh = true;
transformSubmodule.positionOffset = Vector3.zero;
}
2025-07-21 05:42:20 -04:00
2025-07-26 04:20:25 -04:00
if (refreshAll && willRefresh)
{
Refresh();
}
2025-07-21 05:42:20 -04:00
}
public override void Refresh()
{
base.Refresh();
Vector2 posOffset = new Vector2(transformSubmodule.currentPosition.x, transformSubmodule.currentPosition.y);
hold.trackPositioner.motion.offset = posOffset;
meshGenerator.offset = posOffset;
headPoint.motion.offset = posOffset;
tailPoint.motion.offset = posOffset;
}
}
namespace Beatmap
{
2025-10-02 23:49:18 -04:00
public class DTMNoteVisualHold_BM : DTMNoteVisual_BM
2025-07-21 05:42:20 -04:00
{
public DTMNoteVisualHold_BM()
{
2025-10-02 23:49:18 -04:00
2025-07-21 05:42:20 -04:00
}
2025-10-02 23:49:18 -04:00
public DTMNoteVisualHold_BM(string elementName, Guid id, List<string> tags,
string themeBundleName, string objectName, GameElement_BM parent, bool isHighlighted) :
base(elementName, id, tags, parent, themeBundleName, objectName, isHighlighted)
2025-07-21 05:42:20 -04:00
{
2025-10-02 23:49:18 -04:00
2025-07-21 05:42:20 -04:00
}
public override void ExecuteBM()
{
matchedElement = DTMNoteVisualHold.GenerateElement(elementName, elementGuid, tags, false,
2025-10-02 23:49:18 -04:00
themeBundleName, objectName, GetElement(attachedElementGuid), isHighlighted);
2025-07-21 05:42:20 -04:00
}
}
}
}