Refactor (description)

Refactor proxies, fix named, create proxy remnants, don't let focal points be destroyed by stars
This commit is contained in:
Nick 2022-08-25 01:05:16 -04:00
parent bd405f92dc
commit 5fe7630f48
11 changed files with 300 additions and 195 deletions

View File

@ -8,6 +8,7 @@ using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
using NewHorizons.External.Modules.VariableSize;
using NewHorizons.Handlers;
using System.Collections.Generic;
namespace NewHorizons.Builder.Body
{
@ -15,40 +16,60 @@ namespace NewHorizons.Builder.Body
{
private static Material lavaMaterial;
private static GameObject _blackHolePrefab;
private static GameObject _whiteHolePrefab;
private static readonly string _blackHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity";
private static readonly string _whiteHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity";
private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");
private static readonly int Radius = Shader.PropertyToID("_Radius");
private static readonly int MaxDistortRadius = Shader.PropertyToID("_MaxDistortRadius");
private static readonly int MassScale = Shader.PropertyToID("_MassScale");
private static readonly int DistortFadeDist = Shader.PropertyToID("_DistortFadeDist");
private static readonly int Color1 = Shader.PropertyToID("_Color");
public static void Make(GameObject planetGO, NewHorizonsBody body)
public static void Make(GameObject planetGO, NewHorizonsBody body, NewHorizonsBody remnant)
{
if (lavaMaterial == null) lavaMaterial = SearchUtilities.FindObjectOfTypeAndName<ProxyOrbiter>("VolcanicMoon_Body").transform.Find("LavaSphere").GetComponent<MeshRenderer>().material;
var proxyController = ProxyHandler.GetProxy(body.Config.name);
var proxy = proxyController != null ? proxyController.gameObject : new GameObject($"{body.Config.name}_Proxy");
proxy.SetActive(false);
if (proxyController == null)
{
proxyController = proxy.AddComponent<NHProxy>();
proxyController.astroName = body.Config.name;
proxyController._planet = planetGO;
proxyController.planet = planetGO;
}
var success = SharedMake(planetGO, proxy, proxyController, body);
var rootProxy = new GameObject("Root");
rootProxy.transform.parent = proxy.transform;
rootProxy.transform.localPosition = Vector3.zero;
var success = SharedMake(planetGO, rootProxy, proxyController, body);
if (!success)
{
GameObject.Destroy(proxy);
return;
}
proxyController.root = rootProxy;
// Add remnants
if (remnant != null)
{
var remnantGO = new GameObject("Remnant");
remnantGO.transform.parent = proxy.transform;
remnantGO.transform.localPosition = Vector3.zero;
SharedMake(planetGO, remnantGO, proxyController, remnant);
proxyController.stellarRemnantGO = remnantGO;
}
else if (body.Config.Star != null)
{
Logger.LogVerbose($"Making remnant proxy");
var remnantGO = new GameObject("Remnant");
remnantGO.transform.parent = proxy.transform;
remnantGO.transform.localPosition = Vector3.zero;
StellarRemnantBuilder.MakeProxyRemnant(planetGO, remnantGO, body.Mod, body.Config.Star);
proxyController.stellarRemnantGO = remnantGO;
}
proxy.SetActive(true);
}
@ -76,6 +97,7 @@ namespace NewHorizons.Builder.Body
float fogCurveMaxVal = 0;
Renderer topClouds = null;
CloudLightningGenerator lightningGenerator = null;
if (body.Config.Atmosphere != null)
{
atmosphere = AtmosphereBuilder.Make(proxy, null, body.Config.Atmosphere, body.Config.Base.surfaceSize, true).GetComponentInChildren<MeshRenderer>();
@ -147,11 +169,11 @@ namespace NewHorizons.Builder.Body
{
if (singularity.type == SingularityModule.SingularityType.BlackHole)
{
MakeBlackHole(proxy, singularity.position, singularity.size, singularity.curve);
SingularityBuilder.MakeBlackHoleProxy(proxy, singularity.position, singularity.size, singularity.curve);
}
else
{
MakeWhiteHole(proxy, singularity.position, singularity.size, singularity.curve);
SingularityBuilder.MakeWhiteHoleProxy(proxy, singularity.position, singularity.size, singularity.curve);
}
if (realSize < singularity.size) realSize = singularity.size;
@ -199,11 +221,11 @@ namespace NewHorizons.Builder.Body
proxyController._atmosphere = atmosphere;
proxyController._fog = fog;
proxyController._fogCurveMaxVal = fogCurveMaxVal;
proxyController._topClouds = topClouds;
proxyController._lightningGenerator = lightningGenerator;
proxyController._supernovaPlanetEffectController = supernovaPlanetEffect;
proxyController.topClouds = topClouds;
proxyController.lightningGenerator = lightningGenerator;
proxyController.supernovaPlanetEffectController = supernovaPlanetEffect;
proxyController._realObjectDiameter = realSize;
proxyController._baseRealObjectDiameter = realSize;
proxyController.baseRealObjectDiameter = realSize;
}
return true;
@ -240,63 +262,5 @@ namespace NewHorizons.Builder.Body
sizeController.size = size;
return sizeController;
}
private static GameObject MakeBlackHole(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
{
if (_blackHolePrefab == null) _blackHolePrefab = SearchUtilities.Find(_blackHolePath);
var blackHoleShader = _blackHolePrefab.GetComponent<MeshRenderer>().material.shader;
if (blackHoleShader == null) blackHoleShader = _blackHolePrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;
var blackHoleRender = new GameObject("BlackHoleRender");
blackHoleRender.transform.parent = rootObject.transform;
if (position != null) blackHoleRender.transform.localPosition = position;
else blackHoleRender.transform.localPosition = Vector3.zero;
blackHoleRender.transform.localScale = Vector3.one * size;
var meshFilter = blackHoleRender.AddComponent<MeshFilter>();
meshFilter.mesh = _blackHolePrefab.GetComponent<MeshFilter>().mesh;
var meshRenderer = blackHoleRender.AddComponent<MeshRenderer>();
meshRenderer.material = new Material(blackHoleShader);
meshRenderer.material.SetFloat(Radius, size * 0.4f);
meshRenderer.material.SetFloat(MaxDistortRadius, size * 0.95f);
meshRenderer.material.SetFloat(MassScale, 1);
meshRenderer.material.SetFloat(DistortFadeDist, size * 0.55f);
if (curve != null) AddSizeController(blackHoleRender, curve, size);
blackHoleRender.SetActive(true);
return blackHoleRender;
}
private static GameObject MakeWhiteHole(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
{
if (_whiteHolePrefab == null) _whiteHolePrefab = SearchUtilities.Find(_whiteHolePath);
var whiteHoleShader = _whiteHolePrefab.GetComponent<MeshRenderer>().material.shader;
if (whiteHoleShader == null) whiteHoleShader = _whiteHolePrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;
var whiteHoleRenderer = new GameObject("WhiteHoleRenderer");
whiteHoleRenderer.transform.parent = rootObject.transform;
if (position != null) whiteHoleRenderer.transform.localPosition = position;
else whiteHoleRenderer.transform.localPosition = Vector3.zero;
whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f;
var meshFilter = whiteHoleRenderer.AddComponent<MeshFilter>();
meshFilter.mesh = _whiteHolePrefab.GetComponent<MeshFilter>().mesh;
var meshRenderer = whiteHoleRenderer.AddComponent<MeshRenderer>();
meshRenderer.material = new Material(whiteHoleShader);
meshRenderer.sharedMaterial.SetFloat(Radius, size * 0.4f);
meshRenderer.sharedMaterial.SetFloat(DistortFadeDist, size);
meshRenderer.sharedMaterial.SetFloat(MaxDistortRadius, size * 2.8f);
meshRenderer.sharedMaterial.SetColor(Color1, new Color(1.88f, 1.88f, 1.88f, 1f));
if (curve != null) AddSizeController(whiteHoleRenderer, curve, size);
whiteHoleRenderer.SetActive(true);
return whiteHoleRenderer;
}
}
}

View File

@ -15,6 +15,9 @@ namespace NewHorizons.Builder.Body
{
public static class SingularityBuilder
{
private static readonly string _blackHoleProxyPath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity";
private static readonly string _whiteHoleProxyPath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity";
private static GameObject _blackHoleProxyPrefab, _whiteHoleProxyPrefab;
private static Shader blackHoleShader = null;
private static Shader whiteHoleShader = null;
@ -283,5 +286,71 @@ namespace NewHorizons.Builder.Body
whiteHole.SetActive(true);
return whiteHole;
}
public static GameObject MakeBlackHoleProxy(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
{
if (_blackHoleProxyPrefab == null) _blackHoleProxyPrefab = SearchUtilities.Find(_blackHoleProxyPath);
var blackHoleShader = _blackHoleProxyPrefab.GetComponent<MeshRenderer>().material.shader;
if (blackHoleShader == null) blackHoleShader = _blackHoleProxyPrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;
var blackHoleRender = new GameObject("BlackHoleRender");
blackHoleRender.transform.parent = rootObject.transform;
if (position != null) blackHoleRender.transform.localPosition = position;
else blackHoleRender.transform.localPosition = Vector3.zero;
blackHoleRender.transform.localScale = Vector3.one * size;
var meshFilter = blackHoleRender.AddComponent<MeshFilter>();
meshFilter.mesh = _blackHoleProxyPrefab.GetComponent<MeshFilter>().mesh;
var meshRenderer = blackHoleRender.AddComponent<MeshRenderer>();
meshRenderer.material = new Material(blackHoleShader);
meshRenderer.material.SetFloat(Radius, size * 0.4f);
meshRenderer.material.SetFloat(MaxDistortRadius, size * 0.95f);
meshRenderer.material.SetFloat(MassScale, 1);
meshRenderer.material.SetFloat(DistortFadeDist, size * 0.55f);
if (curve != null) AddSizeController(blackHoleRender, curve, size);
blackHoleRender.SetActive(true);
return blackHoleRender;
}
public static GameObject MakeWhiteHoleProxy(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
{
if (_whiteHoleProxyPrefab == null) _whiteHoleProxyPrefab = SearchUtilities.Find(_whiteHoleProxyPath);
var whiteHoleShader = _whiteHoleProxyPrefab.GetComponent<MeshRenderer>().material.shader;
if (whiteHoleShader == null) whiteHoleShader = _whiteHoleProxyPrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;
var whiteHoleRenderer = new GameObject("WhiteHoleRenderer");
whiteHoleRenderer.transform.parent = rootObject.transform;
if (position != null) whiteHoleRenderer.transform.localPosition = position;
else whiteHoleRenderer.transform.localPosition = Vector3.zero;
whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f;
var meshFilter = whiteHoleRenderer.AddComponent<MeshFilter>();
meshFilter.mesh = _whiteHoleProxyPrefab.GetComponent<MeshFilter>().mesh;
var meshRenderer = whiteHoleRenderer.AddComponent<MeshRenderer>();
meshRenderer.material = new Material(whiteHoleShader);
meshRenderer.sharedMaterial.SetFloat(Radius, size * 0.4f);
meshRenderer.sharedMaterial.SetFloat(DistortFadeDist, size);
meshRenderer.sharedMaterial.SetFloat(MaxDistortRadius, size * 2.8f);
meshRenderer.sharedMaterial.SetColor(Color1, new Color(1.88f, 1.88f, 1.88f, 1f));
if (curve != null) AddSizeController(whiteHoleRenderer, curve, size);
whiteHoleRenderer.SetActive(true);
return whiteHoleRenderer;
}
private static SizeController AddSizeController(GameObject go, VariableSizeModule.TimeValuePair[] curve, float size)
{
var sizeController = go.AddComponent<SizeController>();
sizeController.SetScaleCurve(curve);
sizeController.size = size;
return sizeController;
}
}
}

View File

@ -167,10 +167,10 @@ namespace NewHorizons.Builder.Body
starEvolutionController.atmosphere = sunAtmosphere;
starEvolutionController.controller = starController;
starEvolutionController.supernova = supernova;
starEvolutionController.StartColour = starModule.tint;
starEvolutionController.EndColour = starModule.endTint;
starEvolutionController.SupernovaColour = starModule.supernovaTint;
starEvolutionController.WillExplode = starModule.stellarDeathType != StellarDeathType.None;
starEvolutionController.startColour = starModule.tint;
starEvolutionController.endColour = starModule.endTint;
starEvolutionController.supernovaColour = starModule.supernovaTint;
starEvolutionController.willExplode = starModule.stellarDeathType != StellarDeathType.None;
starEvolutionController.lifespan = starModule.lifespan;
starEvolutionController.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp;
starEvolutionController.heatVolume = heatVolume.GetComponent<HeatHazardVolume>();
@ -211,7 +211,7 @@ namespace NewHorizons.Builder.Body
starGO.SetActive(false);
var controller = starGO.AddComponent<StarEvolutionController>();
controller._isProxy = true;
controller.isProxy = true;
if (starModule.curve != null) controller.SetScaleCurve(starModule.curve);
controller.size = starModule.size;
controller.supernovaSize = starModule.supernovaSize;
@ -221,10 +221,10 @@ namespace NewHorizons.Builder.Body
controller.supernovaScaleStart = duration * 0.9f;
controller.deathType = starModule.stellarDeathType;
controller.supernova = supernova;
controller.StartColour = starModule.tint;
controller.EndColour = starModule.endTint;
controller.SupernovaColour = starModule.supernovaTint;
controller.WillExplode = starModule.stellarDeathType != StellarDeathType.None;
controller.startColour = starModule.tint;
controller.endColour = starModule.endTint;
controller.supernovaColour = starModule.supernovaTint;
controller.willExplode = starModule.stellarDeathType != StellarDeathType.None;
controller.lifespan = starModule.lifespan;
controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp;
if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture))

View File

@ -1,3 +1,4 @@
using Epic.OnlineServices.Stats;
using NewHorizons.Builder.General;
using NewHorizons.Components;
using NewHorizons.Components.SizeControllers;
@ -26,28 +27,12 @@ namespace NewHorizons.Builder.Body
var remnantType = star.Config.Star.stellarRemnantType;
var progenitorSize = star.Config.Star.size;
if (remnantType == StellarRemnantType.Default)
{
if (progenitorSize >= 4000) remnantType = StellarRemnantType.BlackHole;
else if (2000 < progenitorSize && progenitorSize < 4000) remnantType = StellarRemnantType.NeutronStar;
else remnantType = StellarRemnantType.WhiteDwarf;
}
if (remnantType == StellarRemnantType.Default) remnantType = GetDefault(star.Config.Star.size);
switch (remnantType)
{
case StellarRemnantType.WhiteDwarf:
var whiteDwarfSize = progenitorSize / 10;
var wdModule = new StarModule
{
size = whiteDwarfSize,
tint = new MColor(384, 384, 384, 255),
lightTint = MColor.white,
lightRadius = 10000,
solarLuminosity = 0.5f
};
StarBuilder.Make(go, sector, wdModule, mod, true);
MakeWhiteDwarf(go, sector, mod, star.Config.Star);
break;
case StellarRemnantType.NeutronStar:
@ -56,12 +41,11 @@ namespace NewHorizons.Builder.Body
break;
case StellarRemnantType.Pulsar:
MakeNeutronStar(go, sector, mod, star.Config.Star);
// TODO: add jets, up rotation speed (use a RotateTransform on the star instead of changing sidereal period)
break;
case StellarRemnantType.BlackHole:
var blackHoleSize = progenitorSize / 100;
SingularityBuilder.MakeBlackHole(go, sector, Vector3.zero, blackHoleSize, true, string.Empty);
MakeBlackhole(go, sector, star.Config.Star);
break;
default:
@ -77,7 +61,29 @@ namespace NewHorizons.Builder.Body
}
}
private static GameObject MakeNeutronStar(GameObject root, Sector sector, IModBehaviour mod, StarModule progenitor)
private static StellarRemnantType GetDefault(float progenitorSize)
{
if (progenitorSize >= 4000) return StellarRemnantType.BlackHole;
else if (2000 < progenitorSize && progenitorSize < 4000) return StellarRemnantType.NeutronStar;
else return StellarRemnantType.WhiteDwarf;
}
private static GameObject MakeWhiteDwarf(GameObject planetGO, Sector sector, IModBehaviour mod, StarModule progenitor, GameObject proxy = null)
{
var whiteDwarfSize = progenitor.size / 10;
var whiteDwarfModule = new StarModule
{
size = whiteDwarfSize,
tint = new MColor(384, 384, 384, 255),
lightTint = MColor.white,
lightRadius = 10000,
solarLuminosity = 0.5f
};
if (proxy != null) return StarBuilder.MakeStarProxy(planetGO, proxy, whiteDwarfModule, mod, true);
else return StarBuilder.Make(planetGO, sector, whiteDwarfModule, mod, true).Item1;
}
private static GameObject MakeNeutronStar(GameObject planetGO, Sector sector, IModBehaviour mod, StarModule progenitor, GameObject proxy = null)
{
var neutronStarSize = progenitor.size / 50;
var neutronStarModule = new StarModule
@ -91,7 +97,9 @@ namespace NewHorizons.Builder.Body
};
// Instead of showing the typical star surface we use a tinted singularity
var (neutronStar, _, _) = StarBuilder.Make(root, sector, neutronStarModule, mod, true);
GameObject neutronStar;
if (proxy != null) neutronStar = StarBuilder.MakeStarProxy(planetGO, proxy, neutronStarModule, mod, true);
else (neutronStar, _, _) = StarBuilder.Make(planetGO, sector, neutronStarModule, mod, true);
neutronStar.FindChild("Surface").SetActive(false);
// Modify solar flares
@ -101,10 +109,40 @@ namespace NewHorizons.Builder.Body
flares.gameObject.transform.localScale = new Vector3(0.85f, 0.85f, 0.85f);
// Add singularity
var singularityRenderer = SingularityBuilder.MakeBlackHoleGraphics(root, neutronStarSize * 2.5f);
var singularityRenderer = SingularityBuilder.MakeBlackHoleGraphics(planetGO, neutronStarSize * 2.5f);
singularityRenderer.GetComponent<MeshRenderer>().material.color = new Color(0.5f, 2f, 2f, 1f);
return neutronStar;
}
private static GameObject MakeBlackhole(GameObject planetGO, Sector sector, StarModule progenitor, GameObject proxy = null)
{
var blackHoleSize = progenitor.size / 100;
if (proxy != null) return SingularityBuilder.MakeBlackHoleProxy(proxy, Vector3.zero, blackHoleSize);
else return SingularityBuilder.MakeBlackHole(planetGO, sector, Vector3.zero, blackHoleSize, true, string.Empty);
}
public static GameObject MakeProxyRemnant(GameObject planet, GameObject proxy, IModBehaviour mod, StarModule progenitor)
{
var remnantType = progenitor.stellarRemnantType;
if (remnantType == StellarRemnantType.Default) remnantType = GetDefault(progenitor.size);
switch (remnantType)
{
case StellarRemnantType.WhiteDwarf:
return MakeWhiteDwarf(planet, null, mod, progenitor, proxy);
case StellarRemnantType.NeutronStar:
return MakeNeutronStar(planet, null, mod, progenitor, proxy);
case StellarRemnantType.Pulsar:
return MakeNeutronStar(planet, null, mod, progenitor, proxy);
case StellarRemnantType.BlackHole:
return MakeBlackhole(planet, null, progenitor, proxy);
default:
Logger.LogError($"Couldn't make proxy remnant for {planet.name}");
return null;
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace NewHorizons.Builder.General
{
NHAstroObject astroObject = body.AddComponent<NHAstroObject>();
astroObject.HideDisplayName = !config.Base.hasMapMarker;
astroObject.invulnerableToSun = config.Base.invulnerableToSun || config.Star != null;
astroObject.invulnerableToSun = config.Base.invulnerableToSun;
if (config.Orbit != null) astroObject.SetOrbitalParametersFromConfig(config.Orbit);

View File

@ -1,7 +1,9 @@
using Epic.OnlineServices.Stats;
using NewHorizons.Components.SizeControllers;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Components
{
@ -9,17 +11,25 @@ namespace NewHorizons.Components
{
public string astroName;
public GameObject _planet;
public GameObject _star;
public StarEvolutionController _starEvolutionController;
private Renderer[] _starRenderers;
private TessellatedRenderer[] _starTessellatedRenderers;
private ParticleSystemRenderer[] _starParticleRenderers;
private SolarFlareEmitter _solarFlareEmitter;
public CloudLightningGenerator _lightningGenerator;
public Renderer _topClouds;
public NHSupernovaPlanetEffectController _supernovaPlanetEffectController;
public float _baseRealObjectDiameter;
public GameObject planet;
private GameObject[] _stars;
public StarEvolutionController[] StarEvolutionControllers { get; private set; }
private IEnumerable<Renderer> _starRenderers = new List<Renderer>();
private IEnumerable<TessellatedRenderer> _starTessellatedRenderers = new List<TessellatedRenderer>();
private IEnumerable<ParticleSystemRenderer> _starParticleRenderers = new List<ParticleSystemRenderer>();
private IEnumerable<SolarFlareEmitter> _solarFlareEmitter = new List<SolarFlareEmitter>();
// Public stuff from the builder
public CloudLightningGenerator lightningGenerator;
public Renderer topClouds;
public NHSupernovaPlanetEffectController supernovaPlanetEffectController;
public float baseRealObjectDiameter;
public GameObject root;
public GameObject stellarRemnantGO;
public override void Awake()
{
@ -32,20 +42,26 @@ namespace NewHorizons.Components
// The star part cant be disabled like the rest and we have to manually disable the renderers
// Else it can stop the supernova effect mid way through
if (_starEvolutionController == null) _starEvolutionController = GetComponentInChildren<StarEvolutionController>();
if (_star == null) _star = _starEvolutionController?.gameObject;
if (_star != null)
StarEvolutionControllers = GetComponentsInChildren<StarEvolutionController>();
_stars = StarEvolutionControllers.Select(x => x.gameObject).ToArray();
foreach (var star in _stars)
{
_starRenderers = _star.GetComponentsInChildren<Renderer>();
_starTessellatedRenderers = _star.GetComponentsInChildren<TessellatedRenderer>();
_starParticleRenderers = _star.GetComponentsInChildren<ParticleSystemRenderer>();
_solarFlareEmitter = _star.GetComponentInChildren<SolarFlareEmitter>();
_starRenderers = _starRenderers.Concat(star.GetComponentsInChildren<Renderer>());
_starTessellatedRenderers = _starTessellatedRenderers.Concat(star.GetComponentsInChildren<TessellatedRenderer>());
_starParticleRenderers = _starParticleRenderers.Concat(star.GetComponentsInChildren<ParticleSystemRenderer>());
_solarFlareEmitter = _solarFlareEmitter.Append(star.GetComponentInChildren<SolarFlareEmitter>());
}
if (_lightningGenerator == null) _lightningGenerator = GetComponentInChildren<CloudLightningGenerator>();
var progenitorEvolutionController = root.GetComponentInChildren<StarEvolutionController>();
if (progenitorEvolutionController != null && stellarRemnantGO != null)
{
progenitorEvolutionController.SetStellarRemnant(stellarRemnantGO);
}
if (_supernovaPlanetEffectController == null) _supernovaPlanetEffectController = GetComponentInChildren<NHSupernovaPlanetEffectController>();
if (lightningGenerator == null) lightningGenerator = GetComponentInChildren<CloudLightningGenerator>();
if (supernovaPlanetEffectController == null) supernovaPlanetEffectController = GetComponentInChildren<NHSupernovaPlanetEffectController>();
// Start off
_outOfRange = false;
@ -81,7 +97,7 @@ namespace NewHorizons.Components
public override void Update()
{
if (_planet == null || !_planet.activeSelf)
if (planet == null || !planet.activeSelf)
{
_outOfRange = false;
ToggleRendering(false);
@ -98,47 +114,51 @@ namespace NewHorizons.Components
foreach (Transform child in transform)
{
if (child.gameObject == _star) continue;
child.gameObject.SetActive(on);
}
if (_star != null)
{
if (_solarFlareEmitter != null)
// The first layer of children are the different states of the proxy; root, remnant, eventually quantum states
foreach (Transform grandChild in child)
{
_solarFlareEmitter.gameObject.SetActive(on);
}
// Don't disable any stars
if (_stars.Contains(grandChild.gameObject)) continue;
foreach (var renderer in _starRenderers)
{
renderer.enabled = on;
}
foreach (var renderer in _starTessellatedRenderers)
{
renderer.enabled = on;
}
foreach (var renderer in _starParticleRenderers)
{
renderer.enabled = on;
// Toggle the grandchildren
grandChild.gameObject.SetActive(on);
}
}
if (_topClouds != null)
foreach (var solarFlare in _solarFlareEmitter)
{
_topClouds.enabled = on;
solarFlare.gameObject.SetActive(on);
}
if (_lightningGenerator != null)
foreach (var renderer in _starRenderers)
{
_lightningGenerator.enabled = on;
renderer.enabled = on;
}
if (_supernovaPlanetEffectController != null)
foreach (var renderer in _starTessellatedRenderers)
{
if (on) _supernovaPlanetEffectController.Enable();
else _supernovaPlanetEffectController.Disable();
renderer.enabled = on;
}
foreach (var renderer in _starParticleRenderers)
{
renderer.enabled = on;
}
if (topClouds != null)
{
topClouds.enabled = on;
}
if (lightningGenerator != null)
{
lightningGenerator.enabled = on;
}
if (supernovaPlanetEffectController != null)
{
if (on) supernovaPlanetEffectController.Enable();
else supernovaPlanetEffectController.Disable();
}
}

View File

@ -116,7 +116,7 @@ namespace NewHorizons.Components
{
if (!_shockLayer.enabled) _shockLayer.enabled = true;
Vector3 dir = Vector3.Normalize(transform.position - StarEvolutionController.transform.position);
s_matPropBlock_ShockLayer.SetColor(s_propID_Color, StarEvolutionController.SupernovaColour != null ? StarEvolutionController.SupernovaColour.ToColor() : _shockLayerColor);
s_matPropBlock_ShockLayer.SetColor(s_propID_Color, StarEvolutionController.supernovaColour != null ? StarEvolutionController.supernovaColour.ToColor() : _shockLayerColor);
s_matPropBlock_ShockLayer.SetMatrix(s_propID_WorldToLocalShockMatrix, Matrix4x4.TRS(transform.position, Quaternion.LookRotation(dir, Vector3.up), Vector3.one).inverse);
s_matPropBlock_ShockLayer.SetVector(s_propID_Dir, dir);
s_matPropBlock_ShockLayer.SetFloat(s_propID_Length, shockLayerTrailLength);

View File

@ -16,15 +16,15 @@ namespace NewHorizons.Components.SizeControllers
{
public class StarEvolutionController : SizeController
{
public bool _isProxy;
public bool isProxy;
public GameObject atmosphere;
public StarController controller;
public StellarDeathController supernova;
public bool WillExplode { get; set; }
public MColor StartColour { get; set; }
public MColor EndColour { get; set; }
public MColor SupernovaColour { get; set; }
public bool willExplode;
public MColor startColour;
public MColor endColour;
public MColor supernovaColour;
public Texture normalRamp;
public Texture collapseRamp;
@ -34,12 +34,13 @@ namespace NewHorizons.Components.SizeControllers
private GameObject _stellarRemnant;
private PlanetaryFogController _fog;
private MeshRenderer[] _atmosphereRenderers;
public HeatHazardVolume heatVolume;
public DestructionVolume destructionVolume;
public StarDestructionVolume planetDestructionVolume;
public StarFluidVolume starFluidVolume;
private SolarFlareEmitter _flareEmitter;
private MapMarker _mapMarker;
private OWRigidbody _rigidbody;
public OWAudioSource oneShotSource;
@ -70,13 +71,13 @@ namespace NewHorizons.Components.SizeControllers
private StarEvolutionController _proxy;
public UnityEvent CollapseStart = new UnityEvent();
public UnityEvent CollapseStop = new UnityEvent();
public UnityEvent SupernovaStart = new UnityEvent();
public UnityEvent SupernovaStop = new UnityEvent();
public UnityEvent CollapseStart = new();
public UnityEvent CollapseStop = new();
public UnityEvent SupernovaStart = new();
public UnityEvent SupernovaStop = new();
private float maxScale;
private float minScale;
private float _maxScale;
private float _minScale;
private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp");
private static readonly int ColorTime = Shader.PropertyToID("_ColorTime");
private static readonly int InnerRadius = Shader.PropertyToID("_InnerRadius");
@ -88,7 +89,6 @@ namespace NewHorizons.Components.SizeControllers
private void Start()
{
_rigidbody = this.GetAttachedOWRigidbody();
if (_rigidbody != null) _mapMarker = _rigidbody.GetComponent<MapMarker>();
var sun = GameObject.FindObjectOfType<SunController>();
_collapseStartSurfaceMaterial = new Material(sun._collapseStartSurfaceMaterial);
@ -117,24 +117,24 @@ namespace NewHorizons.Components.SizeControllers
_startSurfaceMaterial.SetTexture(ColorRamp, _normalRamp);
_endSurfaceMaterial.SetTexture(ColorRamp, _normalRamp);
if (StartColour == null)
if (startColour == null)
{
_startColour = _startSurfaceMaterial.color;
}
else
{
_startColour = StartColour.ToColor();
_startColour = startColour.ToColor();
_startSurfaceMaterial.color = _startColour;
}
if (EndColour == null)
if (endColour == null)
{
_endColour = _startColour;
_endSurfaceMaterial.color = _startColour;
}
else
{
_endColour = EndColour.ToColor();
_endColour = endColour.ToColor();
_endSurfaceMaterial.color = _endColour * 4.5948f;
}
@ -151,13 +151,13 @@ namespace NewHorizons.Components.SizeControllers
if (scaleCurve != null)
{
maxScale = scaleCurve.keys.Select(x => x.value).Max() * size;
minScale = scaleCurve.keys.Select(x => x.value).Min() * size;
_maxScale = scaleCurve.keys.Select(x => x.value).Max() * size;
_minScale = scaleCurve.keys.Select(x => x.value).Min() * size;
}
else
{
maxScale = 0;
minScale = 0;
_maxScale = 0;
_minScale = 0;
scaleCurve = new AnimationCurve();
scaleCurve.AddKey(0, 1);
}
@ -165,7 +165,7 @@ namespace NewHorizons.Components.SizeControllers
_flareEmitter = GetComponentInChildren<SolarFlareEmitter>();
_surfaceMaterial = supernova._surface._materials[0];
if (!_isProxy) SupernovaEffectHandler.RegisterStar(this);
if (!isProxy) SupernovaEffectHandler.RegisterStar(this);
var secondsElapsed = TimeLoop.GetSecondsElapsed();
var lifespanInSeconds = lifespan * 60;
@ -195,11 +195,11 @@ namespace NewHorizons.Components.SizeControllers
private void UpdateMainSequence()
{
// Only do colour transition stuff if they set an end colour
if (EndColour != null)
if (endColour != null)
{
// Use minutes elapsed if theres no resizing happening, else make it get redder the larger it is or wtv
var t = TimeLoop.GetMinutesElapsed() / lifespan;
if (maxScale != minScale) t = Mathf.InverseLerp(minScale, maxScale, CurrentScale);
if (_maxScale != _minScale) t = Mathf.InverseLerp(_minScale, _maxScale, CurrentScale);
if (t < 1f)
{
@ -293,10 +293,20 @@ namespace NewHorizons.Components.SizeControllers
if (collider.attachedRigidbody != null)
{
// Destroy any planets that are not invulnerable to the sun
var body = collider.attachedRigidbody.GetComponent<OWRigidbody>();
var rb = collider.attachedRigidbody;
var body = rb.GetComponent<OWRigidbody>();
var astroObject = collider.gameObject.GetComponent<NHAstroObject>();
if (astroObject != null && !astroObject.invulnerableToSun)
planetDestructionVolume.Vanish(body, new RelativeLocationData(body, _rigidbody, planetDestructionVolume.transform));
if (astroObject != null)
{
if (!astroObject.invulnerableToSun)
planetDestructionVolume.Vanish(body, new RelativeLocationData(body, _rigidbody, planetDestructionVolume.transform));
}
else
{
// Vanish anything unrelated to player
if (!(rb.CompareTag("Player") || rb.CompareTag("Ship") || rb.CompareTag("ShipCockpit") || rb.CompareTag("Probe")))
planetDestructionVolume.Vanish(body, new RelativeLocationData(body, _rigidbody, planetDestructionVolume.transform));
}
}
}
}
@ -412,7 +422,7 @@ namespace NewHorizons.Components.SizeControllers
{
base.FixedUpdate();
UpdateMainSequence();
if (WillExplode && (TimeLoop.GetMinutesElapsed() / lifespan) >= 1) StartCollapse();
if (willExplode && (TimeLoop.GetMinutesElapsed() / lifespan) >= 1) StartCollapse();
}
else
{

View File

@ -219,7 +219,7 @@ namespace NewHorizons.External.Configs
}
}
Dictionary<string, int> existingGroupsPropCounts = new Dictionary<string, int>();
var existingGroupsPropCounts = new Dictionary<string, int>();
foreach (var prop in Props?.details)
{
if (prop.quantumGroupID == null) continue;

View File

@ -448,11 +448,15 @@ namespace NewHorizons.Handlers
AstroObjectLocator.RegisterCustomAstroObject(ao);
var otherBodies = Main.BodyDict[Main.Instance.CurrentStarSystem];
var remnant = otherBodies.Where(x => x.Config.isStellarRemnant && x.Config.name == body.Config.name).FirstOrDefault();
// TODO: add proxies for quantum states
//var quantumStates = otherBodies.Where(x => x.Config.isQuantumState && x.Config.name == body.Config.name).ToArray();
if (!(body.Config.Cloak != null && body.Config.Cloak.radius != 0f))
{
Delay.FireOnNextUpdate(() =>
{
ProxyBuilder.Make(go, body);
ProxyBuilder.Make(go, body, remnant);
});
}

View File

@ -40,7 +40,7 @@ namespace NewHorizons.Patches
[HarmonyPatch(typeof(ProxyBody), nameof(ProxyBody.IsObjectInSupernova))]
public static bool ProxyBody_IsObjectInSupernova(ProxyBody __instance, ref bool __result)
{
if (__instance is NHProxy nh && nh._starEvolutionController != null)
if (__instance is NHProxy nh && nh.StarEvolutionControllers != null)
{
__result = false;
return false;