iso2/scene/HouseDoor.cs
public class HouseDoor : Component {
[Property] Rotation ClosedRot {get; set;}
[Property] Rotation OpenRot {get; set;}
[Property] Action StartAnimating {get; set;}
[Property] Action OnOpen {get; set;}
[Property] Action OnClose {get; set;}
private TimeUntil Animation {get; set;}
[Property, Change(nameof(Switch))] public bool Open {get; set;}
[Property, ReadOnly] public bool Animating {get; set;}
public void Switch() {
Animation = 2.5f;
StartAnimating?.Invoke();
if (Open)
Sound.Play("sounds/door/door_wood_old_open.sound");
else
Sound.Play("sounds/door/door_wood_old_close.sound");
}
protected override void OnUpdate() {
if (Animation && Animating) {
if (Open)
WorldRotation = OpenRot;
else
WorldRotation = ClosedRot;
if (Open)
OnOpen?.Invoke();
else
OnOpen?.Invoke();
Animating = false;
return;
}
if (Animation)
return;
Animating = true;
if (Open)
WorldRotation = ClosedRot.SlerpTo(OpenRot, Animation.Fraction);
else
WorldRotation = OpenRot.SlerpTo(ClosedRot, Animation.Fraction);
base.OnUpdate();
}
}