Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Biome Handler #511

Merged
merged 19 commits into from
Dec 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Horrible code to fix horrible bugs (lose-lose)
  • Loading branch information
LeeTwentyThree committed Dec 19, 2023
commit f8db749e7270ff9beeec72a406fe2d4a7d75574d
90 changes: 81 additions & 9 deletions Nautilus/Utility/BiomeUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using mset;
using System;
using mset;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Nautilus.Utility;

Expand Down Expand Up @@ -42,17 +44,20 @@ public static WaterscapeVolume.Settings CreateBiomeSettings(Vector3 absorption,
};
}

private static GameObject _skyPrefabsParent;
// DO NOT BLAME ME FOR THIS HORRIBLE CODE - SERIALIZE FIELD COMPONENTS HAVE VERY WEIRD BEHAVIOR IN OUR MODS!

private static GameObject _skyPrefabsParent;

/// <summary>
/// Creates a new basic Sky prefab.
/// </summary>
/// <param name="name">The name of the Sky, can be anything.</param>
/// <param name="specularCube">The texture of the Sky, VERY important in determining reflections.</param>
/// <param name="affectedByDayNightCycle">If true, the Sky will appear darker at night and brighter at day.</param>
/// <param name="outdoors">Whether this sky is outdoors or not (should be false for the interiors of player-made structures).</param>
/// <returns></returns>
public static Sky CreateSkyPrefab(string name, Texture specularCube, bool affectedByDayNightCycle = true, bool outdoors = true)
/// <returns>The SkyPrefabFixer component for further modification (this is necessary to get around a Unity bug).</returns>
public static SkyPrefabFixer CreateSkyPrefab(string name, Texture specularCube, bool affectedByDayNightCycle = true,
bool outdoors = true)
{
if (_skyPrefabsParent == null)
{
Expand All @@ -65,12 +70,79 @@ public static Sky CreateSkyPrefab(string name, Texture specularCube, bool affect
var skyObject = new GameObject(name);
skyObject.transform.parent = _skyPrefabsParent.transform;
skyObject.AddComponent<SceneCleanerPreserve>();

var sky = skyObject.AddComponent<Sky>();
sky.specularCube = specularCube;
sky.affectedByDayNightCycle = affectedByDayNightCycle;
sky.outdoors = outdoors;

var skyPrefabFixer = skyObject.AddComponent<SkyPrefabFixer>();
skyPrefabFixer.sky = sky;
skyPrefabFixer.specularCube = specularCube;
skyPrefabFixer.affectedByDayNightCycle = affectedByDayNightCycle;
skyPrefabFixer.outdoors = outdoors;

return sky;
return skyPrefabFixer;
}

/// <summary>
/// Wrapper class that contains all Sky properties, which are automatically assigned. Necessary for our purposes because fields with SerializeField do not have their values saved when they are instantiated. Yes, everything HAS to be public!
/// </summary>
public class SkyPrefabFixer : MonoBehaviour
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public Sky sky;

public Texture specularCube;

public Bounds dimensions = new Bounds(Vector3.zero, Vector3.one);

public bool affectedByDayNightCycle = true;

public bool outdoors = true;

public float masterIntensity = 1f;

public float skyIntensity = 1f;

public float specIntensity = 1f;

public float diffIntensity = 1f;

public float camExposure = 1f;

public float specIntensityLM = 0.2f;

public float diffIntensityLM = 0.05f;

public bool hdrSky = true;

public bool hdrSpec = true;

public bool linearSpace = true;

public bool autoDetectColorSpace = true;

public bool hasDimensions;
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

private void OnEnable()
{
if (sky == null) return;
sky.specularCube = specularCube;
sky.dimensions = dimensions;
sky.affectedByDayNightCycle = affectedByDayNightCycle;
sky.outdoors = outdoors;
sky.masterIntensity = masterIntensity;
sky.skyIntensity = skyIntensity;
sky.diffIntensity = diffIntensity;
sky.camExposure = camExposure;
sky.specIntensity = specIntensity;
sky.specIntensityLM = specIntensityLM;
sky.diffIntensityLM = diffIntensityLM;
sky.hdrSky = hdrSky;
sky.hdrSpec = hdrSpec;
sky.linearSpace = linearSpace;
sky.autoDetectColorSpace = autoDetectColorSpace;
sky.hasDimensions = hasDimensions;
}
}

}