Code/GolfPreviewCamera.cs
using Sandbox;
using System.Linq;
/// <summary>
/// The camera a course scene plays through in the mapper's own project, so Play shows the course
/// instead of a black screen. Sits on the course template's "Preview Camera" object with a Camera
/// Component and the on-screen note (<see cref="GolfPreviewNote"/>) that gameplay is tested from
/// the game's course screen. The game switches the whole object off when it loads the course, and
/// the kit's Set up course leaves it alone; every other camera a course brings along is removed.
/// </summary>
[Title( "Golf Preview Camera" ), Icon( "preview" ), Category( "Golf" )]
public sealed class GolfPreviewCamera : Component
{
/// <summary>With a Golf Menu Camera in the scene, the preview looks from there: the same view the game's menus show.</summary>
[Property, Title( "Follow Menu Camera" )]
public bool FollowMenuCamera { get; set; } = true;
protected override void OnStart()
{
if ( !FollowMenuCamera ) return;
var menu = Scene.GetAllComponents<GolfMenuCamera>().FirstOrDefault();
if ( !menu.IsValid() ) return;
WorldTransform = menu.ViewAt( 0f );
var camera = GetComponent<CameraComponent>( true );
if ( camera.IsValid() ) camera.FieldOfView = menu.FieldOfView;
}
}