A menu camera component for the UI/menu scene. It sets a specific background color when enabled and contains commented-out code for simple camera motion; it also exposes a Velocity property.
using Sandbox;
public class MenuCamera : Component
{
public static readonly Color BackgroundColor = new Color( 0.10196f, 0.10196f, 0.10196f, 1f );
// Sprite RGB is shaded in linear space; camera clear colours are sRGB.
public static readonly float BackgroundLinear = MathF.Pow( (BackgroundColor.r + 0.055f) / 1.055f, 2.4f );
public Vector3 Velocity { get; private set; }
protected override void OnEnabled()
{
base.OnEnabled();
// Apply on every menu load, including when the editor's initial scene was
// already open before its saved background colour changed.
var camera = Components.Get<CameraComponent>();
if ( camera.IsValid() )
{
camera.BackgroundColor = BackgroundColor;
}
}
protected override void OnUpdate()
{
base.OnUpdate();
//Velocity += new Vector3( Game.Random.Float( -1f, 1f ), Game.Random.Float( -1f, 1f ), 0f ) * 50f * Time.Delta;
//Velocity *= (1f - 2f * Time.Delta);
//WorldPosition += Velocity * Time.Delta;
//WorldPosition = Vector3.Lerp( WorldPosition, new Vector3( 0f, 0f, 250f ), 1f * Time.Delta );
//WorldPosition = new Vector3( 5f * Utils.Map(Mouse.Position.x, 0f, Screen.Width, -1f, 1f), Utils.Map( Mouse.Position.y, 0f, Screen.Height, 2f, -4f), 250f);
}
}