推动Config新增
This commit is contained in:
@@ -1,12 +1,47 @@
|
||||
using Convention;
|
||||
using Demo.Game.Attr;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
namespace ConfigType
|
||||
{
|
||||
public class ParticleEffectConfig : IEffectHookObjectConfig
|
||||
{
|
||||
public Dictionary<string, string[]> AssetBundles;
|
||||
public override void Deserialize(BinaryReader reader)
|
||||
{
|
||||
int count = BinarySerializeUtility.ReadInt(reader);
|
||||
while(count-->0)
|
||||
{
|
||||
var temp = BinarySerializeUtility.DeserializeStringArray(reader);
|
||||
var key = temp[0];
|
||||
var value = temp[1..];
|
||||
AssetBundles.Add(key, value);
|
||||
}
|
||||
base.Deserialize(reader);
|
||||
}
|
||||
|
||||
public override void Serialize(BinaryWriter writer)
|
||||
{
|
||||
BinarySerializeUtility.WriteInt(writer, AssetBundles.Count);
|
||||
foreach (var (key, value) in AssetBundles)
|
||||
{
|
||||
string[] temp = new string[value.Length + 1];
|
||||
temp[0] = key;
|
||||
Array.Copy(value, 0, temp, 1, value.Length);
|
||||
BinarySerializeUtility.SerializeArray(writer, value.ToArray());
|
||||
}
|
||||
base.Serialize(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Scriptable]
|
||||
public class ParticleEffect : IEffectHookObject, IAssetBundleLoader
|
||||
{
|
||||
@@ -15,15 +50,14 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<ParticleEffect>();
|
||||
}
|
||||
|
||||
private Dictionary<string,bool> AssetBundleLoaders = new();
|
||||
private readonly List<string> AssetBundles = new();
|
||||
private int AssetBundleLoadingCounter = 0;
|
||||
private readonly Dictionary<string,List<string>> AssetBundles = new();
|
||||
private readonly List<GameObject> Prefabs = new();
|
||||
|
||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||
{
|
||||
yield return base.DoSomethingDuringApplyScript();
|
||||
while (AssetBundleLoaders.Any(x => x.Value == false))
|
||||
yield return null;
|
||||
yield return new WaitUntil(() => AssetBundleLoadingCounter == 0);
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
@@ -31,7 +65,7 @@ namespace Demo.Game
|
||||
yield return base.UnloadScript();
|
||||
foreach (var ab in AssetBundles)
|
||||
{
|
||||
yield return this.UnloadAssetBundle(ab);
|
||||
yield return this.UnloadAssetBundle(ab.Key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +77,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void Load(string ab, string prefab)
|
||||
{
|
||||
AssetBundleLoaders.TryAdd(ab, false);
|
||||
AssetBundleLoadingCounter++;
|
||||
ConventionUtility.StartCoroutine(this.LoadAssetBundle(ab, x =>
|
||||
{
|
||||
GameObject sub = Instantiate(x.LoadAsset<GameObject>(prefab));
|
||||
@@ -51,8 +85,10 @@ namespace Demo.Game
|
||||
Prefabs.Add(sub);
|
||||
sub.transform.SetParent(transform);
|
||||
sub.transform.localPosition = Vector3.zero;
|
||||
AssetBundles.Add(ab);
|
||||
AssetBundleLoaders[ab] = true;
|
||||
if(AssetBundles.ContainsKey(ab)==false)
|
||||
AssetBundles.Add(ab, new());
|
||||
AssetBundles[ab].Add(prefab);
|
||||
AssetBundleLoadingCounter--;
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user