天空盒Config已更新
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Convention;
|
using Convention;
|
||||||
using Demo.Game.Attr;
|
using Demo.Game.Attr;
|
||||||
|
using Demo.Game.ConfigType;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -13,7 +14,7 @@ namespace Demo.Game
|
|||||||
{
|
{
|
||||||
public class PrefabRootObjectConfig : ScriptLoadableConfig
|
public class PrefabRootObjectConfig : ScriptLoadableConfig
|
||||||
{
|
{
|
||||||
public Dictionary<string, string[]> LoadedGameObjectNames = new();
|
public Dictionary<string, List<string>> LoadedGameObjectNames = new();
|
||||||
|
|
||||||
public override void Deserialize(BinaryReader reader)
|
public override void Deserialize(BinaryReader reader)
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,7 @@ namespace Demo.Game
|
|||||||
var temp = BinarySerializeUtility.DeserializeStringArray(reader);
|
var temp = BinarySerializeUtility.DeserializeStringArray(reader);
|
||||||
var key = temp[0];
|
var key = temp[0];
|
||||||
var value = temp[1..];
|
var value = temp[1..];
|
||||||
LoadedGameObjectNames.Add(key, value);
|
LoadedGameObjectNames.Add(key, value.ToList());
|
||||||
}
|
}
|
||||||
base.Deserialize(reader);
|
base.Deserialize(reader);
|
||||||
}
|
}
|
||||||
@@ -33,9 +34,12 @@ namespace Demo.Game
|
|||||||
BinarySerializeUtility.WriteInt(writer, LoadedGameObjectNames.Count);
|
BinarySerializeUtility.WriteInt(writer, LoadedGameObjectNames.Count);
|
||||||
foreach (var (key,value) in LoadedGameObjectNames)
|
foreach (var (key,value) in LoadedGameObjectNames)
|
||||||
{
|
{
|
||||||
string[] temp = new string[value.Length + 1];
|
string[] temp = new string[value.Count + 1];
|
||||||
temp[0] = key;
|
temp[0] = key;
|
||||||
Array.Copy(value, 0, temp, 1, value.Length);
|
for(int i=0,e=value.Count;i<e;i++)
|
||||||
|
{
|
||||||
|
temp[1 + i] = value[i];
|
||||||
|
}
|
||||||
BinarySerializeUtility.SerializeArray(writer, value.ToArray());
|
BinarySerializeUtility.SerializeArray(writer, value.ToArray());
|
||||||
}
|
}
|
||||||
base.Serialize(writer);
|
base.Serialize(writer);
|
||||||
@@ -52,7 +56,7 @@ namespace Demo.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int LoadingCounter = 0;
|
private int LoadingCounter = 0;
|
||||||
private readonly Dictionary<string, List<string>> LoadedGameObjectNames = new();
|
private Dictionary<string, List<string>> LoadedGameObjectNames => GetConfig<PrefabRootObjectConfig>().LoadedGameObjectNames;
|
||||||
private readonly List<GameObject> LoadedGameObjects = new();
|
private readonly List<GameObject> LoadedGameObjects = new();
|
||||||
|
|
||||||
protected override IEnumerator DoSomethingDuringApplyScript()
|
protected override IEnumerator DoSomethingDuringApplyScript()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Demo.Game.ConfigType;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Unity.Collections;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Demo.Game
|
namespace Demo.Game
|
||||||
@@ -23,11 +23,42 @@ namespace Demo.Game
|
|||||||
SkyNames = BinarySerializeUtility.DeserializeStringArray(reader);
|
SkyNames = BinarySerializeUtility.DeserializeStringArray(reader);
|
||||||
SkyIndexs = BinarySerializeUtility.DeserializeIntArray(reader);
|
SkyIndexs = BinarySerializeUtility.DeserializeIntArray(reader);
|
||||||
base.Deserialize(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<Material>(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)
|
public override void Serialize(BinaryWriter writer)
|
||||||
{
|
{
|
||||||
BinarySerializeUtility.WriteString(writer, SkyAssetBundlePath);
|
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, SkyNames);
|
||||||
BinarySerializeUtility.SerializeArray(writer, SkyIndexs);
|
BinarySerializeUtility.SerializeArray(writer, SkyIndexs);
|
||||||
base.Serialize(writer);
|
base.Serialize(writer);
|
||||||
@@ -47,11 +78,16 @@ namespace Demo.Game
|
|||||||
return new GameObject().AddComponent<SkyUpdatement>();
|
return new GameObject().AddComponent<SkyUpdatement>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int SkyAssetBundleLoaderStatus = 0;
|
internal int SkyAssetBundleLoaderStatus = 0;
|
||||||
private readonly Dictionary<string, int> NameCache = new();
|
internal readonly Dictionary<string, int> NameCache = new();
|
||||||
private readonly Dictionary<int, Material> MaterialCache = new();
|
internal readonly Dictionary<int, string> IndexCache = new();
|
||||||
|
internal readonly Dictionary<int, Material> MaterialCache = new();
|
||||||
|
|
||||||
public string SkyAssetBundlePath;
|
public string SkyAssetBundlePath
|
||||||
|
{
|
||||||
|
get => GetConfig<SkyUpdatementConfig>().SkyAssetBundlePath;
|
||||||
|
set => GetConfig<SkyUpdatementConfig>().SkyAssetBundlePath = value;
|
||||||
|
}
|
||||||
public AssetBundle SkyAssetBundle;
|
public AssetBundle SkyAssetBundle;
|
||||||
|
|
||||||
protected override int Lerp(int begin, int end, float t)
|
protected override int Lerp(int begin, int end, float t)
|
||||||
@@ -125,6 +161,7 @@ namespace Demo.Game
|
|||||||
{
|
{
|
||||||
id = NameCache.Count;
|
id = NameCache.Count;
|
||||||
NameCache[sky] = id;
|
NameCache[sky] = id;
|
||||||
|
IndexCache[id] = sky;
|
||||||
}
|
}
|
||||||
MaterialCache[id] = mat;
|
MaterialCache[id] = mat;
|
||||||
ManualAddEntry(time, id, default);
|
ManualAddEntry(time, id, default);
|
||||||
|
|||||||
Reference in New Issue
Block a user