diff --git a/NewHorizons/Assets/xen.newhorizons b/NewHorizons/Assets/xen.newhorizons index ec531739..ad4180e0 100644 Binary files a/NewHorizons/Assets/xen.newhorizons and b/NewHorizons/Assets/xen.newhorizons differ diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index c39dabf6..652ca524 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -133,6 +133,13 @@ namespace NewHorizons.Builder.Body levelController.SetScaleCurve(ring.curve); } + if (ring.opacity != null) + { + var ringOC = ringGO.AddComponent(); + ringOC.SetOpacityCurve(ring.opacity); + ringOC.SetMeshRenderer(ringMR); + } + return ringGO; } diff --git a/NewHorizons/Components/RingOpacityController.cs b/NewHorizons/Components/RingOpacityController.cs new file mode 100644 index 00000000..adc3924b --- /dev/null +++ b/NewHorizons/Components/RingOpacityController.cs @@ -0,0 +1,42 @@ +using NewHorizons.External.Modules.VariableSize; +using UnityEngine; + +namespace NewHorizons.Components +{ + public class RingOpacityController : MonoBehaviour + { + private static readonly int Alpha = Shader.PropertyToID("_Alpha"); + + public AnimationCurve opacityCurve { get; protected set; } + public float CurrentOpacity { get; protected set; } + + private MeshRenderer _meshRenderer; + + protected void FixedUpdate() + { + if (opacityCurve != null) + { + CurrentOpacity = opacityCurve.Evaluate(TimeLoop.GetMinutesElapsed()); + } + else + { + CurrentOpacity = 1; + } + + if (_meshRenderer == null) return; + + _meshRenderer.material.SetFloat(Alpha, CurrentOpacity); + } + + public void SetOpacityCurve(VariableSizeModule.TimeValuePair[] curve) + { + opacityCurve = new AnimationCurve(); + foreach (var pair in curve) + { + opacityCurve.AddKey(new Keyframe(pair.time, pair.value)); + } + } + + public void SetMeshRenderer(MeshRenderer meshRenderer) => _meshRenderer = meshRenderer; + } +} diff --git a/NewHorizons/External/Modules/VariableSize/RingModule.cs b/NewHorizons/External/Modules/VariableSize/RingModule.cs index dd0ecaf2..3030df30 100644 --- a/NewHorizons/External/Modules/VariableSize/RingModule.cs +++ b/NewHorizons/External/Modules/VariableSize/RingModule.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Newtonsoft.Json; namespace NewHorizons.External.Modules.VariableSize @@ -45,5 +45,10 @@ namespace NewHorizons.External.Modules.VariableSize /// Should this ring be unlit? /// public bool unlit; + + /// + /// Fade this module over time + /// + public TimeValuePair[] opacity; } } \ No newline at end of file