diff --git a/Assets/Scripts/Environment/PrefabRootObject.cs b/Assets/Scripts/Environment/PrefabRootObject.cs index 369db10..62a1c5b 100644 --- a/Assets/Scripts/Environment/PrefabRootObject.cs +++ b/Assets/Scripts/Environment/PrefabRootObject.cs @@ -1,5 +1,6 @@ using Convention; using Demo.Game.Attr; +using Demo.Game.ConfigType; using System; using System.Collections; using System.Collections.Generic; @@ -13,7 +14,7 @@ namespace Demo.Game { public class PrefabRootObjectConfig : ScriptLoadableConfig { - public Dictionary LoadedGameObjectNames = new(); + public Dictionary> LoadedGameObjectNames = new(); public override void Deserialize(BinaryReader reader) { @@ -23,7 +24,7 @@ namespace Demo.Game var temp = BinarySerializeUtility.DeserializeStringArray(reader); var key = temp[0]; var value = temp[1..]; - LoadedGameObjectNames.Add(key, value); + LoadedGameObjectNames.Add(key, value.ToList()); } base.Deserialize(reader); } @@ -33,9 +34,12 @@ namespace Demo.Game BinarySerializeUtility.WriteInt(writer, LoadedGameObjectNames.Count); foreach (var (key,value) in LoadedGameObjectNames) { - string[] temp = new string[value.Length + 1]; + string[] temp = new string[value.Count + 1]; temp[0] = key; - Array.Copy(value, 0, temp, 1, value.Length); + for(int i=0,e=value.Count;i> LoadedGameObjectNames = new(); + private Dictionary> LoadedGameObjectNames => GetConfig().LoadedGameObjectNames; private readonly List LoadedGameObjects = new(); protected override IEnumerator DoSomethingDuringApplyScript() diff --git a/Assets/Scripts/Environment/SkyUpdatement.cs b/Assets/Scripts/Environment/SkyUpdatement.cs index 7552b27..8edb1f0 100644 --- a/Assets/Scripts/Environment/SkyUpdatement.cs +++ b/Assets/Scripts/Environment/SkyUpdatement.cs @@ -4,7 +4,7 @@ using Demo.Game.ConfigType; using System.Collections; using System.Collections.Generic; using System.IO; -using Unity.Collections; +using System.Linq; using UnityEngine; namespace Demo.Game @@ -23,11 +23,42 @@ namespace Demo.Game SkyNames = BinarySerializeUtility.DeserializeStringArray(reader); SkyIndexs = BinarySerializeUtility.DeserializeIntArray(reader); base.Deserialize(reader); + var sky = (SkyUpdatement)target; + sky.Load(SkyAssetBundlePath); + for (int i = 0, e = SkyNames.Length; i < e; i++) + { + sky.NameCache.Add(SkyNames[i], SkyIndexs[i]); + sky.IndexCache.Add(SkyIndexs[i], SkyNames[i]); + sky.SkyAssetBundleLoaderStatus++; + IEnumerator Foo() + { + yield return new WaitUntil(() => sky.SkyAssetBundle != null); + var ir = sky.SkyAssetBundle.LoadAssetAsync(SkyNames[i]); + ir.completed += delegate + { + var mat = ir.asset as Material; + sky.MaterialCache[SkyIndexs[i]] = mat; + sky.SkyAssetBundleLoaderStatus--; + }; + yield return ir; + } + ConventionUtility.StartCoroutine(Foo()); + } } public override void Serialize(BinaryWriter writer) { BinarySerializeUtility.WriteString(writer, SkyAssetBundlePath); + var sky = (SkyUpdatement)target; + int e = sky.NameCache.Count; + SkyNames =new string[e]; + SkyIndexs=new int[e]; + int i = 0; + foreach (var item in sky.NameCache) + { + SkyNames[i] = item.Key; + SkyIndexs[i] = item.Value; + } BinarySerializeUtility.SerializeArray(writer, SkyNames); BinarySerializeUtility.SerializeArray(writer, SkyIndexs); base.Serialize(writer); @@ -47,11 +78,16 @@ namespace Demo.Game return new GameObject().AddComponent(); } - private int SkyAssetBundleLoaderStatus = 0; - private readonly Dictionary NameCache = new(); - private readonly Dictionary MaterialCache = new(); + internal int SkyAssetBundleLoaderStatus = 0; + internal readonly Dictionary NameCache = new(); + internal readonly Dictionary IndexCache = new(); + internal readonly Dictionary MaterialCache = new(); - public string SkyAssetBundlePath; + public string SkyAssetBundlePath + { + get => GetConfig().SkyAssetBundlePath; + set => GetConfig().SkyAssetBundlePath = value; + } public AssetBundle SkyAssetBundle; protected override int Lerp(int begin, int end, float t) @@ -125,6 +161,7 @@ namespace Demo.Game { id = NameCache.Count; NameCache[sky] = id; + IndexCache[id] = sky; } MaterialCache[id] = mat; ManualAddEntry(time, id, default);