Merge branch 'master' into external-rework-2

This commit is contained in:
Nick 2022-05-17 20:41:09 -04:00
commit ac69892488
13 changed files with 354 additions and 65 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

View File

@ -7,7 +7,7 @@ namespace NewHorizons.Builder.Atmosphere
public static void Make(GameObject planetGO, PlanetConfig config, float sphereOfInfluence)
{
var innerRadius = config.Base.SurfaceSize;
var useMiniMap = config.Base.IsSatellite;
var useMiniMap = !config.Base.IsSatellite;
GameObject volumesGO = new GameObject("Volumes");
volumesGO.SetActive(false);

View File

@ -21,7 +21,7 @@ namespace NewHorizons.Builder.Body
private static readonly string _whiteHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity";
public static void Make(GameObject gameObject, NewHorizonsBody body)
public static void Make(GameObject planetGO, NewHorizonsBody body)
{
if (lavaMaterial == null) lavaMaterial = SearchUtilities.FindObjectOfTypeAndName<ProxyOrbiter>("VolcanicMoon_Body").transform.Find("LavaSphere").GetComponent<MeshRenderer>().material;
@ -56,9 +56,7 @@ namespace NewHorizons.Builder.Body
}
if (body.Config.Star != null)
{
var starGO = StarBuilder.MakeStarGraphics(newProxy, null, body.Config.Star);
if (body.Config.Star.Curve != null) AddSizeController(starGO, body.Config.Star.Curve, body.Config.Star.Size);
var starGO = StarBuilder.MakeStarProxy(planetGO, newProxy, body.Config.Star);
if (realSize < body.Config.Star.Size) realSize = body.Config.Star.Size;
}
@ -134,8 +132,6 @@ namespace NewHorizons.Builder.Body
var proxyController = newProxy.AddComponent<NHProxy>();
proxyController.astroName = body.Config.Name;
proxyController._realObjectDiameter = realSize;
proxyController.renderers = newProxy.GetComponentsInChildren<Renderer>();
proxyController.tessellatedRenderers = newProxy.GetComponentsInChildren<TessellatedRenderer>();
}
catch (Exception ex)
{

View File

@ -26,20 +26,23 @@ namespace NewHorizons.Builder.Body
sunAudio.name = "Audio_Star";
GameObject sunAtmosphere = null;
if (starModule.HasAtmosphere)
{
var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), planetGO.transform);
sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform);
sunAtmosphere.transform.position = planetGO.transform.position;
sunAtmosphere.transform.localScale = Vector3.one;
sunAtmosphere.transform.localScale = Vector3.one * OuterRadiusRatio;
sunAtmosphere.name = "Atmosphere_Star";
PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
if (starModule.Tint != null)
{
fog.fogTint = starModule.Tint.ToColor();
sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size * OuterRadiusRatio);
sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one;
foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>())
{
lod.material.SetColor("_SkyColor", starModule.Tint.ToColor());
lod.material.SetColor("_AtmosFar", starModule.Tint.ToColor());
lod.material.SetColor("_AtmosNear", starModule.Tint.ToColor());
lod.material.SetFloat("_InnerRadius", starModule.Size);
lod.material.SetFloat("_OuterRadius", starModule.Size * OuterRadiusRatio);
}
@ -47,6 +50,7 @@ namespace NewHorizons.Builder.Body
fog.transform.localScale = Vector3.one;
fog.fogRadius = starModule.Size * OuterRadiusRatio;
fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f);
if (starModule.Curve != null)
{
var controller = sunAtmosphere.AddComponent<StarAtmosphereSizeController>();
@ -70,7 +74,7 @@ namespace NewHorizons.Builder.Body
deathVolume.transform.localScale = Vector3.one;
deathVolume.GetComponent<SphereCollider>().radius = 1f;
deathVolume.GetComponent<DestructionVolume>()._onlyAffectsPlayerAndShip = false;
deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = false;
deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = true;
deathVolume.name = "DestructionVolume";
Light ambientLight = ambientLightGO.GetComponent<Light>();
@ -123,20 +127,47 @@ namespace NewHorizons.Builder.Body
starController.SunColor = lightColour;
}
if (starModule.Curve != null)
{
var levelController = starGO.AddComponent<SandLevelController>();
var curve = new AnimationCurve();
foreach (var pair in starModule.Curve)
{
curve.AddKey(new Keyframe(pair.Time, starModule.Size * pair.Value));
}
levelController._scaleCurve = curve;
}
var supernova = MakeSupernova(starGO, starModule);
var controller = starGO.AddComponent<StarEvolutionController>();
if(starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve();
controller.size = starModule.Size;
controller.atmosphere = sunAtmosphere;
controller.supernova = supernova;
controller.startColour = starModule.Tint;
controller.endColour = starModule.EndTint;
controller.willExplode = starModule.GoSupernova;
// It fucking insists on this existing and its really annoying
var supernovaVolume = new GameObject("SupernovaVolumePlaceholder");
supernovaVolume.transform.SetParent(starGO.transform);
supernova._supernovaVolume = supernovaVolume.AddComponent<SupernovaDestructionVolume>();
var sphere = supernovaVolume.AddComponent<SphereShape>();
sphere.radius = 0f;
supernovaVolume.AddComponent<OWCollider>();
return starController;
}
public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule)
{
var starGO = MakeStarGraphics(proxyGO, null, starModule);
var supernova = MakeSupernova(starGO, starModule);
var controller = starGO.AddComponent<StarEvolutionController>();
if (starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve();
controller.size = starModule.Size;
controller.supernova = supernova;
controller.startColour = starModule.Tint;
controller.endColour = starModule.EndTint;
controller.enabled = true;
planet.GetComponentInChildren<StarEvolutionController>().SetProxy(controller);
return proxyGO;
}
public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule)
{
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/StarColorOverTime.png");
@ -184,5 +215,34 @@ namespace NewHorizons.Builder.Body
return starGO;
}
private static SupernovaEffectController MakeSupernova(GameObject starGO, StarModule starModule)
{
var supernovaGO = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/Supernova").InstantiateInactive();
supernovaGO.transform.SetParent(starGO.transform);
supernovaGO.transform.localPosition = Vector3.zero;
var supernova = supernovaGO.GetComponent<SupernovaEffectController>();
supernova._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>();
supernova._supernovaVolume = null;
if(starModule.SupernovaTint != null)
{
var colour = starModule.SupernovaTint.ToColor();
var supernovaMaterial = new Material(supernova._supernovaMaterial);
var ramp = ImageUtilities.LerpGreyscaleImage(ImageUtilities.GetTexture(Main.Instance, "AssetBundle/Effects_SUN_Supernova_d.png"), Color.white, colour);
supernovaMaterial.SetTexture("_ColorRamp", ramp);
supernova._supernovaMaterial = supernovaMaterial;
// Motes
var moteMaterial = supernova.GetComponentInChildren<ParticleSystemRenderer>().material;
moteMaterial.color = new Color(colour.r * 3f, colour.g * 3f, colour.b * 3f, moteMaterial.color.a);
}
supernovaGO.SetActive(true);
return supernova;
}
}
}

