同步
This commit is contained in:
@@ -8,12 +8,18 @@ using UnityEngine;
|
||||
|
||||
namespace Ichni.RhythmGame
|
||||
{
|
||||
public partial class TimeEffectsCollection : GameElement, IHaveTransformSubmodule, IHaveEffectSubmodule
|
||||
public partial class TimeEffectsCollection : GameElement, IHaveTransformSubmodule, IHaveEffectSubmodule, IScheduledElement
|
||||
{
|
||||
#region [暴露属性字段] Essential Configs
|
||||
public float time; //触发效果的时间
|
||||
#endregion
|
||||
|
||||
#region [运行时缓存] Cached Effect Lists
|
||||
private List<EffectBase> _priorEffects;
|
||||
private List<EffectBase> _defaultEffects;
|
||||
private List<EffectBase> _lateEffects;
|
||||
#endregion
|
||||
|
||||
#region [子模块接口] Submodules
|
||||
public TransformSubmodule transformSubmodule { get; set; }
|
||||
public EffectSubmodule effectSubmodule { get; set; }
|
||||
@@ -34,31 +40,55 @@ namespace Ichni.RhythmGame
|
||||
transformSubmodule = new TransformSubmodule(this);
|
||||
effectSubmodule = new EffectSubmodule(this);
|
||||
}
|
||||
|
||||
public override void AfterInitialize()
|
||||
{
|
||||
base.AfterInitialize();
|
||||
CacheEffectLists();
|
||||
CoreServices.UpdateScheduler.Register(UpdatePhase.Effect, this);
|
||||
}
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
base.OnDelete();
|
||||
CoreServices.UpdateScheduler.Unregister(UpdatePhase.Effect, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缓存 effectCollection 中的 Prior/Default/Late 列表引用,
|
||||
/// 避免 ScheduledUpdate 中每帧执行 Dictionary string key 查找。
|
||||
/// </summary>
|
||||
private void CacheEffectLists()
|
||||
{
|
||||
if (effectSubmodule?.effectCollection == null) return;
|
||||
effectSubmodule.effectCollection.TryGetValue("Prior", out _priorEffects);
|
||||
effectSubmodule.effectCollection.TryGetValue("Default", out _defaultEffects);
|
||||
effectSubmodule.effectCollection.TryGetValue("Late", out _lateEffects);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region [轮询更新] Main Update
|
||||
private void Update()
|
||||
#region [IScheduledElement] Scheduler Interface
|
||||
public void ScheduledUpdate(UpdatePhase phase, float songTime)
|
||||
{
|
||||
if (!GameManager.Instance.songPlayer.isUpdating || effectSubmodule == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (effectSubmodule == null) return;
|
||||
|
||||
foreach (EffectBase effect in effectSubmodule.effectCollection["Prior"])
|
||||
{
|
||||
effect.UpdateEffect(time);
|
||||
}
|
||||
UpdateEffectList(_priorEffects, time);
|
||||
UpdateEffectList(_defaultEffects, time);
|
||||
UpdateEffectList(_lateEffects, time);
|
||||
}
|
||||
|
||||
foreach (EffectBase effect in effectSubmodule.effectCollection["Default"])
|
||||
private static void UpdateEffectList(List<EffectBase> effects, float effectTime)
|
||||
{
|
||||
if (effects == null) return;
|
||||
for (int i = 0; i < effects.Count; i++)
|
||||
{
|
||||
effect.UpdateEffect(time);
|
||||
}
|
||||
|
||||
foreach (EffectBase effect in effectSubmodule.effectCollection["Late"])
|
||||
{
|
||||
effect.UpdateEffect(time);
|
||||
effects[i].UpdateEffect(effectTime);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsScheduledActive => isActiveAndEnabled;
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user