using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Ichni.RhythmGame { public class EffectSubmodule : SubmoduleBase { public List effectList; public EffectSubmodule(BaseElement attachedElement) : base(attachedElement) { effectList = new List(); } public override void SaveBM() { matchedBM = new Beatmap.EffectSubmodule_BM(attachedElement); } } public interface IHaveEffect { public EffectSubmodule effectSubmodule { get; set; } } namespace Beatmap { public class EffectSubmodule_BM : Submodule_BM { public List effectList; public EffectSubmodule_BM() { } public EffectSubmodule_BM(BaseElement attachedElement) : base(attachedElement) { effectList = new List(); } public override void ExecuteBM() { attachedElement = GetElement(attachedElementGuid); (attachedElement as IHaveEffect).effectSubmodule = new EffectSubmodule(attachedElement); } public override void DuplicateBM(BaseElement attached) { (attached as IHaveEffect).effectSubmodule = new EffectSubmodule(attached); } } } public abstract class EffectBase { public enum EffectState { Before = -1, Middle = 0, After = 1, Error = 100 } /// /// 效果的持续时间,如果为0则表示瞬间效果 /// public float effectTime; /// /// 是否是瞬间效果 /// public bool isInstantEffect => effectTime <= 0; /// /// 效果当前的状态 /// public EffectState nowEffectState; protected EffectBase() { this.effectTime = 0; this.nowEffectState = EffectState.Before; } protected EffectBase(float effectTime) { this.effectTime = effectTime; this.nowEffectState = EffectState.Before; } public virtual void UpdateEffect() { EffectState state = CheckEffectState(); if (state == EffectState.Before && nowEffectState != EffectState.Before) { nowEffectState = EffectState.Before; Recover(); } else if (state == EffectState.Middle) { nowEffectState = EffectState.Middle; Execute(); } else if (state == EffectState.After && nowEffectState != EffectState.After) { nowEffectState = EffectState.After; Adjust(); } } public virtual EffectState CheckEffectState() { throw new System.NotImplementedException(); } /// /// 在效果的持续时间内,触发这个方法 /// public virtual void Execute() { } /// /// 如果是非瞬间效果,在效果完成后,触发这个方法; /// 如果是瞬间效果,则此方法即为Execute。原有的Execute方法不被调用。 /// public virtual void Adjust() { } /// /// 如果时间轴回退到效果的触发时间之前,则触发这个方法 /// public virtual void Recover() { } } }