Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
JohnCorby 2022-07-13 21:15:04 -07:00
commit 434cb6cbb5
23 changed files with 147 additions and 40 deletions

View File

@ -44,9 +44,9 @@ namespace NewHorizons.Builder.Body
cloakSectorController.EnableCloak(); cloakSectorController.EnableCloak();
// To cloak from the start // To cloak from the start
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit); Delay.FireOnNextUpdate(cloakSectorController.OnPlayerExit);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(hasCustomAudio ? cloakSectorController.TurnOnMusic : cloakSectorController.TurnOffMusic); Delay.FireOnNextUpdate(hasCustomAudio ? cloakSectorController.TurnOnMusic : cloakSectorController.TurnOffMusic);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(keepReferenceFrame ? cloakSectorController.EnableReferenceFrameVolume : cloakSectorController.DisableReferenceFrameVolume); Delay.FireOnNextUpdate(keepReferenceFrame ? cloakSectorController.EnableReferenceFrameVolume : cloakSectorController.DisableReferenceFrameVolume);
} }
} }
} }

View File

@ -159,7 +159,7 @@ namespace NewHorizons.Builder.Body
funnelSizeController.anchor = planetGO.transform; funnelSizeController.anchor = planetGO.transform;
// Finish up next tick // Finish up next tick
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PostMake(funnelGO, funnelSizeController, module)); Delay.FireOnNextUpdate(() => PostMake(funnelGO, funnelSizeController, module));
} }
private static void PostMake(GameObject funnelGO, FunnelController funnelSizeController, FunnelModule module) private static void PostMake(GameObject funnelGO, FunnelController funnelSizeController, FunnelModule module)

View File

@ -55,7 +55,7 @@ namespace NewHorizons.Builder.Body
OLC._ambientLight = GDOLC._ambientLight; // this needs to be set or else is black OLC._ambientLight = GDOLC._ambientLight; // this needs to be set or else is black
// trigger sector enter // trigger sector enter
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Delay.FireOnNextUpdate(() =>
{ {
OEC._active = true; OEC._active = true;
OEC.enabled = true; OEC.enabled = true;

View File

@ -1,5 +1,6 @@
using NewHorizons.Components.Orbital; using NewHorizons.Components.Orbital;
using NewHorizons.External.Configs; using NewHorizons.External.Configs;
using NewHorizons.Utility;
using UnityEngine; using UnityEngine;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.General namespace NewHorizons.Builder.General
@ -51,7 +52,7 @@ namespace NewHorizons.Builder.General
{ {
Logger.Log($"Setting center of universe to {config.name}"); Logger.Log($"Setting center of universe to {config.name}");
Main.Instance.ModHelper.Events.Unity.RunWhen( Delay.RunWhen(
() => Locator._centerOfTheUniverse != null, () => Locator._centerOfTheUniverse != null,
() => Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent<OWRigidbody>() () => Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent<OWRigidbody>()
); );

View File

@ -78,7 +78,7 @@ namespace NewHorizons.Builder.General
if ((Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && module.startWithSuit)) && !suitUpQueued) if ((Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && module.startWithSuit)) && !suitUpQueued)
{ {
suitUpQueued = true; suitUpQueued = true;
Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => SuitUp()); Delay.RunWhen(() => Main.IsSystemReady, () => SuitUp());
} }
Logger.Log($"Made spawnpoint on [{planetGO.name}]"); Logger.Log($"Made spawnpoint on [{planetGO.name}]");

View File

@ -78,7 +78,7 @@ namespace NewHorizons.Builder.Orbital
orbitLine._numVerts = (int)Mathf.Clamp(config.Orbit.semiMajorAxis / 1000f, numVerts, 4096); orbitLine._numVerts = (int)Mathf.Clamp(config.Orbit.semiMajorAxis / 1000f, numVerts, 4096);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(orbitLine.InitializeLineRenderer); Delay.FireOnNextUpdate(orbitLine.InitializeLineRenderer);
return orbitLine; return orbitLine;
} }

