Files
ichni_Creator_Studio/Assets/Scripts/Base/GeneralSubmodules/EffectSubmodule.cs
SoulliesOfficial 7ab738cb68 架构重新设计
基本重做了所有物体和次级模块代码
2025-02-08 02:31:39 -05:00

221 lines
6.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
namespace Ichni.RhythmGame
{
public partial class EffectSubmodule : SubmoduleBase
{
public Dictionary<string, List<EffectBase>> effectCollection;
public EffectSubmodule(GameElement attachedGameElement, EffectSubmodulePreset preset = EffectSubmodulePreset.Default)
: base(attachedGameElement)
{
effectCollection = new Dictionary<string, List<EffectBase>>();
if (preset == EffectSubmodulePreset.Default)
{
effectCollection.Add("Default", new List<EffectBase>());
}
else if (preset == EffectSubmodulePreset.Note)
{
effectCollection.Add("Generate", new List<EffectBase>());
effectCollection.Add("GeneralJudge", new List<EffectBase>());
effectCollection.Add("Perfect", new List<EffectBase>());
effectCollection.Add("Good", new List<EffectBase>());
effectCollection.Add("Bad", new List<EffectBase>());
effectCollection.Add("Miss", new List<EffectBase>());
}
}
public EffectSubmodule(GameElement attachedGameElement, Dictionary<string, List<EffectBase_BM>> effectList_BM) : base(attachedGameElement)
{
effectCollection = new Dictionary<string, List<EffectBase>>();
foreach (var effect in effectList_BM)
{
List<EffectBase> effectList = new List<EffectBase>();
foreach (var effectBM in effect.Value)
{
effectList.Add(effectBM.ConvertToGameType());
}
effectCollection.Add(effect.Key, effectList);
}
}
public override void SaveBM()
{
matchedBM = new EffectSubmodule_BM(attachedGameElement);
}
}
public partial class EffectSubmodule
{
public enum EffectSubmodulePreset
{
Default,
Note,
}
}
public interface IHaveEffectSubmodule
{
public EffectSubmodule effectSubmodule { get; set; }
}
namespace Beatmap
{
public class EffectSubmodule_BM : Submodule_BM
{
public Dictionary<string, List<EffectBase_BM>> effectCollection;
public EffectSubmodule_BM()
{
}
public EffectSubmodule_BM(GameElement attachedElement) : base(attachedElement)
{
effectCollection = new Dictionary<string, List<EffectBase_BM>>();
IHaveEffectSubmodule element = attachedElement as IHaveEffectSubmodule;
foreach (var effect in element.effectSubmodule.effectCollection)
{
List<EffectBase_BM> effectList = new List<EffectBase_BM>();
foreach (var effectBase in effect.Value)
{
effectList.Add(effectBase.ConvertToBM());
}
effectCollection.Add(effect.Key, effectList);
}
}
public override void ExecuteBM()
{
attachedElement = GameElement_BM.GetElement(attachedElementGuid);
(attachedElement as IHaveEffectSubmodule).effectSubmodule = new EffectSubmodule(attachedElement);
}
public override void DuplicateBM(GameElement attached)
{
(attached as IHaveEffectSubmodule).effectSubmodule = new EffectSubmodule(attached);
}
}
}
public abstract class EffectBase
{
public enum EffectState
{
Before = -1,
Middle = 0,
After = 1,
Error = 100
}
/// <summary>
/// 效果的持续时间如果为0则表示瞬间效果
/// </summary>
public float effectTime;
/// <summary>
/// 是否是瞬间效果
/// </summary>
public bool isInstantEffect => effectTime <= 0;
/// <summary>
/// 效果当前的状态
/// </summary>
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();
}
/// <summary>
/// 在效果的持续时间内,触发这个方法
/// </summary>
public virtual void Execute()
{
}
/// <summary>
/// 如果是非瞬间效果,在效果完成后,触发这个方法;
/// 如果是瞬间效果则此方法即为Execute。原有的Execute方法不被调用。
/// </summary>
public virtual void Adjust()
{
}
/// <summary>
/// 如果时间轴回退到效果的触发时间之前,则触发这个方法
/// </summary>
public virtual void Recover()
{
}
/// <summary>
/// 转换为存档类
/// </summary>
/// <returns></returns>
public abstract EffectBase_BM ConvertToBM();
}
namespace Beatmap
{
public abstract class EffectBase_BM
{
public float effectTime;
public EffectBase_BM()
{
}
public EffectBase_BM(float effectTime)
{
this.effectTime = effectTime;
}
public abstract EffectBase ConvertToGameType();
}
}
}