View File

@ -103,17 +103,17 @@ namespace NewHorizons.Builder.ShipLog
ShipLogAstroObject astroObject = gameObject.AddComponent<ShipLogAstroObject>();
astroObject._id = ShipLogHandler.GetAstroObjectId(body);
Texture2D image;
Texture2D outline;
Texture2D image = null;
Texture2D outline = null;
string imagePath = body.Config.ShipLog?.mapMode?.revealedSprite;
string outlinePath = body.Config.ShipLog?.mapMode?.outlineSprite;
if (imagePath != null) image = ImageUtilities.GetTexture(body.Mod, imagePath);
else image = AutoGenerateMapModePicture(body);
if (image == null) image = AutoGenerateMapModePicture(body);
if (outlinePath != null) outline = ImageUtilities.GetTexture(body.Mod, outlinePath);
else outline = ImageUtilities.MakeOutline(image, Color.white, 10);
if (outline == null) outline = ImageUtilities.MakeOutline(image, Color.white, 10);
astroObject._imageObj = CreateImage(gameObject, image, body.Config.Name + " Revealed", layer);
astroObject._outlineObj = CreateImage(gameObject, outline, body.Config.Name + " Outline", layer);

View File

@ -1,12 +1,35 @@
using NewHorizons.Utility;
using NewHorizons.Components.SizeControllers;
using NewHorizons.Utility;
using System.Collections.Generic;
using UnityEngine;
namespace NewHorizons.Components
{
public class NHProxy : ProxyPlanet
{
public string astroName;
public Renderer[] renderers;
public TessellatedRenderer[] tessellatedRenderers;
private GameObject _star;
private Renderer[] _starRenderers;
private TessellatedRenderer[] _starTessellatedRenderers;
public override void Awake()
{
base.Awake();
// 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<StarEvolutionController>()?.gameObject;
if(_star != null)
{
_starRenderers = _star.GetComponentsInChildren<Renderer>();
_starTessellatedRenderers = _star.GetComponentsInChildren<TessellatedRenderer>();
}
// Start off
_outOfRange = false;
ToggleRendering(false);
}
public override void Initialize()
{
@ -32,10 +55,25 @@ namespace NewHorizons.Components
public override void ToggleRendering(bool on)
{
base.ToggleRendering(on);
foreach (Transform child in transform)
{
if (child.gameObject == _star) continue;
child.gameObject.SetActive(on);
}
if(_star != null)
{
foreach (var renderer in _starRenderers)
{
renderer.enabled = on;
}
foreach (var renderer in _starTessellatedRenderers)
{
renderer.enabled = on;
}
}
}
}
}

View File

@ -4,13 +4,21 @@ namespace NewHorizons.Components.SizeControllers
public class SizeController : MonoBehaviour
{
public AnimationCurve scaleCurve;
public float CurrentScale { get; private set; }
public float CurrentScale { get; protected set; }
public float size = 1f;
protected void FixedUpdate()
{
if(scaleCurve != null)
{
CurrentScale = scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed()) * size;
base.transform.localScale = new Vector3(CurrentScale, CurrentScale, CurrentScale);
}
else
{
CurrentScale = size;
}
base.transform.localScale = Vector3.one * CurrentScale;
}
}
}

