mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Cache LOD texture stuff better and gooder
This commit is contained in:
parent
fe4f7f5919
commit
e9bba3fa9b
@ -64,7 +64,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
GameObject prop = GameObject.Instantiate(prefab, sector.transform);
|
GameObject prop = GameObject.Instantiate(prefab, sector.transform);
|
||||||
prop.SetActive(false);
|
prop.SetActive(false);
|
||||||
|
|
||||||
sector.OnOccupantEnterSector += (SectorDetector sd) => OWAssetHandler.LoadObject(prop);
|
sector.OnOccupantEnterSector += (SectorDetector sd) => OWAssetHandler.OnOccupantEnterSector(prop, sd, sector);
|
||||||
OWAssetHandler.LoadObject(prop);
|
OWAssetHandler.LoadObject(prop);
|
||||||
|
|
||||||
foreach (var component in prop.GetComponents<Component>().Concat(prop.GetComponentsInChildren<Component>()))
|
foreach (var component in prop.GetComponents<Component>().Concat(prop.GetComponentsInChildren<Component>()))
|
||||||
|
|||||||
@ -11,52 +11,73 @@ namespace NewHorizons.Handlers
|
|||||||
public static class OWAssetHandler
|
public static class OWAssetHandler
|
||||||
{
|
{
|
||||||
private static Dictionary<Material, string> _materialCache;
|
private static Dictionary<Material, string> _materialCache;
|
||||||
|
private static Dictionary<GameObject, List<string>> _objectCache;
|
||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
_materialCache = new Dictionary<Material, string>();
|
_materialCache = new Dictionary<Material, string>();
|
||||||
|
_objectCache = new Dictionary<GameObject, List<string>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void OnOccupantEnterSector(GameObject obj, SectorDetector sd, Sector sector)
|
||||||
|
{
|
||||||
|
LoadObject(obj);
|
||||||
|
|
||||||
|
// If its too laggy put this back idk
|
||||||
|
/*
|
||||||
|
if (sector.GetOccupants().Count > 0 || sd._occupantType == DynamicOccupant.Player)
|
||||||
|
{
|
||||||
|
LoadObject(obj);
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadObject(GameObject obj)
|
public static void LoadObject(GameObject obj)
|
||||||
{
|
{
|
||||||
var assetBundles = new List<string>();
|
var assetBundles = new List<string>();
|
||||||
|
|
||||||
var tables = Resources.FindObjectsOfTypeAll<StreamingMaterialTable>();
|
if (_objectCache.ContainsKey(obj))
|
||||||
foreach (var streamingHandle in obj.GetComponentsInChildren<StreamingMeshHandle>())
|
|
||||||
{
|
{
|
||||||
var assetBundle = streamingHandle.assetBundle;
|
assetBundles = _objectCache[obj];
|
||||||
if (!assetBundles.Contains(assetBundle))
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var tables = Resources.FindObjectsOfTypeAll<StreamingMaterialTable>();
|
||||||
|
foreach (var streamingHandle in obj.GetComponentsInChildren<StreamingMeshHandle>())
|
||||||
{
|
{
|
||||||
assetBundles.Add(assetBundle);
|
var assetBundle = streamingHandle.assetBundle;
|
||||||
}
|
if (!assetBundles.Contains(assetBundle))
|
||||||
if (streamingHandle is StreamingRenderMeshHandle || streamingHandle is StreamingSkinnedMeshHandle)
|
|
||||||
{
|
|
||||||
var materials = streamingHandle.GetComponent<Renderer>().sharedMaterials;
|
|
||||||
|
|
||||||
if (materials.Length == 0) continue;
|
|
||||||
|
|
||||||
if (_materialCache == null) _materialCache = new Dictionary<Material, string>();
|
|
||||||
|
|
||||||
// Gonna assume that if theres more than one material its probably in the same asset bundle anyway right
|
|
||||||
if (_materialCache.TryGetValue(materials[0], out assetBundle))
|
|
||||||
{
|
{
|
||||||
assetBundles.Add(assetBundle);
|
assetBundles.Add(assetBundle);
|
||||||
}
|
}
|
||||||
else
|
if (streamingHandle is StreamingRenderMeshHandle || streamingHandle is StreamingSkinnedMeshHandle)
|
||||||
{
|
{
|
||||||
foreach (var table in tables)
|
var materials = streamingHandle.GetComponent<Renderer>().sharedMaterials;
|
||||||
|
|
||||||
|
if (materials.Length == 0) continue;
|
||||||
|
|
||||||
|
// Gonna assume that if theres more than one material its probably in the same asset bundle anyway right
|
||||||
|
if (_materialCache.TryGetValue(materials[0], out assetBundle))
|
||||||
{
|
{
|
||||||
foreach (var x in table._materialPropertyLookups)
|
assetBundles.Add(assetBundle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var table in tables)
|
||||||
{
|
{
|
||||||
if (materials.Contains(x.material))
|
foreach (var x in table._materialPropertyLookups)
|
||||||
{
|
{
|
||||||
_materialCache.SafeAdd(x.material, table.assetBundle);
|
if (materials.Contains(x.material))
|
||||||
assetBundles.SafeAdd(table.assetBundle);
|
{
|
||||||
|
_materialCache.SafeAdd(x.material, table.assetBundle);
|
||||||
|
assetBundles.SafeAdd(table.assetBundle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_objectCache[obj] = assetBundles;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var assetBundle in assetBundles)
|
foreach (var assetBundle in assetBundles)
|
||||||
|
|||||||
@ -199,8 +199,8 @@ namespace NewHorizons
|
|||||||
NewHorizonsData.Load();
|
NewHorizonsData.Load();
|
||||||
SignalBuilder.Init();
|
SignalBuilder.Init();
|
||||||
AstroObjectLocator.RefreshList();
|
AstroObjectLocator.RefreshList();
|
||||||
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
|
|
||||||
OWAssetHandler.Init();
|
OWAssetHandler.Init();
|
||||||
|
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
|
||||||
LoadTranslations(ModHelper.Manifest.ModFolderPath + "AssetBundle/", this);
|
LoadTranslations(ModHelper.Manifest.ModFolderPath + "AssetBundle/", this);
|
||||||
|
|
||||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
|
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user