using System.Collections; using System.Collections.Generic; using Convention; using UnityEngine; namespace Demo.Game { public class ParticleJudgement : IJudgementHookObject, IAssetBundleLoader { public static ParticleJudgement Make() { return new GameObject().AddComponent(); } [Content, SerializeField] private List TaskLoader = new(); [Content, SerializeField] private Dictionary AssetBundles = new(); [Content, SerializeField] private Dictionary Prefabs = new(); [Content, SerializeField] private Dictionary Durations = new(); protected override IEnumerator DoSomethingDuringApplyScript() { yield return base.DoSomethingDuringApplyScript(); foreach (var task in TaskLoader) yield return task; } public override IEnumerator UnloadScript() { yield return base.UnloadScript(); foreach (var ab in AssetBundles) yield return this.UnloadAssetBundle(ab.Value); } /// /// 加载预制体作为子物体 /// /// 设置的判定效果对应的等级 /// /// /// 判定效果会现形的持续时间 [Convention.RScript.Variable.Attr.Method] public void Load(IInteraction.JudgementLevel levelId, string ab, string prefab, float duration) { TaskLoader.Add(this.LoadAssetBundle(ab, assetBundle => { var obj = assetBundle.LoadAsset(prefab); GameObject sub = Instantiate(obj); sub.SetActive(false); Prefabs.Add(levelId, sub); sub.transform.SetParent(transform); AssetBundles.Add(levelId, ab); Durations.Add(levelId, duration); })); } private void CreateParticle(GameObject prefab) { prefab.SetActive(true); } private void DestroyParticle(GameObject prefab) { prefab.SetActive(false); } public override void OnJudgement(IInteraction.JudgementLevel level) { if (Prefabs.TryGetValue(level, out var effect)) { ConventionUtility.CreateSteps() .Next(() => CreateParticle(effect)) .Wait(Durations[level], () => DestroyParticle(effect)) .Invoke(); } } } }