Change everything (broke proxies)

This commit is contained in:
Nick 2022-08-24 23:12:35 -04:00
parent 807067ed95
commit d32f77f6df
13 changed files with 220 additions and 606 deletions

View File

@ -52,7 +52,7 @@ namespace NewHorizons.Builder.Body
proxy.SetActive(true);
}
internal static bool SharedMake(GameObject planetGO, GameObject proxy, NHProxy proxyController, NewHorizonsBody body, StellarRemnantProxy stellarRemnantProxy = null)
private static bool SharedMake(GameObject planetGO, GameObject proxy, NHProxy proxyController, NewHorizonsBody body)
{
try
{
@ -205,15 +205,6 @@ namespace NewHorizons.Builder.Body
proxyController._realObjectDiameter = realSize;
proxyController._baseRealObjectDiameter = realSize;
}
else if (stellarRemnantProxy != null)
{
stellarRemnantProxy._atmosphere = atmosphere;
stellarRemnantProxy._fog = fog;
stellarRemnantProxy._fogCurveMaxVal = fogCurveMaxVal;
stellarRemnantProxy._topClouds = topClouds;
stellarRemnantProxy._lightningGenerator = lightningGenerator;
stellarRemnantProxy._realObjectDiameter = realSize;
}
return true;
}
@ -224,7 +215,7 @@ namespace NewHorizons.Builder.Body
}
}
internal static GameObject AddColouredSphere(GameObject rootObj, float size, VariableSizeModule.TimeValuePair[] curve, Color color)
private static GameObject AddColouredSphere(GameObject rootObj, float size, VariableSizeModule.TimeValuePair[] curve, Color color)
{
GameObject sphereGO = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphereGO.transform.name = "ProxySphere";
@ -242,7 +233,7 @@ namespace NewHorizons.Builder.Body
return sphereGO;
}
internal static SizeController AddSizeController(GameObject go, VariableSizeModule.TimeValuePair[] curve, float size)
private static SizeController AddSizeController(GameObject go, VariableSizeModule.TimeValuePair[] curve, float size)
{
var sizeController = go.AddComponent<SizeController>();
sizeController.SetScaleCurve(curve);
@ -250,7 +241,7 @@ namespace NewHorizons.Builder.Body
return sizeController;
}
internal static GameObject MakeBlackHole(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
private static GameObject MakeBlackHole(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
{
if (_blackHolePrefab == null) _blackHolePrefab = SearchUtilities.Find(_blackHolePath);
@ -279,7 +270,7 @@ namespace NewHorizons.Builder.Body
return blackHoleRender;
}
internal static GameObject MakeWhiteHole(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
private static GameObject MakeWhiteHole(GameObject rootObject, MVector3 position, float size, VariableSizeModule.TimeValuePair[] curve = null)
{
if (_whiteHolePrefab == null) _whiteHolePrefab = SearchUtilities.Find(_whiteHolePath);

View File

@ -8,6 +8,8 @@ using Logger = NewHorizons.Utility.Logger;
using System.Collections.Generic;
using System.Linq;
using NewHorizons.Components.SizeControllers;
using System.Drawing;
using Color = UnityEngine.Color;
namespace NewHorizons.Builder.Body
{
@ -102,31 +104,17 @@ namespace NewHorizons.Builder.Body
blackHole.transform.parent = sector?.transform ?? planetGO.transform;
blackHole.transform.position = planetGO.transform.TransformPoint(localPosition);
var blackHoleRender = new GameObject("BlackHoleRender");
blackHoleRender.transform.parent = blackHole.transform;
blackHoleRender.transform.localPosition = Vector3.zero;
blackHoleRender.transform.localScale = Vector3.one * size;
var blackHoleRender = MakeBlackHoleGraphics(blackHole, size);
BlackHoleSizeController sizeController = null;
if (curve != null)
{
sizeController = blackHoleRender.AddComponent<BlackHoleSizeController>();
sizeController = blackHoleRender.gameObject.AddComponent<BlackHoleSizeController>();
sizeController.SetScaleCurve(curve);
sizeController.size = size;
sizeController.material = blackHoleRender.material;
}
var meshFilter = blackHoleRender.AddComponent<MeshFilter>();
meshFilter.mesh = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshFilter>().mesh;
var meshRenderer = blackHoleRender.AddComponent<MeshRenderer>();
if (blackHoleShader == null) blackHoleShader = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshRenderer>().sharedMaterial.shader;
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 (sizeController != null) sizeController.material = meshRenderer.material;
if (makeAudio)
{
var blackHoleAmbience = GameObject.Instantiate(SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleAmbience"), blackHole.transform);
@ -180,6 +168,27 @@ namespace NewHorizons.Builder.Body
return blackHole;
}
public static MeshRenderer MakeBlackHoleGraphics(GameObject blackHole, float size)
{
var blackHoleRender = new GameObject("BlackHoleRender");
blackHoleRender.transform.parent = blackHole.transform;
blackHoleRender.transform.localPosition = Vector3.zero;
blackHoleRender.transform.localScale = Vector3.one * size;
var meshFilter = blackHoleRender.AddComponent<MeshFilter>();
meshFilter.mesh = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshFilter>().mesh;
var meshRenderer = blackHoleRender.AddComponent<MeshRenderer>();
if (blackHoleShader == null) blackHoleShader = SearchUtilities.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshRenderer>().sharedMaterial.shader;
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);
return meshRenderer;
}
public static GameObject MakeWhiteHole(GameObject planetGO, Sector sector, OWRigidbody OWRB, Vector3 localPosition, float size,
VariableSizeModule.TimeValuePair[] curve, bool makeZeroGVolume = true)
{

View File

@ -21,7 +21,7 @@ namespace NewHorizons.Builder.Body
private static readonly int InnerRadius = Shader.PropertyToID("_InnerRadius");
private static readonly int OuterRadius = Shader.PropertyToID("_OuterRadius");
public static StarController Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)
public static (GameObject, StarController, StarEvolutionController) Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)
{
var starGO = MakeStarGraphics(planetGO, sector, starModule, mod);
var ramp = starGO.GetComponentInChildren<TessellatedSphereRenderer>().sharedMaterial.GetTexture(ColorRamp);
@ -80,6 +80,7 @@ namespace NewHorizons.Builder.Body
heatVolume.AddComponent<OWTriggerVolume>();
heatVolume.AddComponent<HeatHazardVolume>()._damagePerSecond = 20f;
// Kill player entering the star
var deathVolume = new GameObject("DestructionFluidVolume");
deathVolume.transform.SetParent(starGO.transform, false);
deathVolume.transform.localPosition = Vector3.zero;
@ -95,6 +96,7 @@ namespace NewHorizons.Builder.Body
destructionVolume._deathType = DeathType.Energy;
var starFluidVolume = deathVolume.AddComponent<StarFluidVolume>();
// Destroy planets entering the star
var planetDestructionVolume = new GameObject("PlanetDestructionVolume");
planetDestructionVolume.transform.SetParent(starGO.transform, false);
planetDestructionVolume.transform.localPosition = Vector3.zero;
@ -147,40 +149,41 @@ namespace NewHorizons.Builder.Body
starController.IsStellarRemnant = isStellarRemnant;
}
StarEvolutionController starEvolutionController = null;
if (!isStellarRemnant)
{
var supernova = MakeSupernova(starGO, starModule);
starGO.SetActive(false);
var controller = starGO.AddComponent<StarEvolutionController>();
if (starModule.curve != null) controller.SetScaleCurve(starModule.curve);
controller.size = starModule.size;
controller.supernovaSize = starModule.supernovaSize;
starEvolutionController = starGO.AddComponent<StarEvolutionController>();
if (starModule.curve != null) starEvolutionController.SetScaleCurve(starModule.curve);
starEvolutionController.size = starModule.size;
starEvolutionController.supernovaSize = starModule.supernovaSize;
var duration = starModule.supernovaSize / starModule.supernovaSpeed;
controller.supernovaTime = duration;
controller.supernovaScaleEnd = duration;
controller.supernovaScaleStart = duration * 0.9f;
controller.deathType = starModule.stellarDeathType;
controller.atmosphere = sunAtmosphere;
controller.controller = starController;
controller.supernova = supernova;
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;
controller._heatVolume = heatVolume.GetComponent<HeatHazardVolume>();
controller._destructionVolume = deathVolume.GetComponent<DestructionVolume>();
controller._planetDestructionVolume = planetDestructionVolume.GetComponent<StarDestructionVolume>();
controller._starFluidVolume = starFluidVolume;
controller._oneShotSource = sunAudio.transform.Find("OneShotAudio_Sun")?.GetComponent<OWAudioSource>();
starFluidVolume.SetStarEvolutionController(controller);
starEvolutionController.supernovaTime = duration;
starEvolutionController.supernovaScaleEnd = duration;
starEvolutionController.supernovaScaleStart = duration * 0.9f;
starEvolutionController.deathType = starModule.stellarDeathType;
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.lifespan = starModule.lifespan;
starEvolutionController.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp;
starEvolutionController.heatVolume = heatVolume.GetComponent<HeatHazardVolume>();
starEvolutionController.destructionVolume = deathVolume.GetComponent<DestructionVolume>();
starEvolutionController.planetDestructionVolume = planetDestructionVolume.GetComponent<StarDestructionVolume>();
starEvolutionController.starFluidVolume = starFluidVolume;
starEvolutionController.oneShotSource = sunAudio.transform.Find("OneShotAudio_Sun")?.GetComponent<OWAudioSource>();
starFluidVolume.SetStarEvolutionController(starEvolutionController);
if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture))
{
controller.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture);
starEvolutionController.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture);
}
surfaceAudio.SetStarEvolutionController(controller);
surfaceAudio.SetStarEvolutionController(starEvolutionController);
starGO.SetActive(true);
}
@ -192,7 +195,7 @@ namespace NewHorizons.Builder.Body
shockLayerRuleset._outerRadius = starModule.size * OuterRadiusRatio;
if (starModule.tint != null) shockLayerRuleset._color *= starModule.tint.ToColor();
return starController;
return (starGO, starController, starEvolutionController);
}
public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)

