mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add opacity curve to rings
This commit is contained in:
parent
93a26e6341
commit
a84c243f7a
Binary file not shown.
@ -133,6 +133,13 @@ namespace NewHorizons.Builder.Body
|
||||
levelController.SetScaleCurve(ring.curve);
|
||||
}
|
||||
|
||||
if (ring.opacity != null)
|
||||
{
|
||||
var ringOC = ringGO.AddComponent<RingOpacityController>();
|
||||
ringOC.SetOpacityCurve(ring.opacity);
|
||||
ringOC.SetMeshRenderer(ringMR);
|
||||
}
|
||||
|
||||
return ringGO;
|
||||
}
|
||||
|
||||
|
||||
42
NewHorizons/Components/RingOpacityController.cs
Normal file
42
NewHorizons/Components/RingOpacityController.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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?
|
||||
/// </summary>
|
||||
public bool unlit;
|
||||
|
||||
/// <summary>
|
||||
/// Fade this module over time
|
||||
/// </summary>
|
||||
public TimeValuePair[] opacity;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user