Skip to content

Commit

Permalink
Add skybox switcher component
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyDuchess committed Dec 31, 2024
1 parent 7e9da2d commit 937f5f3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions MapStation.Common/Runtime/MapOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions MapStation.Common/Runtime/SkyboxSwitcher.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
11 changes: 11 additions & 0 deletions MapStation.Common/Runtime/SkyboxSwitcher.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 937f5f3

Please sign in to comment.