32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace SmartRoom
|
|
{
|
|
/// <summary>Deckenbeleuchtung: weiches Dimmen von Leuchtpanels und Lichtquellen.</summary>
|
|
public class LightActuator : MonoBehaviour
|
|
{
|
|
[Range(0, 1)] public float target = 0.6f;
|
|
public float speed = 1.2f;
|
|
public float maxIntensity = 1f;
|
|
public Material panelMaterial;
|
|
public List<Light> lamps = new List<Light>();
|
|
|
|
public float Current { get; private set; }
|
|
|
|
static readonly Color Warm = new Color(1f, 0.97f, 0.9f);
|
|
|
|
void Update()
|
|
{
|
|
Current = Mathf.MoveTowards(Current, target, speed * Time.deltaTime);
|
|
foreach (var l in lamps)
|
|
{
|
|
l.intensity = maxIntensity * Current;
|
|
l.enabled = Current > 0.001f;
|
|
}
|
|
Mat.SetColor(panelMaterial, Color.Lerp(new Color(0.75f, 0.75f, 0.75f), Color.white, Current));
|
|
Mat.SetEmission(panelMaterial, Warm * (Current * 1.6f));
|
|
}
|
|
}
|
|
}
|