using NightclubArcadia.UI; using Unity.Cinemachine; using UnityEngine; namespace NightclubArcadia.Cinematics { /// /// Shifts CinemachinePositionComposer.Composition.ScreenPosition so the /// player is centred in the screen space left of the dialogue panel. /// public sealed class DialogueCameraFraming : MonoBehaviour { [SerializeField] CinemachinePositionComposer composer; [SerializeField] float dialogueScreenX = -0.17f; [SerializeField] bool suppressDeadZoneXInDialogue = true; float defaultDeadZoneX = 0.2f; void Start() { if (composer == null) { composer = FindFirstObjectByType(); } if (composer != null) { defaultDeadZoneX = composer.Composition.DeadZone.Size.x; } if (UIStateController.Instance != null) { UIStateController.Instance.StateChanged += OnStateChanged; } ApplyFraming(); } void OnDestroy() { if (UIStateController.Instance != null) { UIStateController.Instance.StateChanged -= OnStateChanged; } } void OnStateChanged() => ApplyFraming(); void ApplyFraming() { if (composer == null) { return; } var active = UIStateController.Instance != null && UIStateController.Instance.IsDialogueActive; var target = active ? dialogueScreenX : 0f; var composition = composer.Composition; composition.ScreenPosition = new Vector2(target, composition.ScreenPosition.y); if (suppressDeadZoneXInDialogue) { var size = composition.DeadZone.Size; size.x = active ? 0f : defaultDeadZoneX; composition.DeadZone.Size = size; } composer.Composition = composition; } } }