78 lines
2.1 KiB
C#
78 lines
2.1 KiB
C#
|
|
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>();
|
||
|
|
}
|
||
|
|
|
||
|
|
private List<IEnumerator> AssetBundleLoadings = new();
|
||
|
|
private List<string> AssetBundles = new();
|
||
|
|
private List<GameObject> Prefabs = 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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 加载预制体作为子物体
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="ab"></param>
|
||
|
|
/// <param name="prefab"></param>
|
||
|
|
[ScriptableCall(@"
|
||
|
|
<summary>
|
||
|
|
加载预制体作为子物体
|
||
|
|
</summary>
|
||
|
|
<param name=""ab""></param>
|
||
|
|
<param name=""prefab""></param>
|
||
|
|
")]
|
||
|
|
public void Load(string ab, string prefab)
|
||
|
|
{
|
||
|
|
AssetBundleLoadings.Add(this.LoadAssetBundle(ab, x =>
|
||
|
|
{
|
||
|
|
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);
|
||
|
|
}));
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void OnBegin()
|
||
|
|
{
|
||
|
|
foreach (var child in Prefabs)
|
||
|
|
{
|
||
|
|
child.SetActive(true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void OnEnd()
|
||
|
|
{
|
||
|
|
foreach (var child in Prefabs)
|
||
|
|
{
|
||
|
|
child.SetActive(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|