iso2/scene/BunkerHatchInside.cs
using Sandbox.Utility;
public class BunkerHatchInside : Component, Component.ExecuteInEditor {
[Property] public GameObject Hinge {get; set;}
[Property] public Light BunkerLight {get; set;}
[Property] public Color BunkerLightColor {get; set;}
[Property] public SkyBox2D SkyBox {get; set;}
[Property] public Light SkyLight {get; set;}
[Property] public Color SkyLightColor {get; set;}
[Property] public Light BounceLight {get; set;}
[Property] public Color BounceLightColor {get; set;}
[Property] public PacViewNode ViewNode {get; set;}
[Property, Change(nameof(UpdatePlayerDelayAction))] public bool Open {get; set;}
[Property, ReadOnly, Range(0,1)] public float OpenFrac {get {return OpenCurrent;} set {OpenCurrent = value;}}
public void UpdatePlayerDelayAction() {
if (Open)
BasePlayer.Local.PacCamera.DelayMoveAction = () => {Open = false;};
else
BasePlayer.Local.PacCamera.DelayMoveAction = null;
if (Open)
Sound.Play("sounds/door/bunker_open.sound");
}
private float OpenCurrent;
private float OpenVelocity;
private TimeUntil EndDelay;
protected override void OnUpdate() {
OpenCurrent = MathX.SmoothDamp(OpenCurrent, Open ? 1f : 0f, ref OpenVelocity, Open ? 2f : 1f, Time.Delta);
if (OpenCurrent.AlmostEqual(Open ? 1f : 0f, Open ? 0.0001f : 0.03f)) {
if (!OpenCurrent.AlmostEqual(MathF.Round(OpenCurrent), 0.00001f)) {
BasePlayer.Local.PacCamera.InvalidateView();
if (!Open)
Sound.Play("sounds/door/bunker_close.sound");
}
OpenCurrent = OpenCurrent.SnapToGrid(1);
OpenVelocity = 0f;
} else
EndDelay = 0.3f;
ViewNode.FullScreenFMV = !EndDelay;
SkyBox.Enabled = OpenCurrent > 0f;
var openeased = Easing.QuadraticIn(OpenCurrent);
if (!Open)
openeased = Easing.QuadraticOut(OpenCurrent);
BunkerLight.LightColor = BunkerLightColor.Darken(openeased * 0.7f);
SkyLight.LightColor = SkyLightColor * (openeased * 15f).Clamp(0,1);
Hinge.LocalRotation = Rotation.FromRoll(openeased * 60f);
BounceLight.LightColor = BounceLightColor * (openeased * 5f - 0.2f).Clamp(0,1);
base.OnUpdate();
}
}