using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Demo.Game { public class ParticleEffect : IEffectHookObject, IAssetBundleLoader { public static ParticleEffect Make() { return new GameObject().AddComponent(); } private readonly List AssetBundles = new(); private readonly List Prefabs = new(); public override IEnumerator UnloadScript() { yield return base.UnloadScript(); foreach (var ab in AssetBundles) { yield return this.UnloadAssetBundle(ab); } } /// /// 加载预制体作为子物体 /// /// /// [ScriptableCall(@" 加载预制体作为子物体 ")] public IEnumerator Load(string ab, string prefab) { yield return 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); }); } 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); } } } }