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(); } private List AssetBundleLoadings = new(); [Content, SerializeField] private Dictionary AssetBundles = new(); [Content, SerializeField] private Dictionary Prefabs = new(); [Content, SerializeField] private Dictionary Durations = new(); public override IEnumerator LoadScript(string script) { yield return base.LoadScript(script); foreach (var loading in AssetBundleLoadings) yield return loading; } public override IEnumerator UnloadScript() { yield return base.UnloadScript(); foreach (var ab in AssetBundles) yield return this.UnloadAssetBundle(ab.Value); } /// /// 加载预制体作为子物体 /// /// 判定等级对应会出现的粒子效果,若没有对应的则向更低的值寻找 /// /// /// 判定效果的持续时间 [ScriptableCall(@" 加载预制体作为子物体 判定等级对应会出现的粒子效果,若没有对应的则向更低的值寻找 判定效果的持续时间 ")] public void Load(string level, string ab, string prefab, string duration) { int levelId = int.Parse(level); IEnumerator Foo() { AssetBundle assetBundle = null; var ir = this.LoadAssetBundle(ab, x => assetBundle = x); yield return ir; var req = assetBundle.LoadAssetAsync(prefab); yield return req; GameObject sub = Instantiate(req.asset as GameObject); sub.SetActive(false); Prefabs.Add(levelId, sub); sub.transform.SetParent(transform); AssetBundles.Add(levelId, ab); Durations.Add(levelId, float.Parse(duration)); } AssetBundleLoadings.Add(Foo()); } private void CreateParticle(GameObject prefab) { prefab.SetActive(true); } private void DestroyParticle(GameObject prefab) { prefab.SetActive(false); } public override void OnJudgement(int level) { for (int i = level; i >= 0; i--) { if (Prefabs.TryGetValue(i, out var effect)) { ConventionUtility.CreateSteps() .Next(() => CreateParticle(effect)) .Wait(Durations[i], () => DestroyParticle(effect)) .Invoke(); } } } } }