mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Optimizations (#710)
<!-- A new module or something else important --> ## Major features - <!-- A new parameter added to a module, or API feature --> ## Minor features - <!-- Some improvement that requires no action on the part of add-on creators i.e., improved star graphics --> ## Improvements - Cached more stuff to improve loading times. Implements #683 - Cleaned up how planets are destroyed. Should make load screens faster. Implements #573 <!-- Be sure to reference the existing issue if it exists --> ## Bug fixes - Fixes Bramble colours at a distance. Fixes #372
This commit is contained in:
commit
6596c7ce3a
@ -41,7 +41,9 @@ namespace NewHorizons.Builder.Props.Audio
|
|||||||
|
|
||||||
Initialized = true;
|
Initialized = true;
|
||||||
|
|
||||||
|
SceneManager.sceneUnloaded -= OnSceneUnloaded;
|
||||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||||
|
Main.Instance.OnStarSystemLoaded.RemoveListener(OnStarSystemLoaded);
|
||||||
Main.Instance.OnStarSystemLoaded.AddListener(OnStarSystemLoaded);
|
Main.Instance.OnStarSystemLoaded.AddListener(OnStarSystemLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -260,9 +260,17 @@ namespace NewHorizons.Builder.Props
|
|||||||
// Default size is 70
|
// Default size is 70
|
||||||
var fog = brambleNode.FindChild("Effects/InnerWarpFogSphere");
|
var fog = brambleNode.FindChild("Effects/InnerWarpFogSphere");
|
||||||
fog.transform.localScale = Vector3.one * config.scale * 70f;
|
fog.transform.localScale = Vector3.one * config.scale * 70f;
|
||||||
var fogMaterial = fog.GetComponent<MeshRenderer>().material;
|
|
||||||
fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale);
|
// Copy shared material to not be shared
|
||||||
fogMaterial.SetFloat("_Density", fogMaterial.GetFloat("_Density") / config.scale);
|
var fogRenderer = fog.GetComponent<MeshRenderer>();
|
||||||
|
fogRenderer.material = new Material(fogRenderer.sharedMaterial);
|
||||||
|
fogRenderer.material.SetFloat("_Radius", fogRenderer.material.GetFloat("_Radius") * config.scale);
|
||||||
|
fogRenderer.material.SetFloat("_Density", fogRenderer.material.GetFloat("_Density") / config.scale);
|
||||||
|
// Fixes bramble nodes being a weird colour until you approach the first time #372
|
||||||
|
if (config.fogTint != null)
|
||||||
|
{
|
||||||
|
fog.GetComponent<OWRenderer>().SetColor(config.fogTint.ToColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set colors
|
// Set colors
|
||||||
@ -393,7 +401,8 @@ namespace NewHorizons.Builder.Props
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamingHandler.SetUpStreaming(brambleNode, sector);
|
// If the outer fog warp volume is null we're exposed to the solar system so treat it as a keepLoaded type prop
|
||||||
|
StreamingHandler.SetUpStreaming(brambleNode, outerFogWarpVolume == null ? null : sector);
|
||||||
|
|
||||||
// Done!
|
// Done!
|
||||||
brambleNode.SetActive(true);
|
brambleNode.SetActive(true);
|
||||||
|
|||||||
@ -632,6 +632,12 @@ namespace NewHorizons.Builder.Props.TranslatorText
|
|||||||
xmlDocument.LoadXml(xmlPath);
|
xmlDocument.LoadXml(xmlPath);
|
||||||
XmlNode rootNode = xmlDocument.SelectSingleNode("NomaiObject");
|
XmlNode rootNode = xmlDocument.SelectSingleNode("NomaiObject");
|
||||||
|
|
||||||
|
if (rootNode == null)
|
||||||
|
{
|
||||||
|
NHLogger.LogError($"Couldn't find NomaiObject in [{xmlPath}]");
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (object obj in rootNode.SelectNodes("TextBlock"))
|
foreach (object obj in rootNode.SelectNodes("TextBlock"))
|
||||||
{
|
{
|
||||||
XmlNode xmlNode = (XmlNode)obj;
|
XmlNode xmlNode = (XmlNode)obj;
|
||||||
|
|||||||
@ -158,8 +158,20 @@ namespace NewHorizons.Handlers
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
if (body?.Config?.name == null) NHLogger.LogError($"How is there no name for {body}");
|
if (body?.Config?.name == null)
|
||||||
else existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false);
|
{
|
||||||
|
NHLogger.LogError($"How is there no name for {body}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingPlanet == null && body.Config.destroy)
|
||||||
|
{
|
||||||
|
NHLogger.LogError($"{body.Config.name} was meant to be destroyed, but was not found");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingPlanet != null)
|
if (existingPlanet != null)
|
||||||
@ -169,8 +181,14 @@ namespace NewHorizons.Handlers
|
|||||||
if (body.Config.destroy)
|
if (body.Config.destroy)
|
||||||
{
|
{
|
||||||
var ao = existingPlanet.GetComponent<AstroObject>();
|
var ao = existingPlanet.GetComponent<AstroObject>();
|
||||||
if (ao != null) Delay.FireInNUpdates(() => PlanetDestructionHandler.RemoveBody(ao), 2);
|
if (ao != null)
|
||||||
else Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableBody(existingPlanet, false), 2);
|
{
|
||||||
|
Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableAstroObject(ao), 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Delay.FireInNUpdates(() => PlanetDestructionHandler.DisableGameObject(existingPlanet), 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (body.Config.isQuantumState)
|
else if (body.Config.isQuantumState)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,48 +12,9 @@ namespace NewHorizons.Handlers
|
|||||||
{
|
{
|
||||||
public static class PlanetDestructionHandler
|
public static class PlanetDestructionHandler
|
||||||
{
|
{
|
||||||
private static readonly string[] _solarSystemBodies = new string[]
|
public static readonly string[] _suspendBlacklist = new string[] { "Player_Body", "Probe_Body", "Ship_Body" };
|
||||||
{
|
|
||||||
"Ash Twin",
|
|
||||||
"Attlerock",
|
|
||||||
"Brittle Hollow",
|
|
||||||
"Dark Bramble",
|
|
||||||
"DreamWorld",
|
|
||||||
"Ember Twin",
|
|
||||||
"Giant's Deep",
|
|
||||||
"Hollow's Lantern",
|
|
||||||
"Interloper",
|
|
||||||
"Map Satellite",
|
|
||||||
"Orbital Probe Cannon",
|
|
||||||
"Quantum Moon",
|
|
||||||
"RingWorld",
|
|
||||||
"Sun",
|
|
||||||
"Sun Station",
|
|
||||||
"Timber Hearth",
|
|
||||||
"White Hole"
|
|
||||||
};
|
|
||||||
|
|
||||||
private static readonly string[] _eyeOfTheUniverseBodies = new string[]
|
|
||||||
{
|
|
||||||
"Eye Of The Universe",
|
|
||||||
"Vessel"
|
|
||||||
};
|
|
||||||
|
|
||||||
private static readonly string[] _suspendBlacklist = new string[]
|
|
||||||
{
|
|
||||||
"Player_Body",
|
|
||||||
"Ship_Body"
|
|
||||||
};
|
|
||||||
|
|
||||||
public static void RemoveStockPlanets()
|
public static void RemoveStockPlanets()
|
||||||
{
|
|
||||||
if (Main.Instance.CurrentStarSystem == "EyeOfTheUniverse")
|
|
||||||
RemoveEyeOfTheUniverse();
|
|
||||||
else
|
|
||||||
RemoveSolarSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveSolarSystem()
|
|
||||||
{
|
{
|
||||||
// Adapted from EOTS thanks corby
|
// Adapted from EOTS thanks corby
|
||||||
var toDisable = new List<GameObject>();
|
var toDisable = new List<GameObject>();
|
||||||
@ -61,7 +22,7 @@ namespace NewHorizons.Handlers
|
|||||||
// Collect all rigid bodies and proxies
|
// Collect all rigid bodies and proxies
|
||||||
foreach (var rigidbody in CenterOfTheUniverse.s_rigidbodies)
|
foreach (var rigidbody in CenterOfTheUniverse.s_rigidbodies)
|
||||||
{
|
{
|
||||||
if (rigidbody.name is not ("Player_Body" or "Probe_Body" or "Ship_Body"))
|
if (!_suspendBlacklist.Contains(rigidbody.name))
|
||||||
{
|
{
|
||||||
toDisable.Add(rigidbody.gameObject);
|
toDisable.Add(rigidbody.gameObject);
|
||||||
}
|
}
|
||||||
@ -83,32 +44,19 @@ namespace NewHorizons.Handlers
|
|||||||
}
|
}
|
||||||
GameObject.FindObjectOfType<SunProxy>().gameObject.SetActive(false);
|
GameObject.FindObjectOfType<SunProxy>().gameObject.SetActive(false);
|
||||||
|
|
||||||
// force call update here to make it switch to an active star. idk why we didnt have to do this before
|
if (Main.Instance.CurrentStarSystem != "EyeOfTheUniverse")
|
||||||
SunLightEffectsController.Instance.Update();
|
{
|
||||||
|
// Since we didn't call RemoveBody on the all planets there are some we have to call here
|
||||||
|
StrangerRemoved();
|
||||||
|
TimberHearthRemoved();
|
||||||
|
GiantsDeepRemoved();
|
||||||
|
SunRemoved();
|
||||||
|
}
|
||||||
|
|
||||||
// Since we didn't call RemoveBody on the Stranger have to call this here
|
|
||||||
StrangerRemoved();
|
|
||||||
|
|
||||||
// Don't forget to fix THE WARP BUG
|
|
||||||
DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true);
|
|
||||||
}, 2); // Have to wait or shit goes wild
|
}, 2); // Have to wait or shit goes wild
|
||||||
|
|
||||||
foreach (var streamingAssetBundle in StreamingManager.s_activeBundles)
|
|
||||||
{
|
|
||||||
//streamingAssetBundle.Unload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveEyeOfTheUniverse()
|
|
||||||
{
|
|
||||||
foreach (var name in _eyeOfTheUniverseBodies)
|
|
||||||
{
|
|
||||||
var ao = AstroObjectLocator.GetAstroObject(name);
|
|
||||||
if (ao != null) Delay.FireInNUpdates(() => RemoveBody(ao, false), 2);
|
|
||||||
else NHLogger.LogError($"Couldn't find [{name}]");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Planet specific removals
|
||||||
public static void StrangerRemoved()
|
public static void StrangerRemoved()
|
||||||
{
|
{
|
||||||
CloakHandler.FlagStrangerDisabled = true;
|
CloakHandler.FlagStrangerDisabled = true;
|
||||||
@ -119,101 +67,122 @@ namespace NewHorizons.Handlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveBody(AstroObject ao, bool delete = false, List<AstroObject> toDestroy = null)
|
private static void SunRemoved()
|
||||||
{
|
{
|
||||||
NHLogger.LogVerbose($"Removing [{ao.name}]");
|
var sun = SearchUtilities.Find("Sun_Body").GetComponent<AstroObject>();
|
||||||
|
|
||||||
if (ao.GetAstroObjectName() == AstroObject.Name.RingWorld)
|
var starController = sun.gameObject.GetComponent<StarController>();
|
||||||
|
SunLightEffectsController.RemoveStar(starController);
|
||||||
|
SunLightEffectsController.RemoveStarLight(sun.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
|
||||||
|
UnityEngine.Object.Destroy(starController);
|
||||||
|
|
||||||
|
var audio = sun.GetComponentInChildren<SunSurfaceAudioController>();
|
||||||
|
UnityEngine.Object.Destroy(audio);
|
||||||
|
|
||||||
|
foreach (var owAudioSource in sun.GetComponentsInChildren<OWAudioSource>())
|
||||||
{
|
{
|
||||||
StrangerRemoved();
|
owAudioSource.Stop();
|
||||||
|
UnityEngine.Object.Destroy(owAudioSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var audioSource in sun.GetComponentsInChildren<AudioSource>())
|
||||||
|
{
|
||||||
|
audioSource.Stop();
|
||||||
|
UnityEngine.Object.Destroy(audioSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var sunProxy in UnityEngine.Object.FindObjectsOfType<SunProxy>())
|
||||||
|
{
|
||||||
|
NHLogger.LogVerbose($"Destroying SunProxy {sunProxy.gameObject.name}");
|
||||||
|
UnityEngine.Object.Destroy(sunProxy.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop the sun from breaking stuff when the supernova gets triggered
|
||||||
|
GlobalMessenger.RemoveListener("TriggerSupernova", sun.GetComponent<SunController>().OnTriggerSupernova);
|
||||||
|
|
||||||
|
// Just to be safe
|
||||||
|
SunLightEffectsController.Instance.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TimberHearthRemoved()
|
||||||
|
{
|
||||||
|
// Always just fucking kill this one to stop THE WARP BUG!!!
|
||||||
|
GameObject.Destroy(SearchUtilities.Find("StreamingGroup_TH").gameObject);
|
||||||
|
|
||||||
|
var timberHearth = SearchUtilities.Find("TimberHearth_Body");
|
||||||
|
foreach (var obj in timberHearth.GetComponentsInChildren<DayNightTracker>())
|
||||||
|
{
|
||||||
|
GameObject.Destroy(obj.gameObject);
|
||||||
|
}
|
||||||
|
foreach (var obj in timberHearth.GetComponentsInChildren<VillageMusicVolume>())
|
||||||
|
{
|
||||||
|
GameObject.Destroy(obj.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GiantsDeepRemoved()
|
||||||
|
{
|
||||||
|
foreach (var jelly in UnityEngine.Object.FindObjectsOfType<JellyfishController>())
|
||||||
|
{
|
||||||
|
if (jelly.GetSector().GetRootSector().GetName() == Sector.Name.GiantsDeep)
|
||||||
|
{
|
||||||
|
DisableGameObject(jelly.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public static void DisableAstroObject(AstroObject ao, List<AstroObject> toDisable = null)
|
||||||
|
{
|
||||||
if (ao.gameObject == null || !ao.gameObject.activeInHierarchy)
|
if (ao.gameObject == null || !ao.gameObject.activeInHierarchy)
|
||||||
{
|
{
|
||||||
NHLogger.LogVerbose($"[{ao.name}] was already removed");
|
NHLogger.LogVerbose($"[{ao?.name}] was already removed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toDestroy == null) toDestroy = new List<AstroObject>();
|
NHLogger.LogVerbose($"Removing [{ao.name}]");
|
||||||
|
|
||||||
if (toDestroy.Contains(ao))
|
toDisable ??= new List<AstroObject>();
|
||||||
|
|
||||||
|
if (toDisable.Contains(ao))
|
||||||
{
|
{
|
||||||
NHLogger.LogVerbose($"Possible infinite recursion in RemoveBody: {ao.name} might be it's own primary body?");
|
NHLogger.LogVerbose($"Possible infinite recursion in RemoveBody: {ao.name} might be it's own primary body?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toDestroy.Add(ao);
|
toDisable.Add(ao);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch(ao._name)
|
switch(ao._name)
|
||||||
{
|
{
|
||||||
case AstroObject.Name.BrittleHollow:
|
case AstroObject.Name.BrittleHollow:
|
||||||
RemoveBody(AstroObjectLocator.GetAstroObject(AstroObject.Name.WhiteHole.ToString()), delete, toDestroy);
|
DisableAstroObject(AstroObjectLocator.GetAstroObject(AstroObject.Name.WhiteHole.ToString()), toDisable);
|
||||||
// Might prevent leftover fragments from existing
|
// Might prevent leftover fragments from existing
|
||||||
// Might also prevent people from using their own detachable fragments however
|
// Might also prevent people from using their own detachable fragments however
|
||||||
foreach(var fragment in UnityEngine.Object.FindObjectsOfType<DetachableFragment>())
|
foreach(var fragment in UnityEngine.Object.FindObjectsOfType<DetachableFragment>())
|
||||||
{
|
{
|
||||||
DisableBody(fragment.gameObject, delete);
|
DisableGameObject(fragment.gameObject);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstroObject.Name.CaveTwin:
|
case AstroObject.Name.CaveTwin:
|
||||||
case AstroObject.Name.TowerTwin:
|
case AstroObject.Name.TowerTwin:
|
||||||
DisableBody(SearchUtilities.Find("FocalBody"), delete);
|
DisableGameObject(SearchUtilities.Find("FocalBody"));
|
||||||
DisableBody(SearchUtilities.Find("SandFunnel_Body", false), delete);
|
DisableGameObject(SearchUtilities.Find("SandFunnel_Body", false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AstroObject.Name.GiantsDeep:
|
case AstroObject.Name.GiantsDeep:
|
||||||
// Might prevent leftover jellyfish from existing
|
GiantsDeepRemoved();
|
||||||
// Might also prevent people from using their own jellyfish however
|
|
||||||
foreach (var jelly in UnityEngine.Object.FindObjectsOfType<JellyfishController>())
|
|
||||||
{
|
|
||||||
DisableBody(jelly.gameObject, delete);
|
|
||||||
}
|
|
||||||
// Else it will re-eanble the pieces
|
|
||||||
// ao.GetComponent<OrbitalProbeLaunchController>()._realDebrisSectorProxies = null;
|
|
||||||
break;
|
break;
|
||||||
case AstroObject.Name.TimberHearth:
|
case AstroObject.Name.TimberHearth:
|
||||||
// Always just fucking kill this one to stop THE WARP BUG!!!
|
TimberHearthRemoved();
|
||||||
DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true);
|
|
||||||
|
|
||||||
foreach (var obj in UnityEngine.Object.FindObjectsOfType<DayNightTracker>())
|
|
||||||
{
|
|
||||||
DisableBody(obj.gameObject, true);
|
|
||||||
}
|
|
||||||
foreach (var obj in UnityEngine.Object.FindObjectsOfType<VillageMusicVolume>())
|
|
||||||
{
|
|
||||||
DisableBody(obj.gameObject, true);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case AstroObject.Name.Sun:
|
case AstroObject.Name.Sun:
|
||||||
var starController = ao.gameObject.GetComponent<StarController>();
|
SunRemoved();
|
||||||
SunLightEffectsController.RemoveStar(starController);
|
break;
|
||||||
SunLightEffectsController.RemoveStarLight(ao.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
|
case AstroObject.Name.RingWorld:
|
||||||
UnityEngine.Object.Destroy(starController);
|
StrangerRemoved();
|
||||||
|
|
||||||
var audio = ao.GetComponentInChildren<SunSurfaceAudioController>();
|
|
||||||
UnityEngine.Object.Destroy(audio);
|
|
||||||
|
|
||||||
foreach (var owAudioSource in ao.GetComponentsInChildren<OWAudioSource>())
|
|
||||||
{
|
|
||||||
owAudioSource.Stop();
|
|
||||||
UnityEngine.Object.Destroy(owAudioSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var audioSource in ao.GetComponentsInChildren<AudioSource>())
|
|
||||||
{
|
|
||||||
audioSource.Stop();
|
|
||||||
UnityEngine.Object.Destroy(audioSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var sunProxy in UnityEngine.Object.FindObjectsOfType<SunProxy>())
|
|
||||||
{
|
|
||||||
NHLogger.LogVerbose($"Destroying SunProxy {sunProxy.gameObject.name}");
|
|
||||||
UnityEngine.Object.Destroy(sunProxy.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop the sun from breaking stuff when the supernova gets triggered
|
|
||||||
GlobalMessenger.RemoveListener("TriggerSupernova", ao.GetComponent<SunController>().OnTriggerSupernova);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,8 +199,14 @@ namespace NewHorizons.Handlers
|
|||||||
|
|
||||||
// Some children might be astro objects and as such can have children of their own
|
// Some children might be astro objects and as such can have children of their own
|
||||||
var childAO = child.GetComponent<AstroObject>();
|
var childAO = child.GetComponent<AstroObject>();
|
||||||
if (childAO != null) RemoveBody(childAO, false, toDestroy);
|
if (childAO != null)
|
||||||
else DisableBody(child, true);
|
{
|
||||||
|
DisableAstroObject(childAO, toDisable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DisableGameObject(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always delete moons
|
// Always delete moons
|
||||||
@ -239,7 +214,7 @@ namespace NewHorizons.Handlers
|
|||||||
{
|
{
|
||||||
if (obj == null) continue;
|
if (obj == null) continue;
|
||||||
|
|
||||||
RemoveBody(obj.GetComponent<AstroObject>(), false, toDestroy);
|
DisableAstroObject(obj.GetComponent<AstroObject>(), toDisable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -247,36 +222,8 @@ namespace NewHorizons.Handlers
|
|||||||
NHLogger.LogError($"Exception thrown when trying to delete bodies related to [{ao.name}]:\n{e}");
|
NHLogger.LogError($"Exception thrown when trying to delete bodies related to [{ao.name}]:\n{e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deal with proxies
|
DisableGameObject(ao.gameObject);
|
||||||
foreach (var p in UnityEngine.Object.FindObjectsOfType<ProxyOrbiter>())
|
RemoveProxy(ao);
|
||||||
{
|
|
||||||
if (p._originalBody == ao.gameObject)
|
|
||||||
{
|
|
||||||
DisableBody(p.gameObject, true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RemoveProxy(ao.name.Replace("_Body", ""));
|
|
||||||
|
|
||||||
Delay.RunWhen(() => Main.IsSystemReady, () => DisableBody(ao.gameObject, delete));
|
|
||||||
|
|
||||||
foreach (ProxyBody proxy in UnityEngine.Object.FindObjectsOfType<ProxyBody>())
|
|
||||||
{
|
|
||||||
if (proxy?._realObjectTransform?.gameObject == ao.gameObject)
|
|
||||||
{
|
|
||||||
UnityEngine.Object.Destroy(proxy.gameObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveAllProxies()
|
|
||||||
{
|
|
||||||
UnityEngine.Object.Destroy(UnityEngine.Object.FindObjectOfType<DistantProxyManager>().gameObject);
|
|
||||||
|
|
||||||
foreach (var name in _solarSystemBodies)
|
|
||||||
{
|
|
||||||
RemoveProxy(name.Replace(" ", "").Replace("'", ""));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CanSuspend(OWRigidbody rigidbody, string name)
|
private static bool CanSuspend(OWRigidbody rigidbody, string name)
|
||||||
@ -286,7 +233,7 @@ namespace NewHorizons.Handlers
|
|||||||
return CanSuspend(rigidbody._origParentBody, name);
|
return CanSuspend(rigidbody._origParentBody, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void DisableBody(GameObject go, bool delete)
|
internal static void DisableGameObject(GameObject go)
|
||||||
{
|
{
|
||||||
if (go == null) return;
|
if (go == null) return;
|
||||||
|
|
||||||
@ -317,33 +264,18 @@ namespace NewHorizons.Handlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delete)
|
go.SetActive(false);
|
||||||
|
var ol = go.GetComponentInChildren<OrbitLine>();
|
||||||
|
if (ol)
|
||||||
{
|
{
|
||||||
UnityEngine.Object.Destroy(go);
|
ol.enabled = false;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
go.SetActive(false);
|
|
||||||
var ol = go.GetComponentInChildren<OrbitLine>();
|
|
||||||
if (ol)
|
|
||||||
{
|
|
||||||
ol.enabled = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RemoveProxy(string name)
|
private static void RemoveProxy(AstroObject ao)
|
||||||
{
|
{
|
||||||
if (name.Equals("TowerTwin")) name = "AshTwin";
|
ProxyHandler.GetVanillaProxyBody(ao.transform)?.gameObject?.SetActive(false);
|
||||||
if (name.Equals("CaveTwin")) name = "EmberTwin";
|
ProxyHandler.GetVanillaProxyOrbiter(ao.transform)?.gameObject?.SetActive(false);
|
||||||
var distantProxy = SearchUtilities.Find(name + "_DistantProxy", false);
|
|
||||||
var distantProxyClone = SearchUtilities.Find(name + "_DistantProxy(Clone)", false);
|
|
||||||
|
|
||||||
if (distantProxy != null) UnityEngine.Object.Destroy(distantProxy.gameObject);
|
|
||||||
if (distantProxyClone != null) UnityEngine.Object.Destroy(distantProxyClone.gameObject);
|
|
||||||
|
|
||||||
if (distantProxy == null && distantProxyClone == null)
|
|
||||||
NHLogger.LogVerbose($"Couldn't find proxy for {name}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,21 @@
|
|||||||
using NewHorizons.Components;
|
using NewHorizons.Components;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NewHorizons.Handlers
|
namespace NewHorizons.Handlers
|
||||||
{
|
{
|
||||||
public static class ProxyHandler
|
public static class ProxyHandler
|
||||||
{
|
{
|
||||||
private static List<NHProxy> _proxies = new List<NHProxy>();
|
private static List<NHProxy> _proxies = new();
|
||||||
|
private static Dictionary<Transform, ProxyBody> _vanillaProxyBody = new();
|
||||||
|
private static Dictionary<Transform, ProxyOrbiter> _vanillaProxyOrbiter = new();
|
||||||
|
|
||||||
|
public static void ClearCache()
|
||||||
|
{
|
||||||
|
_proxies.Clear();
|
||||||
|
_vanillaProxyBody.Clear();
|
||||||
|
_vanillaProxyOrbiter.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static NHProxy GetProxy(string astroName)
|
public static NHProxy GetProxy(string astroName)
|
||||||
{
|
{
|
||||||
@ -17,6 +27,48 @@ namespace NewHorizons.Handlers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RegisterVanillaProxyBody(ProxyBody proxy)
|
||||||
|
{
|
||||||
|
if (proxy.realObjectTransform != null)
|
||||||
|
{
|
||||||
|
_vanillaProxyBody.Add(proxy.realObjectTransform, proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProxyBody GetVanillaProxyBody(Transform t)
|
||||||
|
{
|
||||||
|
if (_vanillaProxyBody.TryGetValue(t, out ProxyBody proxy))
|
||||||
|
{
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterVanillaProxyOrbiter(ProxyOrbiter proxy)
|
||||||
|
{
|
||||||
|
// The _originalBody is the moon
|
||||||
|
// For _originalPlanetBody, that game object will also have a ProxyBody on it so it'd be counted via the other cache
|
||||||
|
if (proxy._originalBody != null)
|
||||||
|
{
|
||||||
|
_vanillaProxyOrbiter.Add(proxy._originalBody, proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProxyOrbiter GetVanillaProxyOrbiter(Transform t)
|
||||||
|
{
|
||||||
|
if (_vanillaProxyOrbiter.TryGetValue(t, out ProxyOrbiter proxy))
|
||||||
|
{
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void RegisterProxy(NHProxy proxy)
|
public static void RegisterProxy(NHProxy proxy)
|
||||||
{
|
{
|
||||||
_proxies.SafeAdd(proxy);
|
_proxies.SafeAdd(proxy);
|
||||||
|
|||||||
@ -58,8 +58,27 @@ namespace NewHorizons
|
|||||||
public static bool IsSystemReady { get; private set; }
|
public static bool IsSystemReady { get; private set; }
|
||||||
|
|
||||||
public string DefaultStarSystem => SystemDict.ContainsKey(_defaultSystemOverride) ? _defaultSystemOverride : _defaultStarSystem;
|
public string DefaultStarSystem => SystemDict.ContainsKey(_defaultSystemOverride) ? _defaultSystemOverride : _defaultStarSystem;
|
||||||
public string CurrentStarSystem => _currentStarSystem;
|
public string CurrentStarSystem
|
||||||
public bool TimeLoopEnabled => SystemDict[CurrentStarSystem]?.Config?.enableTimeLoop ?? true;
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _currentStarSystem;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// Prevent invalid values
|
||||||
|
if (value != "SolarSystem" && value != "EyeOfTheUniverse" && !SystemDict.ContainsKey(value) && !BodyDict.ContainsKey(value))
|
||||||
|
{
|
||||||
|
NHLogger.LogError($"System \"{value}\" does not exist!");
|
||||||
|
_currentStarSystem = DefaultStarSystem;
|
||||||
|
}
|
||||||
|
_currentStarSystem = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private string _currentStarSystem;
|
||||||
|
private string _previousStarSystem;
|
||||||
|
|
||||||
|
public bool TimeLoopEnabled => CurrentStarSystem == null || (SystemDict[CurrentStarSystem]?.Config?.enableTimeLoop ?? true);
|
||||||
public bool IsWarpingFromShip { get; private set; } = false;
|
public bool IsWarpingFromShip { get; private set; } = false;
|
||||||
public bool IsWarpingFromVessel { get; private set; } = false;
|
public bool IsWarpingFromVessel { get; private set; } = false;
|
||||||
public bool IsWarpingBackToEye { get; internal set; } = false;
|
public bool IsWarpingBackToEye { get; internal set; } = false;
|
||||||
@ -72,7 +91,7 @@ namespace NewHorizons
|
|||||||
public static bool HasWarpDrive { get; private set; } = false;
|
public static bool HasWarpDrive { get; private set; } = false;
|
||||||
|
|
||||||
private string _defaultStarSystem = "SolarSystem";
|
private string _defaultStarSystem = "SolarSystem";
|
||||||
internal string _currentStarSystem = "SolarSystem";
|
|
||||||
private bool _firstLoad = true;
|
private bool _firstLoad = true;
|
||||||
|
|
||||||
private bool _playerAwake;
|
private bool _playerAwake;
|
||||||
@ -259,11 +278,20 @@ namespace NewHorizons
|
|||||||
|
|
||||||
private void OnSceneUnloaded(Scene scene)
|
private void OnSceneUnloaded(Scene scene)
|
||||||
{
|
{
|
||||||
|
// Caches of GameObjects must always be cleared
|
||||||
SearchUtilities.ClearCache();
|
SearchUtilities.ClearCache();
|
||||||
ImageUtilities.ClearCache();
|
ProxyHandler.ClearCache();
|
||||||
AudioUtilities.ClearCache();
|
|
||||||
AssetBundleUtilities.ClearCache();
|
// Caches of other assets only have to be cleared if we changed star systems
|
||||||
EnumUtilities.ClearCache();
|
if (CurrentStarSystem != _previousStarSystem)
|
||||||
|
{
|
||||||
|
NHLogger.Log($"Changing star system from {_previousStarSystem} to {CurrentStarSystem} - Clearing system-specific caches!");
|
||||||
|
ImageUtilities.ClearCache();
|
||||||
|
AudioUtilities.ClearCache();
|
||||||
|
AssetBundleUtilities.ClearCache();
|
||||||
|
EnumUtilities.ClearCache();
|
||||||
|
}
|
||||||
|
|
||||||
IsSystemReady = false;
|
IsSystemReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +357,7 @@ namespace NewHorizons
|
|||||||
|
|
||||||
if (isEyeOfTheUniverse)
|
if (isEyeOfTheUniverse)
|
||||||
{
|
{
|
||||||
_currentStarSystem = "EyeOfTheUniverse";
|
CurrentStarSystem = "EyeOfTheUniverse";
|
||||||
}
|
}
|
||||||
else if (IsWarpingBackToEye)
|
else if (IsWarpingBackToEye)
|
||||||
{
|
{
|
||||||
@ -340,14 +368,8 @@ namespace NewHorizons
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SystemDict.ContainsKey(_currentStarSystem) || !BodyDict.ContainsKey(_currentStarSystem))
|
|
||||||
{
|
|
||||||
NHLogger.LogError($"System \"{_currentStarSystem}\" does not exist!");
|
|
||||||
_currentStarSystem = DefaultStarSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set time loop stuff if its enabled and if we're warping to a new place
|
// Set time loop stuff if its enabled and if we're warping to a new place
|
||||||
if (IsChangingStarSystem && (SystemDict[_currentStarSystem].Config.enableTimeLoop || _currentStarSystem == "SolarSystem") && SecondsElapsedInLoop > 0f)
|
if (IsChangingStarSystem && (SystemDict[CurrentStarSystem].Config.enableTimeLoop || CurrentStarSystem == "SolarSystem") && SecondsElapsedInLoop > 0f)
|
||||||
{
|
{
|
||||||
TimeLoopUtilities.SetSecondsElapsed(SecondsElapsedInLoop);
|
TimeLoopUtilities.SetSecondsElapsed(SecondsElapsedInLoop);
|
||||||
// Prevent the OPC from firing
|
// Prevent the OPC from firing
|
||||||
@ -362,7 +384,7 @@ namespace NewHorizons
|
|||||||
launchController.enabled = false;
|
launchController.enabled = false;
|
||||||
}
|
}
|
||||||
var nomaiProbe = SearchUtilities.Find("NomaiProbe_Body");
|
var nomaiProbe = SearchUtilities.Find("NomaiProbe_Body");
|
||||||
if (nomaiProbe != null) nomaiProbe.gameObject.SetActive(false);
|
nomaiProbe?.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset this
|
// Reset this
|
||||||
@ -554,6 +576,10 @@ namespace NewHorizons
|
|||||||
{
|
{
|
||||||
ResetCurrentStarSystem();
|
ResetCurrentStarSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We only check previous when the scene unloads, and at that point current should be updated to the new system
|
||||||
|
NHLogger.LogVerbose($"Set the previous system to {CurrentStarSystem}");
|
||||||
|
_previousStarSystem = CurrentStarSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here
|
// Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here
|
||||||
@ -603,7 +629,7 @@ namespace NewHorizons
|
|||||||
if (starSystemName != "SolarSystem")
|
if (starSystemName != "SolarSystem")
|
||||||
{
|
{
|
||||||
SetDefaultSystem(starSystemName);
|
SetDefaultSystem(starSystemName);
|
||||||
_currentStarSystem = DefaultStarSystem;
|
CurrentStarSystem = DefaultStarSystem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +846,7 @@ namespace NewHorizons
|
|||||||
// If we're just on the title screen set the system for later
|
// If we're just on the title screen set the system for later
|
||||||
if (LoadManager.GetCurrentScene() == OWScene.TitleScreen)
|
if (LoadManager.GetCurrentScene() == OWScene.TitleScreen)
|
||||||
{
|
{
|
||||||
_currentStarSystem = newStarSystem;
|
CurrentStarSystem = newStarSystem;
|
||||||
IsWarpingFromShip = warp;
|
IsWarpingFromShip = warp;
|
||||||
IsWarpingFromVessel = vessel;
|
IsWarpingFromVessel = vessel;
|
||||||
DidWarpFromVessel = false;
|
DidWarpFromVessel = false;
|
||||||
@ -864,13 +890,13 @@ namespace NewHorizons
|
|||||||
{
|
{
|
||||||
PlayerData.SaveEyeCompletion(); // So that the title screen doesn't keep warping you back to eye
|
PlayerData.SaveEyeCompletion(); // So that the title screen doesn't keep warping you back to eye
|
||||||
|
|
||||||
if (SystemDict[_currentStarSystem].Config.enableTimeLoop) SecondsElapsedInLoop = TimeLoop.GetSecondsElapsed();
|
if (SystemDict[CurrentStarSystem].Config.enableTimeLoop) SecondsElapsedInLoop = TimeLoop.GetSecondsElapsed();
|
||||||
else SecondsElapsedInLoop = -1;
|
else SecondsElapsedInLoop = -1;
|
||||||
|
|
||||||
sceneToLoad = OWScene.SolarSystem;
|
sceneToLoad = OWScene.SolarSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentStarSystem = newStarSystem;
|
CurrentStarSystem = newStarSystem;
|
||||||
|
|
||||||
// Freeze player inputs
|
// Freeze player inputs
|
||||||
OWInput.ChangeInputMode(InputMode.None);
|
OWInput.ChangeInputMode(InputMode.None);
|
||||||
@ -890,7 +916,7 @@ namespace NewHorizons
|
|||||||
// We reset the solar system on death
|
// We reset the solar system on death
|
||||||
if (!IsChangingStarSystem)
|
if (!IsChangingStarSystem)
|
||||||
{
|
{
|
||||||
if (SystemDict[_currentStarSystem].Config.respawnHere) return;
|
if (SystemDict[CurrentStarSystem].Config.respawnHere) return;
|
||||||
|
|
||||||
ResetCurrentStarSystem();
|
ResetCurrentStarSystem();
|
||||||
}
|
}
|
||||||
@ -900,7 +926,7 @@ namespace NewHorizons
|
|||||||
{
|
{
|
||||||
if (SystemDict.ContainsKey(_defaultSystemOverride))
|
if (SystemDict.ContainsKey(_defaultSystemOverride))
|
||||||
{
|
{
|
||||||
_currentStarSystem = _defaultSystemOverride;
|
CurrentStarSystem = _defaultSystemOverride;
|
||||||
|
|
||||||
// Sometimes the override will not support spawning regularly, so always warp in
|
// Sometimes the override will not support spawning regularly, so always warp in
|
||||||
IsWarpingFromShip = true;
|
IsWarpingFromShip = true;
|
||||||
@ -913,7 +939,7 @@ namespace NewHorizons
|
|||||||
NHLogger.LogError($"The given default system override {_defaultSystemOverride} is invalid - no system exists with that name");
|
NHLogger.LogError($"The given default system override {_defaultSystemOverride} is invalid - no system exists with that name");
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentStarSystem = _defaultStarSystem;
|
CurrentStarSystem = _defaultStarSystem;
|
||||||
IsWarpingFromShip = false;
|
IsWarpingFromShip = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,10 +12,10 @@ namespace NewHorizons.Patches.EyeScenePatches
|
|||||||
PlayerData.SaveEyeCompletion();
|
PlayerData.SaveEyeCompletion();
|
||||||
|
|
||||||
// Switch to default just in case another mod warps back.
|
// Switch to default just in case another mod warps back.
|
||||||
if (Main.Instance.CurrentStarSystem == "EyeOfTheUniverse") Main.Instance._currentStarSystem = Main.Instance.DefaultStarSystem;
|
if (Main.Instance.CurrentStarSystem == "EyeOfTheUniverse") Main.Instance.CurrentStarSystem = Main.Instance.DefaultStarSystem;
|
||||||
}
|
}
|
||||||
// Switch to eye just in case another mod warps there.
|
// Switch to eye just in case another mod warps there.
|
||||||
else if (scene == OWScene.EyeOfTheUniverse) Main.Instance._currentStarSystem = "EyeOfTheUniverse";
|
else if (scene == OWScene.EyeOfTheUniverse) Main.Instance.CurrentStarSystem = "EyeOfTheUniverse";
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
|
|||||||
@ -1,15 +1,22 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using NewHorizons.Handlers;
|
||||||
|
|
||||||
namespace NewHorizons.Patches.ProxyPatches
|
namespace NewHorizons.Patches.ProxyPatches;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(ProxyBody))]
|
||||||
|
public static class ProxyBodyPatches
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(ProxyBody))]
|
[HarmonyPostfix]
|
||||||
public static class ProxyBodyPatches
|
[HarmonyPatch(nameof(ProxyBody.LateInitialize))]
|
||||||
|
public static void ProxyBody_LateInitialize(ProxyBody __instance)
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
ProxyHandler.RegisterVanillaProxyBody(__instance);
|
||||||
[HarmonyPatch(nameof(ProxyBody.IsObjectInSupernova))]
|
}
|
||||||
public static bool ProxyBody_IsObjectInSupernova(ProxyBody __instance)
|
|
||||||
{
|
[HarmonyPrefix]
|
||||||
return Locator.GetSunController() != null;
|
[HarmonyPatch(nameof(ProxyBody.IsObjectInSupernova))]
|
||||||
}
|
public static bool ProxyBody_IsObjectInSupernova(ProxyBody __instance)
|
||||||
|
{
|
||||||
|
return Locator.GetSunController() != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
NewHorizons/Patches/ProxyPatches/ProxyOrbiterPatches.cs
Normal file
15
NewHorizons/Patches/ProxyPatches/ProxyOrbiterPatches.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using NewHorizons.Handlers;
|
||||||
|
|
||||||
|
namespace NewHorizons.Patches.ProxyPatches;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(ProxyOrbiter))]
|
||||||
|
public static class ProxyOrbiterPatches
|
||||||
|
{
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(nameof(ProxyOrbiter.SetOriginalBodies))]
|
||||||
|
public static void ProxyOrbiter_SetOriginalBodies(ProxyOrbiter __instance)
|
||||||
|
{
|
||||||
|
ProxyHandler.RegisterVanillaProxyOrbiter(__instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -63,7 +63,7 @@ namespace NewHorizons.Patches.WarpPatches
|
|||||||
Locator.GetPauseCommandListener().AddPauseCommandLock();
|
Locator.GetPauseCommandListener().AddPauseCommandLock();
|
||||||
if (canWarpToEye || canWarpToStarSystem && targetSystem == "EyeOfTheUniverse")
|
if (canWarpToEye || canWarpToStarSystem && targetSystem == "EyeOfTheUniverse")
|
||||||
{
|
{
|
||||||
Main.Instance._currentStarSystem = "EyeOfTheUniverse";
|
Main.Instance.CurrentStarSystem = "EyeOfTheUniverse";
|
||||||
LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, false, LoadManager.FadeType.ToWhite);
|
LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, false, LoadManager.FadeType.ToWhite);
|
||||||
}
|
}
|
||||||
else if (canWarpToStarSystem)
|
else if (canWarpToStarSystem)
|
||||||
|
|||||||
@ -10,11 +10,13 @@ namespace NewHorizons.Utility
|
|||||||
public static class SearchUtilities
|
public static class SearchUtilities
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<string, GameObject> CachedGameObjects = new Dictionary<string, GameObject>();
|
private static readonly Dictionary<string, GameObject> CachedGameObjects = new Dictionary<string, GameObject>();
|
||||||
|
private static readonly Dictionary<string, GameObject> CachedRootGameObjects = new Dictionary<string, GameObject>();
|
||||||
|
|
||||||
public static void ClearCache()
|
public static void ClearCache()
|
||||||
{
|
{
|
||||||
NHLogger.LogVerbose("Clearing search cache");
|
NHLogger.LogVerbose("Clearing search cache");
|
||||||
CachedGameObjects.Clear();
|
CachedGameObjects.Clear();
|
||||||
|
CachedRootGameObjects.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<T> FindObjectsOfTypeAndName<T>(string name) where T : Object
|
public static List<T> FindObjectsOfTypeAndName<T>(string name) where T : Object
|
||||||
@ -107,8 +109,16 @@ namespace NewHorizons.Utility
|
|||||||
// 2: find inactive using root + transform.find
|
// 2: find inactive using root + transform.find
|
||||||
var names = path.Split('/');
|
var names = path.Split('/');
|
||||||
|
|
||||||
|
// Cache the root objects so we don't loop through all of them each time
|
||||||
var rootName = names[0];
|
var rootName = names[0];
|
||||||
var root = SceneManager.GetActiveScene().GetRootGameObjects().FirstOrDefault(x => x.name == rootName);
|
if (!CachedRootGameObjects.TryGetValue(rootName, out var root))
|
||||||
|
{
|
||||||
|
root = SceneManager.GetActiveScene().GetRootGameObjects().FirstOrDefault(x => x.name == rootName);
|
||||||
|
if (root != null)
|
||||||
|
{
|
||||||
|
CachedRootGameObjects.Add(rootName, root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var childPath = string.Join("/", names.Skip(1));
|
var childPath = string.Join("/", names.Skip(1));
|
||||||
go = root ? root.FindChild(childPath) : null;
|
go = root ? root.FindChild(childPath) : null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user