using UnityEngine; namespace SmartRoom { /// /// Außenjalousie: die Endschiene fährt herunter, Lamellen werden nacheinander aus dem Paket /// "abgewickelt" und stellen sich beim Herunterfahren schräg. /// public class BlindActuator : MonoBehaviour { [Range(0, 1)] public float target; // 0 = oben, 1 = unten public float speed = 0.12f; // ~8 s für eine komplette Fahrt public Transform[] slats; public Transform bottomRail; public float top, bottom, stackBase; public float stackGap = 0.008f, maxSlatAngle = 65f; public float Current { get; private set; } public bool IsMoving => !Mathf.Approximately(Current, target); float SlatFactor => Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.15f, 1f, Current)); /// Wie stark die Jalousie Licht/Sonne abschirmt (0..1). public float Closure => Current * (0.55f + 0.45f * SlatFactor); void Update() { if (!IsMoving) return; Current = Mathf.MoveTowards(Current, target, speed * Time.deltaTime); Apply(); } public void Apply() { if (slats == null || slats.Length == 0) return; int n = slats.Length; float railY = Mathf.Lerp(stackBase, bottom, Current); float spacing = (top - bottom) / (n + 1); var rot = Quaternion.Euler(0f, 0f, maxSlatAngle * SlatFactor); for (int i = 0; i < n; i++) { float y = Mathf.Max(top - (i + 1) * spacing, railY + (n - i) * stackGap); slats[i].localPosition = new Vector3(0f, y, 0f); slats[i].localRotation = rot; } bottomRail.localPosition = new Vector3(0f, railY, 0f); } } }