天空盒Config已更新
This commit is contained in:
@@ -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<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)
|
||||
{
|
||||
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<SkyUpdatement>();
|
||||
}
|
||||
|
||||
private int SkyAssetBundleLoaderStatus = 0;
|
||||
private readonly Dictionary<string, int> NameCache = new();
|
||||
private readonly Dictionary<int, Material> MaterialCache = new();
|
||||
internal int SkyAssetBundleLoaderStatus = 0;
|
||||
internal readonly Dictionary<string, int> NameCache = 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;
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user