214 lines
7.1 KiB
C#
214 lines
7.1 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Dreamteck.Splines;
|
||
using Ichni.RhythmGame.Beatmap;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
|
||
namespace Ichni.RhythmGame
|
||
{
|
||
public partial class Hold : NoteBase
|
||
{
|
||
public float holdEndTime;
|
||
public float holdingTime;
|
||
public bool isHolding;
|
||
public bool isFinalJudged;
|
||
|
||
public static Hold GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated,
|
||
GameElement parentElement, float exactJudgeTime, float holdEndTime)
|
||
{
|
||
Hold hold = Instantiate(GameManager.instance.basePrefabs.holdNote, parentElement.transform).GetComponent<Hold>();
|
||
|
||
hold.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
|
||
hold.exactJudgeTime = exactJudgeTime;
|
||
hold.holdEndTime = holdEndTime;
|
||
hold.holdingTime = 0;
|
||
|
||
if (parentElement.TryGetComponent(out Track track))
|
||
{
|
||
if (track.trackTimeSubmodule != null)
|
||
{
|
||
hold.track = track;
|
||
hold.trackPositioner = hold.AddComponent<SplinePositioner>();
|
||
hold.trackPositioner.spline = track.trackPathSubmodule.path;
|
||
hold.trackPositioner.updateMethod = SplineUser.UpdateMethod.LateUpdate;
|
||
hold.isOnTrack = true;
|
||
hold.UpdateNoteInTrack();
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("如果Note要生成在Track上,Track必须有TrackTimeSubmodule组件。");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
hold.track = null;
|
||
hold.isOnTrack = false;
|
||
}
|
||
|
||
return hold;
|
||
}
|
||
}
|
||
|
||
public partial class Hold
|
||
{
|
||
public override void UpdateNoteInMovableTrack()
|
||
{
|
||
if (!isHolding && !isFinalJudged)
|
||
{
|
||
base.UpdateNoteInMovableTrack();
|
||
}
|
||
|
||
if (noteVisual is NoteVisualBaseHold noteVisualHold)
|
||
{
|
||
noteVisualHold.UpdateHoldInMovableTrack();
|
||
}
|
||
}
|
||
|
||
public override void UpdateNoteInStaticTrack()
|
||
{
|
||
base.UpdateNoteInStaticTrack();
|
||
if (noteVisual is NoteVisualBaseHold noteVisualHold)
|
||
{
|
||
noteVisualHold.UpdateHoldInStaticTrack();
|
||
}
|
||
}
|
||
}
|
||
|
||
public partial class Hold
|
||
{
|
||
public override void SetDefaultSubmodules()
|
||
{
|
||
base.SetDefaultSubmodules();
|
||
noteAudioSubmodule = new NoteAudioSubmodule(this, "DefaultTap");
|
||
}
|
||
|
||
public override void SaveBM()
|
||
{
|
||
matchedBM = new Hold_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM, exactJudgeTime, holdEndTime);
|
||
}
|
||
}
|
||
|
||
public partial class Hold
|
||
{
|
||
protected override void Update()
|
||
{
|
||
float songTime = GameManager.instance.songTime;
|
||
|
||
if (isFirstJudged && songTime < exactJudgeTime)
|
||
{
|
||
isFirstJudged = false;
|
||
isHolding = false;
|
||
isFinalJudged = false;
|
||
holdingTime = 0;
|
||
}
|
||
|
||
if (isHolding)
|
||
{
|
||
holdingTime = songTime - exactJudgeTime;
|
||
}
|
||
|
||
/*
|
||
if (isHolding && songTime > holdEndTime)
|
||
{
|
||
isHolding = false;
|
||
isFinalJudged = true;
|
||
noteAudioSubmodule.PlayNoteJudgeAudios(EditorManager.instance.currentJudgeType);
|
||
}
|
||
|
||
if (!isFirstJudged && songTime >= exactJudgeTime)
|
||
{
|
||
if (!isFirstJudged)
|
||
{
|
||
isFirstJudged = true;
|
||
}
|
||
|
||
if (isFirstJudged && !isHolding && songTime < holdEndTime)
|
||
{
|
||
isHolding = true;
|
||
}
|
||
}
|
||
|
||
if (noteJudgeSubmodule != null && !EditorManager.instance.cameraManager.isSceneCameraActive)
|
||
{
|
||
foreach (NoteJudgeUnit unit in noteJudgeSubmodule.judgeUnitList.Where(unit => unit.isShowingJudge))
|
||
{
|
||
unit.UpdateJudge();
|
||
}
|
||
}
|
||
*/
|
||
|
||
noteScreenPosition = GameManager.instance.cameraManager.gameCamera.gameCamera.WorldToScreenPoint(noteVisual.transform.position);
|
||
|
||
/*
|
||
if (noteVisual != null)
|
||
{
|
||
noteVisual.effectSubmodule.effectCollection["Generate"].ForEach(e => e.UpdateEffect(exactJudgeTime));
|
||
noteVisual.effectSubmodule.effectCollection["GeneralJudge"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||
noteVisual.effectSubmodule.effectCollection["Holding"].ForEach(e => e.UpdateEffect(exactJudgeTime));
|
||
|
||
switch (EditorManager.instance.currentJudgeType)
|
||
{
|
||
case NoteJudgeType.Perfect:
|
||
noteVisual.effectSubmodule.effectCollection["Perfect"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||
break;
|
||
case NoteJudgeType.Good:
|
||
noteVisual.effectSubmodule.effectCollection["Good"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||
break;
|
||
case NoteJudgeType.Bad:
|
||
noteVisual.effectSubmodule.effectCollection["Bad"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||
break;
|
||
case NoteJudgeType.Miss:
|
||
noteVisual.effectSubmodule.effectCollection["Miss"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||
break;
|
||
}
|
||
|
||
if (EditorManager.instance.cameraManager.haveGameCamera)
|
||
{
|
||
|
||
}
|
||
}
|
||
*/
|
||
}
|
||
|
||
private void LateUpdate()
|
||
{
|
||
if (isOnTrack)
|
||
{
|
||
UpdateNoteInTrack();
|
||
}
|
||
}
|
||
}
|
||
|
||
namespace Beatmap
|
||
{
|
||
public class Hold_BM : NoteBase_BM
|
||
{
|
||
public float holdEndTime;
|
||
|
||
public Hold_BM()
|
||
{
|
||
|
||
}
|
||
|
||
public Hold_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement, float exactJudgeTime, float holdEndTime)
|
||
: base(elementName, elementGuid, tags, attachedElement, exactJudgeTime)
|
||
{
|
||
this.holdEndTime = holdEndTime;
|
||
}
|
||
|
||
public override void ExecuteBM()
|
||
{
|
||
matchedElement = Hold.GenerateElement(elementName, elementGuid, tags, false,
|
||
GetElement(attachedElementGuid), exactJudgeTime, holdEndTime);
|
||
}
|
||
|
||
public override GameElement DuplicateBM(GameElement parent)
|
||
{
|
||
return Hold.GenerateElement(elementName, Guid.NewGuid(), tags, false, parent, exactJudgeTime, holdEndTime);
|
||
}
|
||
}
|
||
}
|
||
} |