View File

@ -1,258 +1,74 @@
using NewHorizons.Builder.General;
using NewHorizons.Components;
using NewHorizons.Components.SizeControllers;
using NewHorizons.External.Configs;
using NewHorizons.External.Modules.VariableSize;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Color = UnityEngine.Color;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.Body
{
public static class StellarRemnantBuilder
{
public static StellarRemnantController Make(NewHorizonsBody star, GameObject go, OWRigidbody rb, IModBehaviour mod, NewHorizonsBody stellarRemnant = null)
public static GameObject Make(GameObject go, OWRigidbody rb, float soi, IModBehaviour mod, NewHorizonsBody star)
{
try
{
var currentSRC = go.GetComponentInChildren<StellarRemnantController>();
if (currentSRC != null)
{
foreach (var starEvolutionController1 in go.GetComponentsInChildren<StarEvolutionController>(true))
{
starEvolutionController1.SetStellarRemnantController(currentSRC);
}
return currentSRC;
}
Logger.Log($"Creating stellar remnant for [{star.Config.name}]");
var config = star.Config;
var starModule = star.Config.Star;
var size = starModule.size;
var sector = SectorBuilder.Make(go, rb, 0);
var sector = SectorBuilder.Make(go, rb, soi);
sector.name = "StellarRemnant";
var ss = sector.GetComponent<SphereShape>();
var stellarRemnantController = sector.gameObject.AddComponent<StellarRemnantController>();
var starEvolutionController = go.GetComponentInChildren<StarEvolutionController>(true);
stellarRemnantController.SetStarEvolutionController(starEvolutionController);
starEvolutionController.SetStellarRemnantController(stellarRemnantController);
sector.gameObject.SetActive(false);
var remnantType = starModule.stellarRemnantType;
if (stellarRemnant != null)
var remnantType = star.Config.Star.stellarRemnantType;
var progenitorSize = star.Config.Star.size;
if (remnantType == StellarRemnantType.Default)
{
remnantType = StellarRemnantType.Custom;
stellarRemnantController.SetSurfaceSize(stellarRemnant.Config.Base.surfaceSize);
stellarRemnantController.SetSurfaceGravity(stellarRemnant.Config.Base.surfaceGravity);
stellarRemnantController.SetSiderealPeriod(stellarRemnant.Config.Orbit.siderealPeriod);
var srSphereOfInfluence = PlanetCreationHandler.GetSphereOfInfluence(stellarRemnant);
stellarRemnantController.SetSphereOfInfluence(srSphereOfInfluence);
ss.radius = srSphereOfInfluence + 10;
var alignmentRadius = stellarRemnant.Config.Atmosphere?.clouds?.outerCloudRadius ?? 1.5f * stellarRemnant.Config.Base.surfaceSize;
if (stellarRemnant.Config.Base.surfaceGravity == 0) alignmentRadius = 0;
stellarRemnantController.SetAlignmentRadius(alignmentRadius);
PlanetCreationHandler.SharedGenerateBody(stellarRemnant, go, sector, rb);
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() =>
{
var proxyController = ProxyHandler.GetProxy(star.Config.name);
if (proxyController != null)
if (progenitorSize >= 4000) remnantType = StellarRemnantType.BlackHole;
else if (2000 < progenitorSize && progenitorSize < 4000) remnantType = StellarRemnantType.NeutronStar;
else remnantType = StellarRemnantType.WhiteDwarf;
}
switch (remnantType)
{
case StellarRemnantType.WhiteDwarf:
var whiteDwarfSize = progenitorSize / 10;
var wdModule = new StarModule
{
GameObject proxyStellarRemnant = new GameObject("StellarRemnant");
proxyStellarRemnant.transform.SetParent(proxyController.transform, false);
proxyStellarRemnant.SetActive(false);
StellarRemnantProxy srp = proxyStellarRemnant.AddComponent<StellarRemnantProxy>();
srp.SetStellarRemnantController(stellarRemnantController);
proxyController._stellarRemnant = srp;
ProxyBuilder.SharedMake(go, proxyStellarRemnant, null, stellarRemnant, srp);
proxyStellarRemnant.SetActive(true);
}
}, 2);
}
else
{
if (remnantType == StellarRemnantType.Default)
{
if (size >= 4000)
remnantType = StellarRemnantType.BlackHole;
else if (2000 < size && size < 4000)
remnantType = StellarRemnantType.NeutronStar;
else
remnantType = StellarRemnantType.WhiteDwarf;
}
switch (remnantType)
{
case StellarRemnantType.WhiteDwarf:
var wdSurfaceSize = size / 10;
stellarRemnantController.SetSurfaceSize(wdSurfaceSize);
stellarRemnantController.SetSurfaceGravity(config.Base.surfaceGravity * 100f);
stellarRemnantController.SetSphereOfInfluence(wdSurfaceSize * 2);
ss.radius = (wdSurfaceSize * 2) + 10;
stellarRemnantController.SetAlignmentRadius(wdSurfaceSize * 1.5f);
stellarRemnantController.SetSiderealPeriod(config.Orbit.siderealPeriod);
var wdModule = new StarModule
{
size = wdSurfaceSize,
tint = new MColor(384, 384, 384, 255), // refuses to actually be this color for no reason
lightTint = MColor.white,
lightRadius = 10000,
solarLuminosity = 0.5f
};
stellarRemnantController.SetStarController(StarBuilder.Make(go, sector, wdModule, mod, true));
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() =>
{
var proxyController = ProxyHandler.GetProxy(star.Config.name);
if (proxyController != null)
{
GameObject proxyStellarRemnant = new GameObject("StellarRemnant");
proxyStellarRemnant.transform.SetParent(proxyController.transform, false);
proxyStellarRemnant.SetActive(false);
StellarRemnantProxy srp = proxyStellarRemnant.AddComponent<StellarRemnantProxy>();
srp.SetStellarRemnantController(stellarRemnantController);
srp._realObjectDiameter = wdSurfaceSize;
proxyController._stellarRemnant = srp;
proxyController._star = StarBuilder.MakeStarProxy(go, proxyStellarRemnant, wdModule, mod, true);
proxyStellarRemnant.SetActive(true);
}
}, 2);
break;
case StellarRemnantType.NeutronStar:
var nsSurfaceSize = size / 50;
stellarRemnantController.SetSurfaceSize(nsSurfaceSize);
stellarRemnantController.SetSurfaceGravity(config.Base.surfaceGravity * 2500);
stellarRemnantController.SetSphereOfInfluence(nsSurfaceSize * 2);
ss.radius = (nsSurfaceSize * 2) + 10;
stellarRemnantController.SetAlignmentRadius(nsSurfaceSize * 1.5f);
stellarRemnantController.SetSiderealPeriod(0.2f);
var nsModule = new StarModule
{
size = nsSurfaceSize,
tint = new MColor(128, 510, 510, 255),
lightTint = new MColor(128, 255, 255, 255),
lightRadius = 10000,
solarLuminosity = 0.5f
};
stellarRemnantController.SetStarController(StarBuilder.Make(go, sector, nsModule, mod, true));
var nsStarObject = stellarRemnantController.gameObject.FindChild("Star");
nsStarObject.FindChild("Surface").SetActive(false);
nsStarObject.FindChild("Atmosphere_Star").SetActive(false);
var nsFlareEmitter = nsStarObject.GetComponentInChildren<SolarFlareEmitter>();
nsFlareEmitter.lifeLength = 3;
nsFlareEmitter._endScale = 1;
nsFlareEmitter.gameObject.transform.localScale = new Vector3(0.85f, 0.85f, 0.85f);
SingularityBuilder.MakeBlackHole(go, sector, Vector3.zero, nsSurfaceSize * 2.5f, true, string.Empty, null, false);
var nsBlackHole = stellarRemnantController.gameObject.FindChild("BlackHole");
var nsBlackHoleRender = nsBlackHole.FindChild("BlackHoleRender");
nsBlackHoleRender.GetComponent<MeshRenderer>().material.color = new Color(0.5f, 2f, 2f, 1f);
nsBlackHoleRender.transform.SetParent(nsStarObject.transform, true);
GameObject.Destroy(nsBlackHole);
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() =>
{
var proxyController = ProxyHandler.GetProxy(star.Config.name);
if (proxyController != null)
{
GameObject proxyStellarRemnant = new GameObject("StellarRemnant");
proxyStellarRemnant.transform.SetParent(proxyController.transform, false);
proxyStellarRemnant.SetActive(false);
StellarRemnantProxy srp = proxyStellarRemnant.AddComponent<StellarRemnantProxy>();
srp.SetStellarRemnantController(stellarRemnantController);
srp._realObjectDiameter = nsSurfaceSize;
proxyController._stellarRemnant = srp;
proxyController._star = StarBuilder.MakeStarProxy(go, proxyStellarRemnant, nsModule, mod, true);
proxyStellarRemnant.SetActive(true);
}
}, 2);
break;
case StellarRemnantType.Pulsar:
var psSurfaceSize = size / 50;
stellarRemnantController.SetSurfaceSize(psSurfaceSize);
stellarRemnantController.SetSurfaceGravity(config.Base.surfaceGravity * 2500);
stellarRemnantController.SetSphereOfInfluence(psSurfaceSize * 2);
ss.radius = (psSurfaceSize * 2) + 10;
stellarRemnantController.SetAlignmentRadius(psSurfaceSize * 1.5f);
stellarRemnantController.SetSiderealPeriod(0.01f);
var psModule = new StarModule
{
size = psSurfaceSize,
tint = new MColor(128, 510, 510, 255),
lightTint = new MColor(128, 255, 255, 255),
lightRadius = 10000,
solarLuminosity = 0.5f,
};
stellarRemnantController.SetStarController(StarBuilder.Make(go, sector, psModule, mod, true));
var psStarObject = stellarRemnantController.gameObject.FindChild("Star");
psStarObject.FindChild("Surface").SetActive(false);
psStarObject.FindChild("Atmosphere_Star").SetActive(false);
var psFlareEmitter = stellarRemnantController.gameObject.GetComponentInChildren<SolarFlareEmitter>();
psFlareEmitter.lifeLength = 1;
psFlareEmitter._endScale = 1;
psFlareEmitter.gameObject.transform.localScale = new Vector3(0.85f, 0.85f, 0.85f);
SingularityBuilder.MakeBlackHole(go, sector, Vector3.zero, psSurfaceSize * 2.5f, true, string.Empty, null, false);
var psBlackHole = stellarRemnantController.gameObject.FindChild("BlackHole");
var psBlackHoleRender = psBlackHole.FindChild("BlackHoleRender");
psBlackHoleRender.GetComponent<MeshRenderer>().material.color = new Color(0.5f, 2f, 2f, 1f);
psBlackHoleRender.transform.SetParent(psStarObject.transform, true);
GameObject.Destroy(psBlackHole);
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() =>
{
var proxyController = ProxyHandler.GetProxy(star.Config.name);
if (proxyController != null)
{
GameObject proxyStellarRemnant = new GameObject("StellarRemnant");
proxyStellarRemnant.transform.SetParent(proxyController.transform, false);
proxyStellarRemnant.SetActive(false);
StellarRemnantProxy srp = proxyStellarRemnant.AddComponent<StellarRemnantProxy>();
srp.SetStellarRemnantController(stellarRemnantController);
srp._realObjectDiameter = psSurfaceSize;
proxyController._stellarRemnant = srp;
proxyController._star = StarBuilder.MakeStarProxy(go, proxyStellarRemnant, psModule, mod, true);
proxyStellarRemnant.SetActive(true);
}
}, 2);
break;
case StellarRemnantType.BlackHole:
var bhSurfaceSize = size / 100;
stellarRemnantController.SetSurfaceSize(bhSurfaceSize);
stellarRemnantController.SetSurfaceGravity(config.Base.surfaceGravity * 10000);
stellarRemnantController.SetSphereOfInfluence(bhSurfaceSize * 2);
stellarRemnantController.SetSiderealPeriod(0.25f);
ss.radius = (bhSurfaceSize * 2) + 10;
stellarRemnantController.SetAlignmentRadius(bhSurfaceSize * 1.5f);
SingularityBuilder.MakeBlackHole(go, sector, Vector3.zero, bhSurfaceSize, true, string.Empty);
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() =>
{
var proxyController = ProxyHandler.GetProxy(star.Config.name);
if (proxyController != null)
{
GameObject proxyStellarRemnant = new GameObject("StellarRemnant");
proxyStellarRemnant.transform.SetParent(proxyController.transform, false);
proxyStellarRemnant.SetActive(false);
StellarRemnantProxy srp = proxyStellarRemnant.AddComponent<StellarRemnantProxy>();
srp.SetStellarRemnantController(stellarRemnantController);
srp._realObjectDiameter = bhSurfaceSize;
proxyController._stellarRemnant = srp;
ProxyBuilder.MakeBlackHole(proxyStellarRemnant, Vector3.zero, bhSurfaceSize);
proxyStellarRemnant.SetActive(true);
}
}, 2);
break;
default:
break;
}
size = whiteDwarfSize,
tint = new MColor(384, 384, 384, 255),
lightTint = MColor.white,
lightRadius = 10000,
solarLuminosity = 0.5f
};
StarBuilder.Make(go, sector, wdModule, mod, true);
break;
case StellarRemnantType.NeutronStar:
MakeNeutronStar(go, sector, mod, star.Config.Star);
break;
case StellarRemnantType.Pulsar:
MakeNeutronStar(go, sector, mod, star.Config.Star);
break;
case StellarRemnantType.BlackHole:
var blackHoleSize = progenitorSize / 100;
SingularityBuilder.MakeBlackHole(go, sector, Vector3.zero, blackHoleSize, true, string.Empty);
break;
default:
break;
}
stellarRemnantController.SetRemnantType(remnantType);
return stellarRemnantController;
return sector.gameObject;
}
catch (Exception ex)
{
@ -260,5 +76,35 @@ namespace NewHorizons.Builder.Body
return null;
}
}
private static GameObject MakeNeutronStar(GameObject root, Sector sector, IModBehaviour mod, StarModule progenitor)
{
var neutronStarSize = progenitor.size / 50;
var neutronStarModule = new StarModule
{
size = neutronStarSize,
tint = new MColor(128, 510, 510, 255),
lightTint = new MColor(128, 255, 255, 255),
lightRadius = 10000,
solarLuminosity = 0.5f,
hasAtmosphere = false
};
// Instead of showing the typical star surface we use a tinted singularity
var (neutronStar, _, _) = StarBuilder.Make(root, sector, neutronStarModule, mod, true);
neutronStar.FindChild("Surface").SetActive(false);
// Modify solar flares
var flares = neutronStar.GetComponentInChildren<SolarFlareEmitter>();
flares.lifeLength = 3;
flares._endScale = 1;
flares.gameObject.transform.localScale = new Vector3(0.85f, 0.85f, 0.85f);
// Add singularity
var singularityRenderer = SingularityBuilder.MakeBlackHoleGraphics(root, neutronStarSize * 2.5f);
singularityRenderer.GetComponent<MeshRenderer>().material.color = new Color(0.5f, 2f, 2f, 1f);
return neutronStar;
}
}
}

