From 937f5f3181e59845a88d0a999ac91d953dc00583 Mon Sep 17 00:00:00 2001 From: Nahuel Rocchetti Date: Tue, 31 Dec 2024 12:13:45 -0300 Subject: [PATCH] Add skybox switcher component --- MapStation.Common/Runtime/MapOptions.cs | 4 ++ MapStation.Common/Runtime/SkyboxSwitcher.cs | 39 +++++++++++++++++++ .../Runtime/SkyboxSwitcher.cs.meta | 11 ++++++ 3 files changed, 54 insertions(+) create mode 100644 MapStation.Common/Runtime/SkyboxSwitcher.cs create mode 100644 MapStation.Common/Runtime/SkyboxSwitcher.cs.meta diff --git a/MapStation.Common/Runtime/MapOptions.cs b/MapStation.Common/Runtime/MapOptions.cs index d1ece23..c41b591 100644 --- a/MapStation.Common/Runtime/MapOptions.cs +++ b/MapStation.Common/Runtime/MapOptions.cs @@ -29,6 +29,10 @@ public class MapOption { public Camera PreviewCamera; } + private void Awake() { + _instance = this; + } + public string GetDefaultOption(string optionName) { foreach(var option in Options) { if (option.Name == optionName) diff --git a/MapStation.Common/Runtime/SkyboxSwitcher.cs b/MapStation.Common/Runtime/SkyboxSwitcher.cs new file mode 100644 index 0000000..08198ed --- /dev/null +++ b/MapStation.Common/Runtime/SkyboxSwitcher.cs @@ -0,0 +1,39 @@ +using Reptile; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace MapStation.Common.Runtime { + public class SkyboxSwitcher : MonoBehaviour { + [Header("Changes the skybox when enabled.")] + public Material Skybox; + private Material _oldSkybox; +#if BEPINEX + private void Awake() { + StageManager.OnStageInitialized += StageInitialized; + } + + private void OnDestroy() { + StageManager.OnStageInitialized -= StageInitialized; + } + + private void StageInitialized() { + if (isActiveAndEnabled) + OnEnable(); + } +#endif + + private void OnEnable() { + _oldSkybox = RenderSettings.skybox; + RenderSettings.skybox = Skybox; + } + + private void OnDisable() { + if (RenderSettings.skybox == Skybox) + RenderSettings.skybox = _oldSkybox; + } + } +} diff --git a/MapStation.Common/Runtime/SkyboxSwitcher.cs.meta b/MapStation.Common/Runtime/SkyboxSwitcher.cs.meta new file mode 100644 index 0000000..54bcfe6 --- /dev/null +++ b/MapStation.Common/Runtime/SkyboxSwitcher.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: db3f880a601896a439466c9cd35fe501 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: