new-horizons/NewHorizons/Handlers/SystemCreationHandler.cs
2022-07-23 18:19:04 -05:00

50 lines
1.8 KiB
C#

using NewHorizons.Builder.StarSystem;
using NewHorizons.Components;
using NewHorizons.Utility;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
using Object = UnityEngine.Object;
namespace NewHorizons.Handlers
{
public static class SystemCreationHandler
{
public static void LoadSystem(NewHorizonsSystem system)
{
var skybox = SearchUtilities.Find("Skybox/Starfield");
if (system.Config.Skybox?.destroyStarField ?? false)
{
Object.Destroy(skybox);
}
if (system.Config.Skybox?.rightPath != null ||
system.Config.Skybox?.leftPath != null ||
system.Config.Skybox?.topPath != null ||
system.Config.Skybox?.bottomPath != null ||
system.Config.Skybox?.frontPath != null ||
system.Config.Skybox?.bottomPath != null)
{
SkyboxBuilder.Make(system.Config.Skybox, system.Mod);
}
#pragma warning disable CS0618, CS0612 // Type or member is obsolete
if (system.Config.skybox?.assetBundle != null && system.Config.skybox?.path != null)
{
SkyboxBuilder.Make(system.Config.skybox, system.Mod);
}
#pragma warning restore CS0618, CS0612 // Type or member is obsolete
if (system.Config.enableTimeLoop)
{
var timeLoopController = new GameObject("TimeLoopController");
timeLoopController.AddComponent<TimeLoopController>();
}
if (!string.IsNullOrEmpty(system.Config.travelAudio))
{
Delay.FireOnNextUpdate(() => AudioUtilities.SetAudioClip(Locator.GetGlobalMusicController()._travelSource, system.Config.travelAudio, system.Mod));
}
}
}
}