2025-09-25 19:04:05 +08:00
|
|
|
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<ParticleEffect>();
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-06 16:09:52 +08:00
|
|
|
private readonly List<string> AssetBundles = new();
|
|
|
|
|
private readonly List<GameObject> Prefabs = new();
|
2025-09-25 19:04:05 +08:00
|
|
|
|
|
|
|
|
public override IEnumerator UnloadScript()
|
|
|
|
|
{
|
|
|
|
|
yield return base.UnloadScript();
|
|
|
|
|
foreach (var ab in AssetBundles)
|
|
|
|
|
{
|
|
|
|
|
yield return this.UnloadAssetBundle(ab);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载预制体作为子物体
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ab"></param>
|
|
|
|
|
/// <param name="prefab"></param>
|
2025-10-27 20:24:15 +08:00
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-10-06 16:09:52 +08:00
|
|
|
public IEnumerator Load(string ab, string prefab)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-10-06 16:09:52 +08:00
|
|
|
yield return this.LoadAssetBundle(ab, x =>
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
|
|
|
|
GameObject sub = Instantiate(x.LoadAsset<GameObject>(prefab));
|
|
|
|
|
sub.SetActive(false);
|
|
|
|
|
Prefabs.Add(sub);
|
|
|
|
|
sub.transform.SetParent(transform);
|
|
|
|
|
sub.transform.localPosition = Vector3.zero;
|
|
|
|
|
AssetBundles.Add(ab);
|
2025-10-06 16:09:52 +08:00
|
|
|
});
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-08 00:35:50 +08:00
|
|
|
public override void OnInit()
|
|
|
|
|
{
|
|
|
|
|
foreach (var child in Prefabs)
|
|
|
|
|
{
|
|
|
|
|
child.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-25 19:04:05 +08:00
|
|
|
public override void OnBegin()
|
|
|
|
|
{
|
|
|
|
|
foreach (var child in Prefabs)
|
|
|
|
|
{
|
|
|
|
|
child.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnEnd()
|
|
|
|
|
{
|
|
|
|
|
foreach (var child in Prefabs)
|
|
|
|
|
{
|
|
|
|
|
child.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|