Files
ichni_Official/Assets/Scripts/Game/GameElements/GeneralEffects/TimeEffectsCollection.cs

96 lines
3.4 KiB
C#
Raw Normal View History

2025-06-03 02:42:28 -04:00
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame.Beatmap;
using Sirenix.OdinInspector;
2025-07-21 05:42:20 -04:00
using UniRx;
2025-06-03 02:42:28 -04:00
using UnityEngine;
namespace Ichni.RhythmGame
{
2026-06-05 04:45:57 -04:00
public partial class TimeEffectsCollection : GameElement, IHaveTransformSubmodule, IHaveEffectSubmodule, IScheduledElement
2025-06-03 02:42:28 -04:00
{
2026-03-14 03:13:10 -04:00
#region [] Essential Configs
public float time; //触发效果的时间
#endregion
2026-06-05 04:45:57 -04:00
#region [] Cached Effect Lists
private List<EffectBase> _priorEffects;
private List<EffectBase> _defaultEffects;
private List<EffectBase> _lateEffects;
#endregion
2026-03-14 03:13:10 -04:00
#region [] Submodules
2025-07-10 08:42:30 -04:00
public TransformSubmodule transformSubmodule { get; set; }
2025-06-03 02:42:28 -04:00
public EffectSubmodule effectSubmodule { get; set; }
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Lifecycle & Factory
2025-06-03 02:42:28 -04:00
public static TimeEffectsCollection GenerateElement(string name, Guid guid, List<string> tags,
bool isFirstGenerated, GameElement parentElement, float time)
{
2026-03-14 03:13:10 -04:00
TimeEffectsCollection timeEffectsCollection = Instantiate(GameManager.Instance.basePrefabs.emptyObject).AddComponent<TimeEffectsCollection>();
2025-06-03 02:42:28 -04:00
timeEffectsCollection.Initialize(name, guid, tags, isFirstGenerated, parentElement);
timeEffectsCollection.time = time;
return timeEffectsCollection;
}
public override void SetDefaultSubmodules()
{
2025-07-10 08:42:30 -04:00
transformSubmodule = new TransformSubmodule(this);
2025-06-03 02:42:28 -04:00
effectSubmodule = new EffectSubmodule(this);
}
2026-06-05 04:45:57 -04:00
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);
}
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
2026-03-14 03:13:10 -04:00
#region [] Main Update
2026-06-05 04:45:57 -04:00
#region [IScheduledElement] Scheduler Interface
public void ScheduledUpdate(UpdatePhase phase, float songTime)
2025-06-03 02:42:28 -04:00
{
2026-06-05 04:45:57 -04:00
if (effectSubmodule == null) return;
2025-08-11 14:04:06 -04:00
2026-06-05 04:45:57 -04:00
UpdateEffectList(_priorEffects, time);
UpdateEffectList(_defaultEffects, time);
UpdateEffectList(_lateEffects, time);
}
2025-08-11 14:04:06 -04:00
2026-06-05 04:45:57 -04:00
private static void UpdateEffectList(List<EffectBase> effects, float effectTime)
{
if (effects == null) return;
for (int i = 0; i < effects.Count; i++)
2025-08-11 14:04:06 -04:00
{
2026-06-05 04:45:57 -04:00
effects[i].UpdateEffect(effectTime);
2025-08-11 14:04:06 -04:00
}
2025-06-03 02:42:28 -04:00
}
2026-06-05 04:45:57 -04:00
public bool IsScheduledActive => isActiveAndEnabled;
#endregion
2026-03-14 03:13:10 -04:00
#endregion
2025-06-03 02:42:28 -04:00
}
2026-03-31 07:51:40 -04:00
}