View File

@ -1,29 +0,0 @@
using NewHorizons.Builder.Body;
using UnityEngine;
namespace NewHorizons.Components.SizeControllers
{
public class StarAtmosphereSizeController : SizeController
{
private PlanetaryFogController fog;
public float initialSize;
private MeshRenderer[] atmosphereRenderers;
void Awake()
{
fog = GetComponentInChildren<PlanetaryFogController>();
atmosphereRenderers = transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>();
}
protected new void FixedUpdate()
{
base.FixedUpdate();
fog.fogRadius = initialSize * CurrentScale * StarBuilder.OuterRadiusRatio;
fog.lodFadeDistance = initialSize * CurrentScale * (StarBuilder.OuterRadiusRatio - 1f);
foreach (var lod in atmosphereRenderers)
{
lod.material.SetFloat("_InnerRadius", initialSize * CurrentScale);
lod.material.SetFloat("_OuterRadius", initialSize * CurrentScale * StarBuilder.OuterRadiusRatio);
}
}
}
}

View File

@ -0,0 +1,200 @@
using NewHorizons.Builder.Body;
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Components.SizeControllers
{
public class StarEvolutionController : SizeController
{
public GameObject atmosphere;
public SupernovaEffectController supernova;
public bool willExplode;
public MColor startColour { get; set; }
public MColor endColour { get; set; }
private Color _startColour;
private Color _endColour;
private PlanetaryFogController _fog;
private MeshRenderer[] _atmosphereRenderers;
private HeatHazardVolume _heatVolume;
private DestructionVolume _destructionVolume;
private bool _isCollapsing;
private float _collapseStartSize;
private float _collapseTimer;
public float collapseTime = 5f; // seconds
public float lifespan = 22f; // minutes
private float _age;
private bool _isSupernova;
private float _supernovaStartTime;
private Material _collapseStartSurfaceMaterial;
private Material _collapseEndSurfaceMaterial;
private Material _startSurfaceMaterial;
private Material _endSurfaceMaterial;
private StarEvolutionController _proxy;
void Awake()
{
var sun = GameObject.FindObjectOfType<SunController>();
_collapseStartSurfaceMaterial = new Material(sun._collapseStartSurfaceMaterial);
_collapseEndSurfaceMaterial = new Material(sun._collapseEndSurfaceMaterial);
_startSurfaceMaterial = new Material(sun._startSurfaceMaterial);
_endSurfaceMaterial = new Material(sun._endSurfaceMaterial);
// Copy over the material that was set in star builder
_collapseStartSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
_collapseEndSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
_startSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
_endSurfaceMaterial.SetTexture("_ColorRamp", supernova._surface.sharedMaterial.GetTexture("_ColorRamp"));
if (startColour == null)
{
_startColour = _startSurfaceMaterial.color;
}
else
{
_startColour = startColour.ToColor();
_startSurfaceMaterial.color = _startColour;
}
if (endColour == null)
{
_endColour = _startColour;
_endSurfaceMaterial.color = _startColour;
}
else
{
_endColour = endColour.ToColor();
_endSurfaceMaterial.color = _endColour;
}
_heatVolume = GetComponentInChildren<HeatHazardVolume>();
_destructionVolume = GetComponentInChildren<DestructionVolume>();
if (atmosphere != null)
{
_fog = atmosphere?.GetComponentInChildren<PlanetaryFogController>();
_atmosphereRenderers = atmosphere?.transform?.Find("AtmoSphere")?.GetComponentsInChildren<MeshRenderer>();
}
if (willExplode) GlobalMessenger.AddListener("TriggerSupernova", Die);
}
public void OnDestroy()
{
if (willExplode) GlobalMessenger.RemoveListener("TriggerSupernova", Die);
}
public void SetProxy(StarEvolutionController proxy)
{
_proxy = proxy;
_proxy.supernova.SetIsProxy(true);
}
public void Die()
{
_isCollapsing = true;
_collapseStartSize = CurrentScale;
_collapseTimer = 0f;
if (_proxy != null) _proxy.Die();
}
protected new void FixedUpdate()
{
_age += Time.deltaTime;
var ageValue = _age / (lifespan * 60f);
// If we've gone supernova and its been 45 seconds that means it has faded out and is gone
// The 45 is from the animation curve used for the supernova alpha
if (_isSupernova)
{
// Reset the scale back to normal bc now its just the supernova scaling itself + destruction and heat volumes
transform.localScale = Vector3.one;
// 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() * 0.9f;
if (_heatVolume != null) _heatVolume.transform.localScale = Vector3.one * supernova.GetSupernovaRadius();
if (Time.time > _supernovaStartTime + 45f)
{
// Just turn off the star entirely
base.gameObject.SetActive(false);
}
return;
}
Color currentColour;
if (!_isCollapsing)
{
base.FixedUpdate();
currentColour = Color.Lerp(_startColour, _endColour, ageValue);
supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, ageValue);
}
else
{
// When its collapsing we directly take over the scale
var t = _collapseTimer / collapseTime;
CurrentScale = Mathf.Lerp(_collapseStartSize, 0, t);
transform.localScale = Vector3.one * CurrentScale;
_collapseTimer += Time.deltaTime;
currentColour = Color.Lerp(_endColour, Color.white, t);
supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t);
// After the collapse is done we go supernova
if (_collapseTimer > collapseTime)
{
supernova.enabled = true;
_isSupernova = true;
_supernovaStartTime = Time.time;
atmosphere.SetActive(false);
_destructionVolume._deathType = DeathType.Supernova;
return;
}
}
// This is just all the scales stuff for the atmosphere effects
if (_fog != null)
{
_fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio;
_fog.lodFadeDistance = CurrentScale * StarBuilder.OuterRadiusRatio / 3f;
// The colour thing goes over one
var max = Math.Max(currentColour.g, Math.Max(currentColour.b, currentColour.r));
var fogColour = currentColour / max / 1.5f;
fogColour.a = 1f;
_fog.fogTint = fogColour;
_fog._fogTint = fogColour;
}
if (_atmosphereRenderers != null && _atmosphereRenderers.Count() > 0)
{
foreach (var lod in _atmosphereRenderers)
{
lod.material.SetFloat("_InnerRadius", CurrentScale);
lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio);
lod.material.SetColor("_AtmosFar", currentColour);
lod.material.SetColor("_AtmosNear", currentColour);
lod.material.SetColor("_SkyColor", currentColour);
}
}
}
}
}

