@@ -14,7 +14,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
public partial class Hold : NoteBase
|
||||
{
|
||||
//public static List<Hold> holdingHoldList = new();
|
||||
public static List<Hold> holdingHoldList = new();
|
||||
|
||||
public float holdEndTime;
|
||||
public float holdingTime;
|
||||
@@ -65,6 +65,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
EditorManager.instance.projectManager.notePrefabManager.LoadNotePrefab(hold, GetNoteTypeName(hold) + "_Prefab");
|
||||
}
|
||||
|
||||
return hold;
|
||||
|
||||
}
|
||||
@@ -156,24 +157,17 @@ namespace Ichni.RhythmGame
|
||||
|
||||
public partial class Hold
|
||||
{
|
||||
// 添加类级别缓存
|
||||
private static HashSet<Hold> holdingHoldSet = new HashSet<Hold>(); // 替换List为HashSet
|
||||
public override void UpdateNote()
|
||||
protected override void Update()
|
||||
{
|
||||
if (Keyboard.current.hKey.wasPressedThisFrame)
|
||||
{
|
||||
// 优化:避免字典枚举和Lambda
|
||||
var effectCollection = noteVisual.effectSubmodule.effectCollection;
|
||||
foreach (var pair in effectCollection)
|
||||
foreach (KeyValuePair<string, List<EffectBase>> effect in noteVisual.effectSubmodule.effectCollection)
|
||||
{
|
||||
var effects = pair.Value;
|
||||
for (int i = 0; i < effects.Count; i++)
|
||||
{
|
||||
effects[i].Disrupt();
|
||||
}
|
||||
effect.Value.ForEach(x => x.Disrupt());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (holdEndTime < exactJudgeTime)
|
||||
{
|
||||
LogWindow.Log("Hold end time is earlier than exact judge time.", Color.red);
|
||||
@@ -198,6 +192,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
isHolding = false;
|
||||
isFinalJudged = true;
|
||||
//noteAudioSubmodule?.PlayNoteJudgeAudios(EditorManager.instance.currentJudgeType);//有待商榷
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,74 +206,56 @@ namespace Ichni.RhythmGame
|
||||
}
|
||||
}
|
||||
|
||||
// 优化:避免LINQ查询
|
||||
if (noteJudgeSubmodule != null && !EditorManager.instance.cameraManager.isSceneCameraActive)
|
||||
{
|
||||
var judgeUnits = noteJudgeSubmodule.judgeUnitList;
|
||||
for (int i = 0; i < judgeUnits.Count; i++)
|
||||
foreach (NoteJudgeUnit unit in noteJudgeSubmodule.judgeUnitList.Where(unit => unit.isShowingJudge))
|
||||
{
|
||||
var unit = judgeUnits[i];
|
||||
if (unit.isShowingJudge)
|
||||
{
|
||||
unit.UpdateJudge();
|
||||
}
|
||||
unit.UpdateJudge();
|
||||
}
|
||||
}
|
||||
|
||||
if (noteVisual != null)
|
||||
{
|
||||
// 优化:缓存常用引用,避免重复字典查找
|
||||
var effectSubmodule = noteVisual.effectSubmodule;
|
||||
var effectColl = effectSubmodule.effectCollection;
|
||||
noteVisual.effectSubmodule.effectCollection["Generate"].ForEach(e => e.UpdateEffect(exactJudgeTime));
|
||||
noteVisual.effectSubmodule.effectCollection["StartHold"].ForEach(e => e.UpdateEffect(exactJudgeTime));
|
||||
noteVisual.effectSubmodule.effectCollection["Holding"].ForEach(e => e.UpdateEffect(exactJudgeTime));
|
||||
|
||||
// 优化:手动遍历避免Lambda
|
||||
UpdateEffectList(effectColl["Generate"], exactJudgeTime);
|
||||
UpdateEffectList(effectColl["StartHold"], exactJudgeTime);
|
||||
UpdateEffectList(effectColl["Holding"], exactJudgeTime);
|
||||
UpdateEffectList(effectColl["GeneralJudge"], holdEndTime);
|
||||
UpdateEffectList(effectColl["AfterJudge"], holdEndTime);
|
||||
|
||||
// 优化switch语句
|
||||
var judgeType = EditorManager.instance.currentJudgeType;
|
||||
switch (judgeType)
|
||||
noteVisual.effectSubmodule.effectCollection["GeneralJudge"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||||
switch (EditorManager.instance.currentJudgeType)
|
||||
{
|
||||
case NoteJudgeType.Perfect:
|
||||
UpdateEffectList(effectColl["Perfect"], holdEndTime);
|
||||
noteVisual.effectSubmodule.effectCollection["Perfect"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||||
break;
|
||||
case NoteJudgeType.Good:
|
||||
UpdateEffectList(effectColl["Good"], holdEndTime);
|
||||
noteVisual.effectSubmodule.effectCollection["Good"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||||
break;
|
||||
case NoteJudgeType.Bad:
|
||||
UpdateEffectList(effectColl["Bad"], holdEndTime);
|
||||
noteVisual.effectSubmodule.effectCollection["Bad"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||||
break;
|
||||
case NoteJudgeType.Miss:
|
||||
UpdateEffectList(effectColl["Miss"], holdEndTime);
|
||||
noteVisual.effectSubmodule.effectCollection["Miss"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||||
break;
|
||||
}
|
||||
|
||||
noteVisual.effectSubmodule.effectCollection["AfterJudge"].ForEach(e => e.UpdateEffect(holdEndTime));
|
||||
|
||||
if (EditorManager.instance.cameraManager.haveGameCamera)
|
||||
{
|
||||
noteScreenPosition = EditorManager.instance.cameraManager.gameCamera.gameCamera.WorldToScreenPoint(noteVisual.noteVisualPosition);
|
||||
}
|
||||
}
|
||||
|
||||
// 优化:使用HashSet避免Contains的GC
|
||||
// 优化持有列表的添加和移除
|
||||
if (isHolding)
|
||||
{
|
||||
holdingHoldSet.Add(this);
|
||||
if (!holdingHoldList.Contains(this))
|
||||
holdingHoldList.Add(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
holdingHoldSet.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助方法:避免Lambda产生的GC
|
||||
private void UpdateEffectList(List<EffectBase> effects, float time)
|
||||
{
|
||||
for (int i = 0; i < effects.Count; i++)
|
||||
{
|
||||
effects[i].UpdateEffect(time);
|
||||
if (holdingHoldList.Contains(this))
|
||||
holdingHoldList.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Ichni.RhythmGame
|
||||
|
||||
[Title("NoteVisual")]
|
||||
public NoteVisualBase noteVisual;
|
||||
public float NoteAppearTime => noteVisual ? noteVisual.NoteAppearTime : -1;
|
||||
|
||||
[Title("Submodules")]
|
||||
public TimeDurationSubmodule timeDurationSubmodule { get; set; }
|
||||
@@ -34,22 +33,9 @@ namespace Ichni.RhythmGame
|
||||
[FormerlySerializedAs("isJudged")] public bool isFirstJudged;
|
||||
public override int HierarchyPriority => -10;
|
||||
|
||||
|
||||
public override void Initialize(string name, Guid elementGuid, List<string> tags, bool isFirstGenerated, GameElement parentElement)
|
||||
{
|
||||
base.Initialize(name, elementGuid, tags, isFirstGenerated, parentElement);
|
||||
NoteManager.instance.AddNote(this);
|
||||
|
||||
}
|
||||
public override void AfterInitialize()
|
||||
{
|
||||
base.AfterInitialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在MovableTrack上更新Note的位置,注意HoldNote需要重写这个方法
|
||||
/// </summary>
|
||||
|
||||
public virtual void UpdateNoteInMovableTrack()
|
||||
{
|
||||
TrackTimeSubmoduleMovable trackTimeSubmoduleMovable = track.trackTimeSubmodule as TrackTimeSubmoduleMovable;
|
||||
@@ -89,7 +75,7 @@ namespace Ichni.RhythmGame
|
||||
|
||||
foreach (SampleWindow i in SampleWindow.instances.Where(i => i.gameElement)) i.OnceSpawnNote();
|
||||
}
|
||||
public virtual void UpdateNote()
|
||||
protected virtual void Update()
|
||||
{
|
||||
var editor = EditorManager.instance;
|
||||
var cameraManager = editor.cameraManager;
|
||||
@@ -105,13 +91,13 @@ namespace Ichni.RhythmGame
|
||||
if (isFirstJudged && songTime < exactJudgeTime)
|
||||
{
|
||||
isFirstJudged = false;
|
||||
if (noteVisual != null) noteVisual.GetComponent<Collider>().enabled = !isFirstJudged;
|
||||
noteVisual.GetComponent<Collider>().enabled = !isFirstJudged;
|
||||
}
|
||||
else if (!isFirstJudged && songTime >= exactJudgeTime)
|
||||
{
|
||||
noteAudioSubmodule?.PlayNoteJudgeAudios(editor.currentJudgeType);
|
||||
isFirstJudged = true;
|
||||
if (noteVisual != null) noteVisual.GetComponent<Collider>().enabled = !isFirstJudged;
|
||||
noteVisual.GetComponent<Collider>().enabled = !isFirstJudged;
|
||||
}
|
||||
|
||||
// 判定单元更新
|
||||
@@ -249,11 +235,6 @@ namespace Ichni.RhythmGame
|
||||
foreach (SampleWindow i in SampleWindow.instances.Where(i => i.gameElement)) i.OnceSpawnNote();
|
||||
|
||||
}
|
||||
NoteManager.instance.RemoveNote(this);
|
||||
if (noteVisual != null)
|
||||
{
|
||||
noteVisual.OnDelete();
|
||||
}
|
||||
}
|
||||
|
||||
public int CompareTo(NoteBase other)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ichni.Editor;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
@@ -23,10 +21,7 @@ namespace Ichni.RhythmGame
|
||||
public List<GameObject> effectPrefabList;
|
||||
|
||||
public virtual Vector3 noteVisualPosition => noteMain.transform.position;
|
||||
|
||||
public NoteGenerateEffect generateEffect;
|
||||
public float NoteAppearTime => generateEffect is null ? note.exactJudgeTime : note.exactJudgeTime - generateEffect.generateTime;
|
||||
|
||||
|
||||
public EffectSubmodule effectSubmodule { get; set; }
|
||||
public SelectSubmodule selectSubmodule { get; set; }
|
||||
|
||||
@@ -39,19 +34,8 @@ namespace Ichni.RhythmGame
|
||||
noteVisual.isHighlighted = isHighlighted;
|
||||
noteVisual.SetHighlight();
|
||||
noteVisual.SetEditorSubmodules();
|
||||
Observable.NextFrame().Subscribe(_ =>
|
||||
{
|
||||
noteVisual.AfterInitialize();
|
||||
|
||||
});
|
||||
return noteVisual;
|
||||
}
|
||||
public override void AfterInitialize()
|
||||
{
|
||||
base.AfterInitialize();
|
||||
generateEffect ??= effectSubmodule.effectCollection["Generate"].First(i => i is NoteGenerateEffect) as NoteGenerateEffect;
|
||||
if (generateEffect == null) throw new Exception("NoteVisual必须有一个生成特效。");
|
||||
}
|
||||
|
||||
public override void SetDefaultSubmodules()
|
||||
{
|
||||
@@ -64,7 +48,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
selectSubmodule ??= new SelectSubmodule(this, note);
|
||||
}
|
||||
|
||||
|
||||
public override void SetUpInspector()
|
||||
{
|
||||
base.SetUpInspector();
|
||||
@@ -79,7 +63,7 @@ namespace Ichni.RhythmGame
|
||||
inspector.GenerateToggle(this, settingsSubcontainer, "Highlight", nameof(isHighlighted))
|
||||
.AddListenerFunction(SetHighlight);
|
||||
}
|
||||
|
||||
|
||||
public virtual void Recover()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user