View File

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

View File

@ -19,7 +19,6 @@ namespace NewHorizons.Components
public CloudLightningGenerator _lightningGenerator;
public Renderer _topClouds;
public NHSupernovaPlanetEffectController _supernovaPlanetEffectController;
public StellarRemnantProxy _stellarRemnant;
public float _baseRealObjectDiameter;
public override void Awake()
@ -90,39 +89,16 @@ namespace NewHorizons.Components
return;
}
if (_stellarRemnant != null)
{
if (_stellarRemnant.IsActivated())
{
_realObjectDiameter = _stellarRemnant._realObjectDiameter;
_proxyAtan = Mathf.Atan(_stellarRemnant._realObjectDiameter / 42000f);
if (!_stellarRemnant.IsRenderingOn()) ToggleRendering(_outOfRange);
}
else
{
_realObjectDiameter = _baseRealObjectDiameter;
_proxyAtan = Mathf.Atan(_baseRealObjectDiameter / 42000f);
if (_stellarRemnant.IsRenderingOn()) ToggleRendering(_outOfRange);
}
}
base.Update();
}
public override void ToggleRendering(bool on)
{
if (_stellarRemnant != null)
{
_stellarRemnant.ToggleRendering(on);
on = on && !_stellarRemnant.IsActivated();
}
base.ToggleRendering(on);
foreach (Transform child in transform)
{
if (child.gameObject == _star) continue;
if (child.gameObject == _stellarRemnant?.gameObject) continue;
child.gameObject.SetActive(on);
}
@ -168,7 +144,6 @@ namespace NewHorizons.Components
public override void UpdateScale(float scaleMultiplier, float viewDistance)
{
if (_stellarRemnant != null) _stellarRemnant.UpdateScale(scaleMultiplier, viewDistance);
base.UpdateScale(scaleMultiplier, viewDistance);
}
}

View File

@ -11,6 +11,7 @@ namespace NewHorizons.Components.Orbital
public float trueAnomaly { get; set; }
public bool HideDisplayName { get; set; }
public bool IsDimension { get; set; }
public bool invulnerableToSun;
public void SetOrbitalParametersFromConfig(OrbitModule orbit)
{

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.Body;
using NewHorizons.Components.Orbital;
using NewHorizons.External.Modules.VariableSize;
using NewHorizons.Handlers;
using NewHorizons.Utility;
@ -30,18 +31,18 @@ namespace NewHorizons.Components.SizeControllers
private Color _startColour;
private Color _endColour;
private StellarRemnantController _stellarRemnantController;
private GameObject _stellarRemnant;
private PlanetaryFogController _fog;
private MeshRenderer[] _atmosphereRenderers;
public HeatHazardVolume _heatVolume;
public DestructionVolume _destructionVolume;
public StarDestructionVolume _planetDestructionVolume;
public StarFluidVolume _starFluidVolume;
public HeatHazardVolume heatVolume;
public DestructionVolume destructionVolume;
public StarDestructionVolume planetDestructionVolume;
public StarFluidVolume starFluidVolume;
private SolarFlareEmitter _flareEmitter;
private MapMarker _mapMarker;
private OWRigidbody _rigidbody;
public OWAudioSource _oneShotSource;
public OWAudioSource oneShotSource;
private bool _isCollapsing;
private float _collapseStartSize;
@ -137,10 +138,10 @@ namespace NewHorizons.Components.SizeControllers
_endSurfaceMaterial.color = _endColour * 4.5948f;
}
if (_heatVolume == null) _heatVolume = GetComponentInChildren<HeatHazardVolume>();
if (_destructionVolume == null) _destructionVolume = GetComponentInChildren<DestructionVolume>();
if (_planetDestructionVolume == null) _planetDestructionVolume = GetComponentInChildren<StarDestructionVolume>();
if (_starFluidVolume == null) _starFluidVolume = GetComponentInChildren<StarFluidVolume>();
if (heatVolume == null) heatVolume = GetComponentInChildren<HeatHazardVolume>();
if (destructionVolume == null) destructionVolume = GetComponentInChildren<DestructionVolume>();
if (planetDestructionVolume == null) planetDestructionVolume = GetComponentInChildren<StarDestructionVolume>();
if (starFluidVolume == null) starFluidVolume = GetComponentInChildren<StarFluidVolume>();
if (atmosphere != null)
{
@ -246,20 +247,25 @@ namespace NewHorizons.Components.SizeControllers
var t = Mathf.Clamp01((Time.time - (_supernovaStartTime + supernovaScaleStart)) / (supernovaScaleEnd - supernovaScaleStart));
// Make the destruction volume scale slightly smaller so you really have to be in the supernova to die
if (_destructionVolume != null) _destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * Mathf.Lerp(0.9f, 1, t);
if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius();
if (_planetDestructionVolume != null)
if (destructionVolume != null) destructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * Mathf.Lerp(0.9f, 1, t);
if (heatVolume != null) heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius();
if (planetDestructionVolume != null)
{
_planetDestructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * Mathf.Lerp(0.9f, 1, t);
_planetDestructionVolume.GetComponent<SphereCollider>().radius = Mathf.Lerp(0.8f, 1, t);
planetDestructionVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius() * Mathf.Lerp(0.9f, 1, t);
planetDestructionVolume.GetComponent<SphereCollider>().radius = Mathf.Lerp(0.8f, 1, t);
}
if (_stellarRemnantController != null && Time.time > _supernovaStartTime + 15) _stellarRemnantController.PartiallyActivate();
if (_stellarRemnant != null && Time.time > _supernovaStartTime + 15)
{
_stellarRemnant.gameObject.SetActive(true);
var remnantStarController = _stellarRemnant.GetComponentInChildren<StarController>();
if (remnantStarController != null) StarLightController.AddStar(remnantStarController);
}
if (Time.time > _supernovaStartTime + supernovaTime)
{
if (_destructionVolume != null && _destructionVolume._shrinkingBodies.Count > 0) return;
if (_planetDestructionVolume != null && _planetDestructionVolume._shrinkingBodies.Count > 0) return;
if (destructionVolume != null && destructionVolume._shrinkingBodies.Count > 0) return;
if (planetDestructionVolume != null && planetDestructionVolume._shrinkingBodies.Count > 0) return;
DisableStar();
}
}
@ -268,29 +274,29 @@ namespace NewHorizons.Components.SizeControllers
{
if (controller != null) StarLightController.RemoveStar(controller);
// Just turn off the star entirely
if (_isProxy)
gameObject.SetActive(false);
else
if (_stellarRemnant != null)
{
transform.parent.gameObject.SetActive(false); // Turn off sector
if (_stellarRemnantController != null) _stellarRemnantController.FullyActivate();
if (start && _planetDestructionVolume != null)
// If the star is disabled but has a remnant, be sure it is active
_stellarRemnant.gameObject.SetActive(true);
}
else
{
foreach (var collider in Physics.OverlapSphere(_planetDestructionVolume.transform.position, _planetDestructionVolume.GetComponent<SphereCollider>().radius * supernovaSize * 0.9f))
gameObject.SetActive(false);
}
if (start && planetDestructionVolume != null)
{
foreach (var collider in Physics.OverlapSphere(planetDestructionVolume.transform.position, planetDestructionVolume.GetComponent<SphereCollider>().radius * supernovaSize * 0.9f))
{
if (collider.attachedRigidbody != null)
{
// Destroy any planets that are not invulnerable to the sun
var body = collider.attachedRigidbody.GetComponent<OWRigidbody>();
if (body != null && body != _rigidbody)
{
// Vanish anything that is not a player-related object
if (!(collider.attachedRigidbody.CompareTag("Player") || collider.attachedRigidbody.CompareTag("Ship") || collider.attachedRigidbody.CompareTag("ShipCockpit") || collider.attachedRigidbody.CompareTag("Probe")))
{
_planetDestructionVolume.Vanish(body, new RelativeLocationData(body, _rigidbody, _planetDestructionVolume.transform));
}
}
var astroObject = collider.gameObject.GetComponent<NHAstroObject>();
if (astroObject != null && !astroObject.invulnerableToSun)
planetDestructionVolume.Vanish(body, new RelativeLocationData(body, _rigidbody, planetDestructionVolume.transform));
}
}
}
@ -309,7 +315,7 @@ namespace NewHorizons.Components.SizeControllers
_collapseStartSize = CurrentScale;
_collapseTimer = 0f;
supernova._surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial);
if (_oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) _oneShotSource.PlayOneShot(AudioType.Sun_Collapse);
if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse);
if (_proxy != null) _proxy.StartCollapse();
}
@ -338,9 +344,9 @@ namespace NewHorizons.Components.SizeControllers
_isSupernova = true;
_supernovaStartTime = Time.time;
if (atmosphere != null) atmosphere.SetActive(false);
if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova;
if (_planetDestructionVolume != null) _planetDestructionVolume._deathType = DeathType.Supernova;
if (_oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) _oneShotSource.PlayOneShot(AudioType.Sun_Explosion);
if (destructionVolume != null) destructionVolume._deathType = DeathType.Supernova;
if (planetDestructionVolume != null) planetDestructionVolume._deathType = DeathType.Supernova;
if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Explosion);
if (_proxy != null) _proxy.StartSupernova();
}
@ -355,17 +361,17 @@ namespace NewHorizons.Components.SizeControllers
supernova.Deactivate();
_isSupernova = false;
if (atmosphere != null) atmosphere.SetActive(true);
if (_destructionVolume != null)
if (destructionVolume != null)
{
_destructionVolume._deathType = DeathType.Energy;
_destructionVolume.transform.localScale = Vector3.one;
destructionVolume._deathType = DeathType.Energy;
destructionVolume.transform.localScale = Vector3.one;
}
if (_planetDestructionVolume != null)
if (planetDestructionVolume != null)
{
_planetDestructionVolume._deathType = DeathType.Energy;
_planetDestructionVolume.transform.localScale = Vector3.one;
planetDestructionVolume._deathType = DeathType.Energy;
planetDestructionVolume.transform.localScale = Vector3.one;
}
if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one;
if (heatVolume != null) heatVolume.transform.localScale = Vector3.one;
gameObject.SetActive(true);
transform.localScale = Vector3.one;
supernova._surface._materials[0] = _surfaceMaterial;
@ -439,6 +445,6 @@ namespace NewHorizons.Components.SizeControllers
}
}
public void SetStellarRemnantController(StellarRemnantController controller) => _stellarRemnantController = controller;
public void SetStellarRemnant(GameObject stellarRemnant) => _stellarRemnant = stellarRemnant;
}
}

View File

@ -12,12 +12,12 @@ namespace NewHorizons.Components
public float _shockwaveLength = 5f;
public AnimationCurve _shockwaveScale = AnimationCurve.Linear(0.0f, 0.0f, 1f, 100000f);
public AnimationCurve _shockwaveAlpha = AnimationCurve.Linear(0.0f, 1f, 1f, 0.0f);
[Space]
public TessellatedSphereRenderer _surface;
public Material _supernovaMaterial;
public AnimationCurve _supernovaScale = new AnimationCurve(new Keyframe(0, 200, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(45, 50000, 1758.508f, 1758.508f, 1f / 3f, 1f / 3f));
public AnimationCurve _supernovaAlpha = new AnimationCurve(new Keyframe(5, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(15, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(50, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f));
[Space]
public OWAudioSource _audioSource;
public StellarDeathController _main;
private float _time;

View File

@ -1,81 +0,0 @@
using NewHorizons.Components.SizeControllers;
using NewHorizons.External.Modules.VariableSize;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Components
{
public class StellarRemnantController : MonoBehaviour
{
private StellarRemnantType _type = StellarRemnantType.Default;
private bool _activated;
private StarEvolutionController _starEvolutionController;
private StellarRemnantProxy _proxy;
private StarController _starController;
private float _siderealPeriod = 0;
private float _surfaceGravity = 0;
private float _surfaceSize = 0;
private float _sphereOfInfluence = 0;
private float _alignmentRadius = 0;
public StellarRemnantType GetRemnantType() => _type;
public void SetRemnantType(StellarRemnantType type) => _type = type;
public void SetSiderealPeriod(float siderealPeriod) => _siderealPeriod = siderealPeriod;
public void SetSurfaceGravity(float surfaceGravity) => _surfaceGravity = surfaceGravity;
public void SetSurfaceSize(float surfaceSize) => _surfaceSize = surfaceSize;
public void SetAlignmentRadius(float alignmentRadius) => _alignmentRadius = alignmentRadius;
public void SetSphereOfInfluence(float sphereOfInfluence) => _sphereOfInfluence = sphereOfInfluence;
public void SetStarController(StarController starController) => _starController = starController;
public void SetProxy(StellarRemnantProxy proxy) => _proxy = proxy;
public void SetStarEvolutionController(StarEvolutionController controller) => _starEvolutionController = controller;
public void PartiallyActivate()
{
if (!gameObject.activeSelf) gameObject.SetActive(true);
}
public void FullyActivate()
{
if (!gameObject.activeSelf) gameObject.SetActive(true);
var owrb = this.GetAttachedOWRigidbody();
if (owrb != null)
{
owrb.SetAngularVelocity(Vector3.up * (_siderealPeriod == 0 ? 0 : 2 * Mathf.PI / (_siderealPeriod * 60)));
var gravityVolume = owrb.GetAttachedGravityVolume();
if (gravityVolume != null)
{
gravityVolume._alignmentRadius = _alignmentRadius;
gravityVolume._upperSurfaceRadius = _surfaceSize;
gravityVolume._surfaceAcceleration = _surfaceGravity;
gravityVolume._gravitationalMass = _surfaceGravity * Mathf.Pow(_surfaceSize, gravityVolume._falloffExponent) / (1f / 1000f);
if (gravityVolume._setMass) owrb.SetMass(gravityVolume._gravitationalMass);
}
var referenceFrameVolume = owrb._attachedRFVolume;
if (referenceFrameVolume != null)
{
referenceFrameVolume.GetComponent<SphereCollider>().radius = _sphereOfInfluence * 2;
referenceFrameVolume._maxColliderRadius = _sphereOfInfluence * 2;
}
}
if (_starController != null) StarLightController.AddStar(_starController);
_activated = true;
}
public bool IsActivated() => _activated;
}
}

View File

@ -1,152 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static ProxyPlanet;
namespace NewHorizons.Components
{
public class StellarRemnantProxy : MonoBehaviour
{
public float _realObjectDiameter;
public Renderer _atmosphere;
public Renderer _fog;
public float _mieCurveMinDistance = 45000f;
public float _mieCurveMaxDistance = 750000f;
public float _mieCurveMinVal;
public float _mieCurveMaxVal;
public AnimationCurve _mieCurve;
public float _fogCurveMinDistance = 45000f;
public float _fogCurveMaxDistance = 750000f;
public float _fogCurveMinVal;
public float _fogCurveMaxVal;
public AnimationCurve _fogCurve;
public Material _atmosphereMaterial;
public float _baseAtmoMatShellInnerRadius;
public float _baseAtmoMatShellOuterRadius;
public bool _hasAtmosphere;
public bool _hasFog;
public Material _fogMaterial;
public GameObject _star;
public Renderer[] _starRenderers;
public TessellatedRenderer[] _starTessellatedRenderers;
public ParticleSystemRenderer[] _starParticleRenderers;
public SolarFlareEmitter _solarFlareEmitter;
public CloudLightningGenerator _lightningGenerator;
public Renderer _topClouds;
private bool _renderingOn;
public void Awake()
{
_mieCurveMaxVal = 0.1f;
_mieCurve = AnimationCurve.EaseInOut(0.0011f, 1, 1, 0);
_fogCurve = AnimationCurve.Linear(0, 1, 1, 0);
// 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
_star = GetComponentInChildren<TessellatedSphereRenderer>(true)?.transform?.parent?.gameObject;
if (_star != null)
{
_starRenderers = _star.GetComponentsInChildren<Renderer>();
_starTessellatedRenderers = _star.GetComponentsInChildren<TessellatedRenderer>();
_starParticleRenderers = _star.GetComponentsInChildren<ParticleSystemRenderer>();
_solarFlareEmitter = _star.GetComponentInChildren<SolarFlareEmitter>();
}
if (_lightningGenerator == null) _lightningGenerator = GetComponentInChildren<CloudLightningGenerator>();
ToggleRendering(false);
}
public void ToggleRendering(bool on)
{
on = on && IsActivated();
_renderingOn = on;
if (_atmosphere != null) _atmosphere.enabled = on;
if (_fog != null) _fog.enabled = on;
foreach (Transform child in transform)
{
if (child.gameObject == _star) continue;
child.gameObject.SetActive(on);
}
if (_star != null)
{
if (_solarFlareEmitter != null)
{
_solarFlareEmitter.gameObject.SetActive(on);
}
foreach (var renderer in _starRenderers)
{
renderer.enabled = on;
}
foreach (var renderer in _starTessellatedRenderers)
{
renderer.enabled = on;
}
foreach (var renderer in _starParticleRenderers)
{
renderer.enabled = on;
}
}
if (_topClouds != null)
{
_topClouds.enabled = on;
}
if (_lightningGenerator != null)
{
_lightningGenerator.enabled = on;
}
}
public void UpdateScale(float scaleMultiplier, float viewDistance)
{
if (_hasAtmosphere)
{
_atmosphereMaterial.SetFloat(propID_AtmoInnerRadius, _baseAtmoMatShellInnerRadius * scaleMultiplier);
_atmosphereMaterial.SetFloat(propID_AtmoOuterRadius, _baseAtmoMatShellOuterRadius * scaleMultiplier);
_atmosphereMaterial.SetFloat(propID_MieConstant, Mathf.Lerp(_mieCurveMinVal, _mieCurveMaxVal, _mieCurve.Evaluate(Mathf.InverseLerp(_mieCurveMinDistance, _mieCurveMaxDistance, viewDistance))));
}
if (_hasFog) _fogMaterial.SetFloat(propID_FogDensity, Mathf.Lerp(_fogCurveMinVal, _fogCurveMaxVal, _fogCurve.Evaluate(Mathf.InverseLerp(_fogCurveMinDistance, _fogCurveMaxDistance, viewDistance))));
}
public void Initialize()
{
if (_atmosphere != null)
{
_hasAtmosphere = true;
_atmosphereMaterial = new Material(_atmosphere.sharedMaterial);
_baseAtmoMatShellInnerRadius = _atmosphereMaterial.GetFloat(propID_AtmoInnerRadius);
_baseAtmoMatShellOuterRadius = _atmosphereMaterial.GetFloat(propID_AtmoOuterRadius);
_atmosphere.sharedMaterial = _atmosphereMaterial;
}
if (_fog != null)
{
_hasFog = true;
_fogMaterial = new Material(_fog.sharedMaterial);
_fogMaterial.SetFloat(propID_LODFade, 1f);
_fog.sharedMaterial = _fogMaterial;
}
}
public StellarRemnantController _stellarRemnantController;
public void SetStellarRemnantController(StellarRemnantController controller)
{
_stellarRemnantController = controller;
controller.SetProxy(this);
}
public bool IsActivated() => _stellarRemnantController.IsActivated();
public bool IsRenderingOn() => _renderingOn;
}
}

View File

@ -165,11 +165,6 @@ namespace NewHorizons.External.Configs
/// </summary>
public StarModule Star;
/// <summary>
/// Version of New Horizons this config is using (Doesn't do anything)
/// </summary>
public string version;
/// <summary>
/// Add water to this planet
/// </summary>

View File

@ -463,7 +463,7 @@ namespace NewHorizons.Handlers
return go;
}
internal static float GetSphereOfInfluence(NewHorizonsBody body)
private static float GetSphereOfInfluence(NewHorizonsBody body)
{
var atmoSize = body.Config.Atmosphere != null ? body.Config.Atmosphere.size : 0f;
float sphereOfInfluence = Mathf.Max(Mathf.Max(atmoSize, 50), body.Config.Base.surfaceSize * 2f);
@ -473,7 +473,7 @@ namespace NewHorizons.Handlers
}
// What is called both on existing planets and new planets
internal static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb)
private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb)
{
var sphereOfInfluence = GetSphereOfInfluence(body);
@ -504,14 +504,34 @@ namespace NewHorizons.Handlers
if (body.Config.Star != null)
{
if (body.Config.isStellarRemnant)
var (star, starController, starEvolutionController) = StarBuilder.Make(go, sector, body.Config.Star, body.Mod, false);
if (starController != null) StarLightController.AddStar(starController);
// If it has an evolution controller that means it will die -> we make a remnant
if (starEvolutionController != null)
{
sector.GetComponent<StellarRemnantController>().SetStarController(StarBuilder.Make(go, sector, body.Config.Star, body.Mod, true));
}
else
{
StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star, body.Mod, false));
StellarRemnantBuilder.Make(body, go, rb, body.Mod, Main.BodyDict[body.Config.starSystem].Where(x => x.Config.name == body.Config.name && x.Config.isStellarRemnant).FirstOrDefault());
GameObject remnantGO;
// Create the remnant as if it were a planet
if (body.Config.Star.stellarRemnantType == External.Modules.VariableSize.StellarRemnantType.Custom)
{
var remnant = Main.BodyDict[body.Config.starSystem].Where(x => x.Config.name == body.Config.name && x.Config.isStellarRemnant).FirstOrDefault();
var remnantSector = SectorBuilder.Make(go, rb, sphereOfInfluence);
remnantSector.name = "CustomStellarRemnant";
SharedGenerateBody(remnant, go, remnantSector, rb);
remnantGO = remnantSector.gameObject;
}
else
{
remnantGO = StellarRemnantBuilder.Make(go, rb, sphereOfInfluence, body.Mod, body);
}
remnantGO.SetActive(false);
starEvolutionController.SetStellarRemnant(remnantGO);
}
}