View File

@ -1,13 +1,17 @@
using NewHorizons.Utility;
namespace NewHorizons.External.Modules.VariableSize
{
public class StarModule : VariableSizeModule
{
public float Size { get; set; } = 2000f;
public MColor Tint { get; set; }
public MColor EndTint { get; set; }
public MColor SupernovaTint { get; set; }
public MColor SolarFlareTint { get; set; }
public MColor LightTint { get; set; }
public float SolarLuminosity { get; set; } = 1f;
public bool HasAtmosphere { get; set; } = true;
public bool GoSupernova { get; set; } = true;
}
}

View File

@ -14,10 +14,13 @@ namespace NewHorizons.External.Modules.VariableSize
public AnimationCurve GetAnimationCurve(float size = 1f)
{
var curve = new AnimationCurve();
if(Curve != null)
{
foreach (var pair in this.Curve)
{
curve.AddKey(new Keyframe(pair.Time, size * pair.Value));
}
}
return curve;
}
}

View File

@ -596,6 +596,10 @@
"$ref": "#/$defs/color",
"description": "Colour of the star."
},
"endTint": {
"$ref": "#/$defs/color",
"description": "Colour of the star at the end of its life."
},
"solarFlareTint": {
"$ref": "#/$defs/color",
"description": "Colour of the solar flares. The shader is a bit weird so the value you put won't exactly reflect what you see. Try experimenting with different colours to see what works."
@ -618,6 +622,11 @@
"curve": {
"$ref": "#/$defs/curve",
"description": "Allows the star to shrink/grow over time."
},
"goSupernova": {
"type": "boolean",
"default": true,
"description": "Should this star explode after 22 minutes?"
}
}
},

View File

@ -3,7 +3,7 @@
"author": "xen, Bwc9876, & Book",
"name": "New Horizons",
"uniqueName": "xen.NewHorizons",
"version": "0.17.0",
"version": "0.18.0",
"owmlVersion": "2.1.0",
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.AutoResume", "PacificEngine.OW_Randomizer" ],
"pathsToPreserve": [ "planets", "systems", "translations" ]