Fix star size in SunLightParamUpdater

This commit is contained in:
Nick 2023-08-23 00:14:45 -04:00
parent 41121fdc26
commit b3327f7ae6
3 changed files with 32 additions and 12 deletions

View File

@ -454,6 +454,8 @@ namespace NewHorizons.Components.SizeControllers
public float GetSupernovaRadius() => supernova.GetSupernovaRadius();
public float GetSurfaceRadius() => transform.localScale.x;
public float GetMaxSupernovaRadius() => supernovaSize;
protected new void FixedUpdate()

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.Atmosphere;
using NewHorizons.Components.SizeControllers;
using NewHorizons.Utility.OWML;
using System.Collections.Generic;
using UnityEngine;
@ -17,7 +18,11 @@ namespace NewHorizons.Components.Stars
private readonly List<StarController> _stars = new();
private readonly List<Light> _lights = new();
private StarController _activeStar;
// SunController or StarEvolutionController
public StarEvolutionController ActiveStarEvolutionController { get; private set; }
public SunController ActiveSunController { get; private set; }
private StarController _activeStarController;
private SunLightController _sunLightController;
private SunLightParamUpdater _sunLightParamUpdater;
@ -54,7 +59,7 @@ namespace NewHorizons.Components.Stars
NHLogger.LogVerbose($"Removing star from list: {star?.gameObject?.name}");
if (Instance._stars.Contains(star))
{
if (Instance._activeStar != null && Instance._activeStar.Equals(star))
if (Instance._activeStarController != null && Instance._activeStarController.Equals(star))
{
Instance._stars.Remove(star);
if (Instance._stars.Count > 0) Instance.ChangeActiveStar(Instance._stars[0]);
@ -121,11 +126,11 @@ namespace NewHorizons.Components.Stars
if (_stars.Count > 0)
{
if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy)
if (_activeStarController == null || !_activeStarController.gameObject.activeInHierarchy)
{
if (_stars.Contains(_activeStar))
if (_stars.Contains(_activeStarController))
{
_stars.Remove(_activeStar);
_stars.Remove(_activeStarController);
}
if (_stars.Count > 0)
@ -145,8 +150,8 @@ namespace NewHorizons.Components.Stars
// Update atmo shaders
foreach (var (planet, material) in AtmosphereBuilder.Skys)
{
var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude;
var intensity = Mathf.Min(_activeStar.Intensity / (sqrDist / hearthSunDistanceSqr), 1f);
var sqrDist = (planet.transform.position - _activeStarController.transform.position).sqrMagnitude;
var intensity = Mathf.Min(_activeStarController.Intensity / (sqrDist / hearthSunDistanceSqr), 1f);
material.SetFloat(SunIntensity, intensity);
}
@ -156,7 +161,7 @@ namespace NewHorizons.Components.Stars
if (star == null) continue;
if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue;
if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStar.Intensity * (_activeStar.transform.position - origin).sqrMagnitude)
if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStarController.Intensity * (_activeStarController.transform.position - origin).sqrMagnitude)
{
ChangeActiveStar(star);
break;
@ -170,11 +175,13 @@ namespace NewHorizons.Components.Stars
{
if (_sunLightController == null || _sunLightParamUpdater == null) return;
if (_activeStar != null) _activeStar.Disable();
_activeStarController?.Disable();
NHLogger.LogVerbose($"Switching active star: {star.gameObject.name}");
_activeStar = star;
_activeStarController = star;
ActiveStarEvolutionController = star.GetComponentInChildren<StarEvolutionController>();
ActiveSunController = star.GetComponent<SunController>();
star.Enable();

View File

@ -1,4 +1,5 @@
using HarmonyLib;
using NewHorizons.Components.Stars;
using UnityEngine;
namespace NewHorizons.Patches.SunPatches
{
@ -13,10 +14,20 @@ namespace NewHorizons.Patches.SunPatches
{
Vector3 position = __instance.transform.position;
float w = 2000f;
if (__instance._sunController != null)
var sunController = SunLightEffectsController.Instance.ActiveSunController;
var starEvolutionController = SunLightEffectsController.Instance.ActiveStarEvolutionController;
if (sunController != null)
{
w = __instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius();
w = sunController.HasSupernovaStarted() ? sunController.GetSupernovaRadius() : sunController.GetSurfaceRadius();
}
// This is an addition in this patch, to work with our stars
else if (starEvolutionController != null)
{
w = starEvolutionController.HasSupernovaStarted() ? starEvolutionController.GetSupernovaRadius() : starEvolutionController.GetSurfaceRadius();
}
float range = __instance.sunLight.range;
Color color = __instance._sunLightController != null ? __instance._sunLightController.sunColor : __instance.sunLight.color;
float w2 = __instance._sunLightController != null ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity;