using System;
using UnityEngine;
using Framework.Services;
namespace Framework.Cameras {
/// Provides access to the current camera
public class CameraManager : Service, ICameraManager {
/// Triggered when the active camera changes
public event Action CameraChanged;
/// Camera that is currently active
///
/// By informing the camera manager about which camera is being used, other services
/// such as a background music or ambient sound service can keep their audio sources
/// attached to the active camera.
///
public Camera ActiveCamera {
get {
if(!ReferenceEquals(Camera.main, this.activeCamera)) {
this.activeCamera = Camera.main;
OnCameraChanged();
}
return this.activeCamera;
}
set {
if(!ReferenceEquals(value, this.activeCamera)) {
this.activeCamera = value;
OnCameraChanged();
}
}
}
/// Fires the CameraChanged event
protected virtual void OnCameraChanged() {
Debug.Log("New active camera is " + this.activeCamera.name);
const bool disablePrevious = true;
CameraHelper.ActivateCamera(this.activeCamera, disablePrevious);
if(CameraChanged != null) {
CameraChanged(this.activeCamera);
}
}
/// Camera that is currently active
private Camera activeCamera;
}
} // namespace Framework.Cameras