2025-12-12 15:19:10 +08:00
|
|
|
using Convention;
|
|
|
|
|
using Demo.Attr;
|
2025-09-25 19:04:05 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2025-11-30 17:33:26 +08:00
|
|
|
using System.Linq;
|
2025-09-25 19:04:05 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Demo.Game
|
|
|
|
|
{
|
2025-12-12 15:19:10 +08:00
|
|
|
[Scriptable]
|
2025-09-25 19:04:05 +08:00
|
|
|
public class ParticleEffect : IEffectHookObject, IAssetBundleLoader
|
|
|
|
|
{
|
|
|
|
|
public static ParticleEffect Make()
|
|
|
|
|
{
|
|
|
|
|
return new GameObject().AddComponent<ParticleEffect>();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-30 17:33:26 +08:00
|
|
|
private Dictionary<string,bool> AssetBundleLoaders = new();
|
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
|
|
|
|
2025-11-30 17:33:26 +08:00
|
|
|
protected override IEnumerator DoSomethingDuringApplyScript()
|
|
|
|
|
{
|
|
|
|
|
yield return base.DoSomethingDuringApplyScript();
|
|
|
|
|
while (AssetBundleLoaders.Any(x => x.Value == false))
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
|
|
|
|
|
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-11-30 17:33:26 +08:00
|
|
|
public void Load(string ab, string prefab)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-11-30 17:33:26 +08:00
|
|
|
AssetBundleLoaders.TryAdd(ab, false);
|
|
|
|
|
ConventionUtility.StartCoroutine(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-11-30 17:33:26 +08:00
|
|
|
AssetBundleLoaders[ab] = true;
|
|
|
|
|
}));
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|