View File

@ -125,7 +125,7 @@ namespace NewHorizons.Builder.Props
// Enable all children or something // Enable all children or something
// BUG doesnt work because enabled is a property, not a field // BUG doesnt work because enabled is a property, not a field
var enabledField = component?.GetType()?.GetField("enabled"); var enabledField = component?.GetType()?.GetField("enabled");
if (enabledField != null && enabledField.FieldType == typeof(bool)) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => enabledField.SetValue(component, true)); if (enabledField != null && enabledField.FieldType == typeof(bool)) Events.FireOnNextUpdate(() => enabledField.SetValue(component, true));
*/ */
// Fix a bunch of sector stuff // Fix a bunch of sector stuff
@ -167,7 +167,7 @@ namespace NewHorizons.Builder.Props
var sectorField = component?.GetType()?.GetField("_sector"); var sectorField = component?.GetType()?.GetField("_sector");
if (sectorField != null && sectorField.FieldType == typeof(Sector)) if (sectorField != null && sectorField.FieldType == typeof(Sector))
{ {
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => sectorField.SetValue(component, sector)); Events.FireOnNextUpdate(() => sectorField.SetValue(component, sector));
} }
} }
*/ */
@ -227,7 +227,7 @@ namespace NewHorizons.Builder.Props
} }
// Fix a bunch of stuff when done loading // Fix a bunch of stuff when done loading
Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => Delay.RunWhen(() => Main.IsSystemReady, () =>
{ {
try try
{ {

View File

@ -32,7 +32,7 @@ namespace NewHorizons.Builder.Props
var geyserFluidVolume = geyserGO.GetComponentInChildren<GeyserFluidVolume>(); var geyserFluidVolume = geyserGO.GetComponentInChildren<GeyserFluidVolume>();
// Do this after awake // Do this after awake
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => geyserFluidVolume._maxHeight = 1); Delay.FireOnNextUpdate(() => geyserFluidVolume._maxHeight = 1);
geyserFluidVolume.enabled = true; geyserFluidVolume.enabled = true;
geyserGO.transform.Find("FluidVolume_Geyser").GetComponent<CapsuleShape>().enabled = true; geyserGO.transform.Find("FluidVolume_Geyser").GetComponent<CapsuleShape>().enabled = true;

View File

@ -165,7 +165,7 @@ namespace NewHorizons.Builder.Props
customScroll.SetActive(true); customScroll.SetActive(true);
// Enable the collider and renderer // Enable the collider and renderer
Main.Instance.ModHelper.Events.Unity.RunWhen( Delay.RunWhen(
() => Main.IsSystemReady, () => Main.IsSystemReady,
() => () =>
{ {

View File

@ -83,7 +83,7 @@ namespace NewHorizons.Builder.Props
imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath); imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath);
AddModules(slideInfo, ref slide); AddModules(slideInfo, ref slide, mod);
slideCollection.slides[i] = slide; slideCollection.slides[i] = slide;
} }
@ -171,7 +171,7 @@ namespace NewHorizons.Builder.Props
imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath); imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath);
AddModules(slideInfo, ref slide); AddModules(slideInfo, ref slide, mod);
slideCollection.slides[i] = slide; slideCollection.slides[i] = slide;
} }
@ -218,7 +218,7 @@ namespace NewHorizons.Builder.Props
imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath); imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath);
AddModules(slideInfo, ref slide); AddModules(slideInfo, ref slide, mod);
slideCollection.slides[i] = slide; slideCollection.slides[i] = slide;
} }
@ -282,7 +282,7 @@ namespace NewHorizons.Builder.Props
imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath); imageLoader.pathsToLoad.Add(mod.ModHelper.Manifest.ModFolderPath + slideInfo.imagePath);
AddModules(slideInfo, ref slide); AddModules(slideInfo, ref slide, mod);
slideCollection.slides[i] = slide; slideCollection.slides[i] = slide;
} }
@ -322,20 +322,20 @@ namespace NewHorizons.Builder.Props
return standingTorch; return standingTorch;
} }
private static void AddModules(PropModule.SlideInfo slideInfo, ref Slide slide) private static void AddModules(PropModule.SlideInfo slideInfo, ref Slide slide, IModBehaviour mod)
{ {
var modules = new List<SlideFunctionModule>(); var modules = new List<SlideFunctionModule>();
if (!String.IsNullOrEmpty(slideInfo.beatAudio)) if (!String.IsNullOrEmpty(slideInfo.beatAudio))
{ {
var audioBeat = new SlideBeatAudioModule(); var audioBeat = new SlideBeatAudioModule();
audioBeat._audioType = (AudioType)Enum.Parse(typeof(AudioType), slideInfo.beatAudio); audioBeat._audioType = AudioTypeHandler.GetAudioType(slideInfo.beatAudio, mod);
audioBeat._delay = slideInfo.beatDelay; audioBeat._delay = slideInfo.beatDelay;
modules.Add(audioBeat); modules.Add(audioBeat);
} }
if (!String.IsNullOrEmpty(slideInfo.backdropAudio)) if (!String.IsNullOrEmpty(slideInfo.backdropAudio))
{ {
var audioBackdrop = new SlideBackdropAudioModule(); var audioBackdrop = new SlideBackdropAudioModule();
audioBackdrop._audioType = (AudioType)Enum.Parse(typeof(AudioType), slideInfo.backdropAudio); audioBackdrop._audioType = AudioTypeHandler.GetAudioType(slideInfo.backdropAudio, mod);
audioBackdrop._fadeTime = slideInfo.backdropFadeTime; audioBackdrop._fadeTime = slideInfo.backdropFadeTime;
modules.Add(audioBackdrop); modules.Add(audioBackdrop);
} }

View File

@ -29,7 +29,7 @@ namespace NewHorizons.Builder.Props
{ {
heightMapTexture = ImageUtilities.GetTexture(mod, heightMap.heightMap); heightMapTexture = ImageUtilities.GetTexture(mod, heightMap.heightMap);
// defer remove texture to next frame // defer remove texture to next frame
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Object.Destroy(heightMapTexture)); Delay.FireOnNextUpdate(() => Object.Destroy(heightMapTexture));
} }
catch (Exception) { } catch (Exception) { }
if (heightMapTexture == null) if (heightMapTexture == null)

View File

@ -118,7 +118,7 @@ namespace NewHorizons.Builder.Props
// Resize the distance it can be heard from to match roughly with the size // Resize the distance it can be heard from to match roughly with the size
var maxDistance = info.audioDistance; var maxDistance = info.audioDistance;
if (maxDistance <= 0) maxDistance = scale * 10f; if (maxDistance <= 0) maxDistance = scale * 10f;
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Delay.FireOnNextUpdate(() =>
{ {
audioSource.maxDistance = maxDistance; audioSource.maxDistance = maxDistance;
audioSource.minDistance = maxDistance / 10f; audioSource.minDistance = maxDistance / 10f;

View File

@ -37,7 +37,7 @@ namespace NewHorizons.Builder.Props
launcherGO.SetActive(true); launcherGO.SetActive(true);
// Have to null check else it breaks on reload configs // Have to null check else it breaks on reload configs
Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady && meteorLauncher._meteorPool != null, () => Delay.RunWhen(() => Main.IsSystemReady && meteorLauncher._meteorPool != null, () =>
{ {
foreach (var meteor in meteorLauncher._meteorPool) foreach (var meteor in meteorLauncher._meteorPool)
{ {

View File

@ -114,7 +114,7 @@ namespace NewHorizons.Components
if (name.Length > 17) textComponent.fontSize = 10; if (name.Length > 17) textComponent.fontSize = 10;
// Do it next frame // Do it next frame
var fontPath = "Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot/TH_VILLAGE/EntryCardRoot/NameBackground/Name"; var fontPath = "Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot/TH_VILLAGE/EntryCardRoot/NameBackground/Name";
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => textComponent.font = SearchUtilities.Find(fontPath).GetComponent<Text>().font); Delay.FireOnNextUpdate(() => textComponent.font = SearchUtilities.Find(fontPath).GetComponent<Text>().font);
newCard.SetActive(true); newCard.SetActive(true);
newCard.transform.name = uniqueID; newCard.transform.name = uniqueID;

View File

@ -121,7 +121,7 @@ namespace NewHorizons.Components
{ {
if (_isWarpingIn && LateInitializerManager.isDoneInitializing) if (_isWarpingIn && LateInitializerManager.isDoneInitializing)
{ {
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => StartWarpInEffect(), 1); Delay.FireInNUpdates(() => StartWarpInEffect(), 1);
_isWarpingIn = false; _isWarpingIn = false;
} }
@ -139,7 +139,7 @@ namespace NewHorizons.Components
// Idk whats making this work but now it works and idc // Idk whats making this work but now it works and idc
if (_waitingToBeSeated && PlayerState.IsInsideShip() && _eyesOpen) if (_waitingToBeSeated && PlayerState.IsInsideShip() && _eyesOpen)
{ {
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => FinishWarpIn(), 1); Delay.FireInNUpdates(() => FinishWarpIn(), 1);
_waitingToBeSeated = false; _waitingToBeSeated = false;
} }
} }
@ -174,7 +174,7 @@ namespace NewHorizons.Components
Logger.LogVerbose("Finishing warp"); Logger.LogVerbose("Finishing warp");
Locator.GetShipBody().GetComponentInChildren<ShipCockpitController>().OnPressInteract(); Locator.GetShipBody().GetComponentInChildren<ShipCockpitController>().OnPressInteract();
_waitingToBeSeated = false; _waitingToBeSeated = false;
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => _whitehole.Collapse(), 30); Delay.FireInNUpdates(() => _whitehole.Collapse(), 30);
var resources = Locator.GetPlayerTransform().GetComponent<PlayerResources>(); var resources = Locator.GetPlayerTransform().GetComponent<PlayerResources>();

View File

@ -346,7 +346,7 @@ namespace NewHorizons.External.Configs
if (Props.signals == null) Props.signals = new SignalModule.SignalInfo[0]; if (Props.signals == null) Props.signals = new SignalModule.SignalInfo[0];
Props.signals = Props.signals.Concat(Signal.signals).ToArray(); Props.signals = Props.signals.Concat(Signal.signals).ToArray();
} }
// Signals no longer use two differen variables for audio // Signals no longer use two different variables for audio
if (Props?.signals != null) if (Props?.signals != null)
{ {
foreach (var signal in Props.signals) foreach (var signal in Props.signals)

View File

@ -1,3 +1,4 @@
using System;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@ -50,10 +51,10 @@ namespace NewHorizons.External.Configs
/// </summary> /// </summary>
public bool startHere; public bool startHere;
[System.Obsolete("travelAudioClip is deprecated, please use travelAudio instead")] [Obsolete("travelAudioClip is deprecated, please use travelAudio instead")]
public string travelAudioClip; public string travelAudioClip;
[System.Obsolete("travelAudioFilePath is deprecated, please use travelAudio instead")] [Obsolete("travelAudioFilePath is deprecated, please use travelAudio instead")]
public string travelAudioFilePath; public string travelAudioFilePath;
/// <summary> /// <summary>

View File

@ -0,0 +1,91 @@
using NewHorizons.Utility;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Handlers
{
public static class AudioTypeHandler
{
private static Dictionary<string, AudioType> _customAudioTypes;
private static List<AudioLibrary.AudioEntry> _audioEntries;
private static int _startingInt = 4000;
public static void Init()
{
_customAudioTypes = new Dictionary<string, AudioType>();
_audioEntries = new List<AudioLibrary.AudioEntry>();
Delay.RunWhen(
() => Locator.GetAudioManager()?._libraryAsset != null,
PostInit
);
}
private static void PostInit()
{
Logger.LogVerbose($"Adding all custom AudioTypes to the library");
var library = Locator.GetAudioManager()._libraryAsset;
library.audioEntries = library.audioEntries.Concat(_audioEntries).ToArray();
Locator.GetAudioManager()._audioLibraryDict = library.BuildAudioEntryDictionary();
}
// Will return an existing audio type or create a new one for the given audio string
public static AudioType GetAudioType(string audio, IModBehaviour mod)
{
try
{
if (audio.Contains(".wav") || audio.Contains(".mp3") || audio.Contains(".ogg"))
{
return AddCustomAudioType(audio, mod);
}
else
{
return (AudioType)Enum.Parse(typeof(AudioType), audio);
}
}
catch (Exception e)
{
Logger.LogError($"Couldn't load AudioType {e.Message}, {e.StackTrace}");
return AudioType.None;
}
}
// Create a custom audio type from relative file path and the mod
public static AudioType AddCustomAudioType(string audioPath, IModBehaviour mod)
{
AudioType audioType;
var id = mod.ModHelper.Manifest.UniqueName + "_" + audioPath;
if (_customAudioTypes.TryGetValue(id, out audioType)) return audioType;
var audioClip = AudioUtilities.LoadAudio(mod.ModHelper.Manifest.ModFolderPath + "/" + audioPath);
if (audioClip == null)
{
Logger.LogError($"Couldn't create audioType for {audioPath}");
return AudioType.None;
}
return AddCustomAudioType(id, new AudioClip[] { audioClip });
}
// Create a custom audio type from a set of audio clips. Needs a unique ID
public static AudioType AddCustomAudioType(string id, AudioClip[] audioClips)
{
var audioType = (AudioType)_startingInt + _customAudioTypes.Count();
Logger.LogVerbose($"Registering custom audio type {id} as {audioType}");
_audioEntries.Add(new AudioLibrary.AudioEntry(audioType, audioClips));
_customAudioTypes.Add(id, audioType);
return audioType;
}
}
}

View File

@ -138,7 +138,7 @@ namespace NewHorizons.Handlers
Logger.Log("Done loading bodies"); Logger.Log("Done loading bodies");
// Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies); // Events.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies);
if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestructionHandler.RemoveSolarSystem(); if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestructionHandler.RemoveSolarSystem();
} }
@ -164,8 +164,8 @@ namespace NewHorizons.Handlers
if (body.Config.destroy) if (body.Config.destroy)
{ {
var ao = existingPlanet.GetComponent<AstroObject>(); var ao = existingPlanet.GetComponent<AstroObject>();
if (ao != null) Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestructionHandler.RemoveBody(ao), 2); if (ao != null) Delay.FireInNUpdates(() => PlanetDestructionHandler.RemoveBody(ao), 2);
else Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 2); else Delay.FireInNUpdates(() => existingPlanet.SetActive(false), 2);
} }
else if (body.Config.isQuantumState) else if (body.Config.isQuantumState)
{ {
@ -279,7 +279,7 @@ namespace NewHorizons.Handlers
{ {
// We purposefully use GameObject.Find here because we don't want to find inactive things. // We purposefully use GameObject.Find here because we don't want to find inactive things.
// If you were to try and disable two children with the same name, if we were finding inactive then we'd disable the first one twice // If you were to try and disable two children with the same name, if we were finding inactive then we'd disable the first one twice
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.Find(go.name + "/" + child)?.SetActive(false), 2); Delay.FireInNUpdates(() => GameObject.Find(go.name + "/" + child)?.SetActive(false), 2);
} }
} }
@ -417,7 +417,7 @@ namespace NewHorizons.Handlers
if (body.Config.Orbit.showOrbitLine && !body.Config.Orbit.isStatic) if (body.Config.Orbit.showOrbitLine && !body.Config.Orbit.isStatic)
{ {
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => OrbitlineBuilder.Make(body.Object, ao as NHAstroObject, body.Config.Orbit.isMoon, body.Config)); Delay.FireOnNextUpdate(() => OrbitlineBuilder.Make(body.Object, ao as NHAstroObject, body.Config.Orbit.isMoon, body.Config));
} }
if (!body.Config.Orbit.isStatic) if (!body.Config.Orbit.isStatic)
@ -429,7 +429,7 @@ namespace NewHorizons.Handlers
if (!(body.Config.Cloak != null && body.Config.Cloak.radius != 0f)) if (!(body.Config.Cloak != null && body.Config.Cloak.radius != 0f))
{ {
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Delay.FireOnNextUpdate(() =>
{ {
ProxyBuilder.Make(go, body); ProxyBuilder.Make(go, body);
}); });

View File

@ -54,12 +54,12 @@ namespace NewHorizons.Handlers
foreach (var name in _solarSystemBodies) foreach (var name in _solarSystemBodies)
{ {
var ao = AstroObjectLocator.GetAstroObject(name); var ao = AstroObjectLocator.GetAstroObject(name);
if (ao != null) Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => RemoveBody(ao, false), 2); if (ao != null) Delay.FireInNUpdates(() => RemoveBody(ao, false), 2);
else Logger.LogError($"Couldn't find [{name}]"); else Logger.LogError($"Couldn't find [{name}]");
} }
// Bring the sun back because why not // Bring the sun back because why not
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 3); Delay.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 3);
} }
public static void RemoveBody(AstroObject ao, bool delete = false, List<AstroObject> toDestroy = null) public static void RemoveBody(AstroObject ao, bool delete = false, List<AstroObject> toDestroy = null)
@ -198,7 +198,7 @@ namespace NewHorizons.Handlers
} }
RemoveProxy(ao.name.Replace("_Body", "")); RemoveProxy(ao.name.Replace("_Body", ""));
Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => DisableBody(ao.gameObject, delete)); Delay.RunWhen(() => Main.IsSystemReady, () => DisableBody(ao.gameObject, delete));
foreach (ProxyBody proxy in GameObject.FindObjectsOfType<ProxyBody>()) foreach (ProxyBody proxy in GameObject.FindObjectsOfType<ProxyBody>())
{ {

View File

@ -30,7 +30,7 @@ namespace NewHorizons.Handlers
if (!string.IsNullOrEmpty(system.Config.travelAudio)) if (!string.IsNullOrEmpty(system.Config.travelAudio))
{ {
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => AudioUtilities.SetAudioClip(Locator.GetGlobalMusicController()._travelSource, system.Config.travelAudio, system.Mod)); Delay.FireOnNextUpdate(() => AudioUtilities.SetAudioClip(Locator.GetGlobalMusicController()._travelSource, system.Config.travelAudio, system.Mod));
} }
} }
} }

View File

@ -273,7 +273,10 @@ namespace NewHorizons
BrambleNodeBuilder.Init(); BrambleNodeBuilder.Init();
AstroObjectLocator.Init(); AstroObjectLocator.Init();
StreamingHandler.Init(); StreamingHandler.Init();
AudioTypeHandler.Init();
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]); PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
VesselWarpHandler.LoadVessel(); VesselWarpHandler.LoadVessel();
SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]); SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]);
LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this); LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this);

View File

@ -0,0 +1,11 @@
using System;
namespace NewHorizons.Utility
{
public static class Delay
{
public static void RunWhen(Func<bool> predicate, Action action) => Main.Instance.ModHelper.Events.Unity.RunWhen(predicate, action);
public static void FireInNUpdates(Action action, int n) => Main.Instance.ModHelper.Events.Unity.FireInNUpdates(action, n);
public static void FireOnNextUpdate(Action action) => Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(action);
}
}