mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Set up star evolution controller
This commit is contained in:
parent
ffedbd5b0d
commit
c58bcb36b0
@ -33,9 +33,10 @@ namespace NewHorizons.Builder.Body
|
|||||||
|
|
||||||
sunAudio.name = "Audio_Star";
|
sunAudio.name = "Audio_Star";
|
||||||
|
|
||||||
|
GameObject sunAtmosphere = null;
|
||||||
if (starModule.HasAtmosphere)
|
if (starModule.HasAtmosphere)
|
||||||
{
|
{
|
||||||
var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), planetGO.transform);
|
sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), planetGO.transform);
|
||||||
sunAtmosphere.transform.position = planetGO.transform.position;
|
sunAtmosphere.transform.position = planetGO.transform.position;
|
||||||
sunAtmosphere.transform.localScale = Vector3.one;
|
sunAtmosphere.transform.localScale = Vector3.one;
|
||||||
sunAtmosphere.name = "Atmosphere_Star";
|
sunAtmosphere.name = "Atmosphere_Star";
|
||||||
@ -54,12 +55,6 @@ namespace NewHorizons.Builder.Body
|
|||||||
fog.transform.localScale = Vector3.one;
|
fog.transform.localScale = Vector3.one;
|
||||||
fog.fogRadius = starModule.Size * OuterRadiusRatio;
|
fog.fogRadius = starModule.Size * OuterRadiusRatio;
|
||||||
fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f);
|
fog.lodFadeDistance = fog.fogRadius * (StarBuilder.OuterRadiusRatio - 1f);
|
||||||
if (starModule.Curve != null)
|
|
||||||
{
|
|
||||||
var controller = sunAtmosphere.AddComponent<StarAtmosphereSizeController>();
|
|
||||||
controller.scaleCurve = starModule.ToAnimationCurve();
|
|
||||||
controller.initialSize = starModule.Size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform);
|
var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform);
|
||||||
@ -130,20 +125,31 @@ namespace NewHorizons.Builder.Body
|
|||||||
starController.SunColor = lightColour;
|
starController.SunColor = lightColour;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (starModule.Curve != null)
|
var supernova = MakeSupernova(starGO);
|
||||||
{
|
|
||||||
var levelController = starGO.AddComponent<SandLevelController>();
|
var controller = starGO.AddComponent<StarEvolutionController>();
|
||||||
var curve = new AnimationCurve();
|
if(starModule.Curve != null) controller.scaleCurve = starModule.ToAnimationCurve();
|
||||||
foreach (var pair in starModule.Curve)
|
controller.size = starModule.Size;
|
||||||
{
|
controller.atmosphere = sunAtmosphere;
|
||||||
curve.AddKey(new Keyframe(pair.Time, starModule.Size * pair.Value));
|
controller.supernova = supernova;
|
||||||
}
|
|
||||||
levelController._scaleCurve = curve;
|
|
||||||
}
|
|
||||||
|
|
||||||
return starController;
|
return starController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GameObject MakeStarProxy(GameObject planetGO, StarModule starModule)
|
||||||
|
{
|
||||||
|
MakeStarGraphics(planetGO, null, starModule);
|
||||||
|
|
||||||
|
if (starModule.Curve != null)
|
||||||
|
{
|
||||||
|
var controller = planetGO.AddComponent<StarEvolutionController>();
|
||||||
|
controller.scaleCurve = starModule.ToAnimationCurve();
|
||||||
|
controller.size = starModule.Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return planetGO;
|
||||||
|
}
|
||||||
|
|
||||||
public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule)
|
public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule)
|
||||||
{
|
{
|
||||||
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/StarColorOverTime.png");
|
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/StarColorOverTime.png");
|
||||||
@ -191,5 +197,19 @@ namespace NewHorizons.Builder.Body
|
|||||||
|
|
||||||
return starGO;
|
return starGO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SupernovaEffectController MakeSupernova(GameObject starGO)
|
||||||
|
{
|
||||||
|
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>();
|
||||||
|
|
||||||
|
supernovaGO.SetActive(true);
|
||||||
|
|
||||||
|
return supernova;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ namespace NewHorizons.Components.SizeControllers
|
|||||||
public class SizeController : MonoBehaviour
|
public class SizeController : MonoBehaviour
|
||||||
{
|
{
|
||||||
public AnimationCurve scaleCurve;
|
public AnimationCurve scaleCurve;
|
||||||
public float CurrentScale { get; private set; }
|
public float CurrentScale { get; protected set; }
|
||||||
public float size = 1f;
|
public float size = 1f;
|
||||||
|
|
||||||
protected void FixedUpdate()
|
protected void FixedUpdate()
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
using NewHorizons.Builder.Body;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
using NewHorizons.Builder.Body;
|
||||||
|
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;
|
||||||
|
|
||||||
|
private PlanetaryFogController _fog;
|
||||||
|
private MeshRenderer[] _atmosphereRenderers;
|
||||||
|
|
||||||
|
private bool _isCollapsing;
|
||||||
|
private float _collapseStartSize;
|
||||||
|
private float _collapseTimer;
|
||||||
|
|
||||||
|
public float collapseTime = 5f;
|
||||||
|
|
||||||
|
private bool _isSupernova;
|
||||||
|
private float _supernovaStartTime;
|
||||||
|
|
||||||
|
private Material _collapseStartSurfaceMaterial;
|
||||||
|
private Material _collapseEndSurfaceMaterial;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
var sun = GameObject.FindObjectOfType<SunController>();
|
||||||
|
_collapseStartSurfaceMaterial = sun._collapseStartSurfaceMaterial;
|
||||||
|
_collapseEndSurfaceMaterial = sun._collapseEndSurfaceMaterial;
|
||||||
|
|
||||||
|
if (atmosphere != null)
|
||||||
|
{
|
||||||
|
_fog = atmosphere.GetComponentInChildren<PlanetaryFogController>();
|
||||||
|
_atmosphereRenderers = atmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Die()
|
||||||
|
{
|
||||||
|
_isCollapsing = true;
|
||||||
|
_collapseStartSize = CurrentScale;
|
||||||
|
_collapseTimer = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected new void FixedUpdate()
|
||||||
|
{
|
||||||
|
// If we've gone supernova and its been 30 seconds that means it has faded out and is gone
|
||||||
|
if (_isSupernova)
|
||||||
|
{
|
||||||
|
transform.localScale = Vector3.one;
|
||||||
|
if (Time.time > _supernovaStartTime + 30f)
|
||||||
|
{
|
||||||
|
base.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_isCollapsing)
|
||||||
|
{
|
||||||
|
base.FixedUpdate();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
|
supernova._surface._materials[0].Lerp(this._collapseStartSurfaceMaterial, this._collapseEndSurfaceMaterial, t);
|
||||||
|
|
||||||
|
// After the collapse is done we go supernova
|
||||||
|
if (_collapseTimer > collapseTime)
|
||||||
|
{
|
||||||
|
supernova.enabled = true;
|
||||||
|
_isSupernova = true;
|
||||||
|
_supernovaStartTime = Time.time;
|
||||||
|
atmosphere.SetActive(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is just all the scales stuff for the atmosphere effects
|
||||||
|
if (atmosphere != null)
|
||||||
|
{
|
||||||
|
atmosphere.transform.localScale = CurrentScale * Vector3.one;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_fog != null)
|
||||||
|
{
|
||||||
|
_fog.fogRadius = CurrentScale * StarBuilder.OuterRadiusRatio;
|
||||||
|
_fog.lodFadeDistance = CurrentScale * (StarBuilder.OuterRadiusRatio - 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_atmosphereRenderers.Count() > 0)
|
||||||
|
{
|
||||||
|
foreach (var lod in _atmosphereRenderers)
|
||||||
|
{
|
||||||
|
lod.material.SetFloat("_InnerRadius", CurrentScale);
|
||||||
|
lod.material.SetFloat("_OuterRadius", CurrentScale * StarBuilder.OuterRadiusRatio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,10 +20,13 @@ namespace NewHorizons.External.VariableSize
|
|||||||
public AnimationCurve ToAnimationCurve(float size = 1f)
|
public AnimationCurve ToAnimationCurve(float size = 1f)
|
||||||
{
|
{
|
||||||
var curve = new AnimationCurve();
|
var curve = new AnimationCurve();
|
||||||
|
if(Curve != null)
|
||||||
|
{
|
||||||
foreach (var pair in this.Curve)
|
foreach (var pair in this.Curve)
|
||||||
{
|
{
|
||||||
curve.AddKey(new Keyframe(pair.Time, size * pair.Value));
|
curve.AddKey(new Keyframe(pair.Time, size * pair.Value));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return curve;
|
return curve;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user