Table of Contents

Example - View Presets

You want named camera viewpoints the player can jump between, fx. main building on F1, the front gate on F2, the barracks on F3.

A preset is just an OrbitalCameraState captured ahead of time. Restore one with SetState and you're there instantly. Capture during play with GetState so the player can define their own.

using UnityEngine;
using Goehler.OrbitalCam;

public class CameraPresets : MonoBehaviour {

    [SerializeField] private OrbitalCameraSystem _camera;
    [SerializeField] private OrbitalCameraState[] _slots = new OrbitalCameraState[3];

    private void Update() {
        if (Input.GetKeyDown(KeyCode.F1)) Recall(0);
        if (Input.GetKeyDown(KeyCode.F2)) Recall(1);
        if (Input.GetKeyDown(KeyCode.F3)) Recall(2);

        if (Input.GetKeyDown(KeyCode.Alpha1)) Capture(0);
        if (Input.GetKeyDown(KeyCode.Alpha2)) Capture(1);
        if (Input.GetKeyDown(KeyCode.Alpha3)) Capture(2);
    }

    private void Capture(int slot) => _slots[slot] = _camera.GetState();
    private void Recall(int slot) => _camera.SetState(_slots[slot]);
}

OrbitalCameraState is [Serializable], so the array shows up in the Inspector and you can set the slot values in advance without entering Play mode. Set position, rotation, tilt, and zoom on each element to define your default views.

Note

SetState is the instant variant. If you want the camera to glide between presets instead of snapping, swap the recall for the three animated calls: MoveCameraTo, RotateAndTiltCameraTo, and ZoomCameraTo. Pull the values out of the stored state; they share animationTime, so all three end together.

This pattern is wired up in the Scripting Demo scene. Hit Play, move the camera around, press 1/2/3 to capture, then F1/F2/F3 to recall.

See Save and Load for more on the underlying capture/restore mechanic.