using Convention; using Demo.Attr; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Demo.Game { [Scriptable] public class ParticleEffect : IEffectHookObject, IAssetBundleLoader { public static ParticleEffect Make() { return new GameObject().AddComponent(); } private Dictionary AssetBundleLoaders = new(); private readonly List AssetBundles = new(); private readonly List Prefabs = new(); protected override IEnumerator DoSomethingDuringApplyScript() { yield return base.DoSomethingDuringApplyScript(); while (AssetBundleLoaders.Any(x => x.Value == false)) yield return null; } public override IEnumerator UnloadScript() { yield return base.UnloadScript(); foreach (var ab in AssetBundles) { yield return this.UnloadAssetBundle(ab); } } /// /// 加载预制体作为子物体 /// /// /// [Convention.RScript.Variable.Attr.Method] public void Load(string ab, string prefab) { AssetBundleLoaders.TryAdd(ab, false); ConventionUtility.StartCoroutine(this.LoadAssetBundle(ab, x => { GameObject sub = Instantiate(x.LoadAsset(prefab)); sub.SetActive(false); Prefabs.Add(sub); sub.transform.SetParent(transform); sub.transform.localPosition = Vector3.zero; AssetBundles.Add(ab); AssetBundleLoaders[ab] = true; })); } public override void OnInit() { foreach (var child in Prefabs) { child.SetActive(false); } } public override void OnBegin() { foreach (var child in Prefabs) { child.SetActive(true); } } public override void OnEnd() { foreach (var child in Prefabs) { child.SetActive(false); } } } }