76 lines
3.6 KiB
C#
76 lines
3.6 KiB
C#
using UnityEngine;
|
|
|
|
namespace Unheimlich.World.HouseOfLeaves
|
|
{
|
|
/// <summary>
|
|
/// Animates the sand terrain shader progression based on the player's
|
|
/// advancement through the corridor.
|
|
///
|
|
/// Drives the _Progression float on the sand material from 0 to 1,
|
|
/// simulating sand flooding the corridor as the player advances.
|
|
/// </summary>
|
|
public class SandTerrainController : MonoBehaviour
|
|
{
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
// Serialized Fields
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
|
|
[Header("References")]
|
|
[Tooltip("The HouseOfLeavesController driving the progression value.")]
|
|
[SerializeField] private HouseOfLeavesController _controller;
|
|
|
|
[Tooltip("The sand terrain Transform holding the sand material.")]
|
|
[SerializeField] private Transform _sandTerrain;
|
|
|
|
[Header("Progression Settings")]
|
|
[Tooltip("Animation curve mapping progression [0,1] to shader value [0,1]. " +
|
|
"Use this to delay or ease the sand appearance.")]
|
|
[SerializeField] private AnimationCurve _riseCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
// Private Fields
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
|
|
private Renderer _renderer;
|
|
|
|
private static readonly int ProgressionID = Shader.PropertyToID("_Progression");
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
// Unity Messages
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
|
|
private void Start()
|
|
{
|
|
if (_controller == null)
|
|
{
|
|
Debug.LogError("[SandTerrainController] HouseOfLeavesController reference is missing.");
|
|
return;
|
|
}
|
|
|
|
if (_sandTerrain == null)
|
|
{
|
|
Debug.LogError("[SandTerrainController] Sand terrain Transform is missing.");
|
|
return;
|
|
}
|
|
|
|
_renderer = _sandTerrain.GetComponent<Renderer>();
|
|
|
|
if (_renderer == null)
|
|
{
|
|
Debug.LogError("[SandTerrainController] No Renderer found on sand terrain.");
|
|
return;
|
|
}
|
|
|
|
// Initialize shader progression to zero.
|
|
_renderer.material.SetFloat(ProgressionID, 0f);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_controller == null || _renderer == null) return;
|
|
|
|
float t = _riseCurve.Evaluate(_controller.Progression);
|
|
_renderer.material.SetFloat(ProgressionID, t);
|
|
}
|
|
}
|
|
} |