using UnityEngine;

[ExecuteInEditMode]
public class PixelPerfectCamera : MonoBehaviour
{
    // TODO: set this constant to the Pixels Per Unit value set for all sprites
    public static readonly int PixelsPerUnit = 32;
    public int targetResolutionHeight = 1080;

    private Camera camera;

    private void Awake()
    {
        camera = GetComponent<Camera>();

        if (camera == null)
            Debug.LogError("PixelPerfectCamera component must be attached to a Camera");

        camera.orthographicSize = (1f * targetResolutionHeight) / 2 / PixelsPerUnit;
    }

#if UNITY_EDITOR
    private void Update()
    {
        camera.orthographicSize = (1f * targetResolutionHeight) / 2 / PixelsPerUnit;
    }
#endif
}
