BGJ-2022.1/Assets/Scripts/Camera/CameraPlayerFinder.cs

45 lines
1.5 KiB
C#
Raw Permalink Normal View History

2022-02-27 11:03:05 +03:00
using System;
2022-02-25 23:38:09 +03:00
using Cinemachine;
2022-02-27 00:43:46 +03:00
using Level;
2022-02-25 23:38:09 +03:00
using UnityEngine;
2022-02-27 11:03:05 +03:00
using UnityEngine.Events;
2022-02-27 00:43:46 +03:00
using UnityEngine.U2D;
2022-02-25 23:38:09 +03:00
namespace Camera
{
public class CameraPlayerFinder : MonoBehaviour
{
[SerializeField] private int FixedResolutionX = 426;
[SerializeField] private int FixedResolutionY = 240;
[SerializeField] private int FollowResolutionX = 278;
[SerializeField] private int FollowResolutionY = 162;
2022-02-25 23:38:09 +03:00
private CinemachineVirtualCamera _cinemachineVirtualCamera;
2022-02-27 00:43:46 +03:00
private PixelPerfectCamera pixelPerfectCamera = null;
2022-02-25 23:38:09 +03:00
2022-02-25 23:38:09 +03:00
private void Awake()
{
_cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
2022-02-27 00:43:46 +03:00
pixelPerfectCamera = GameObject.FindObjectOfType<PixelPerfectCamera>();
2022-02-27 11:03:05 +03:00
LevelManager.Instance.OnLevelChanged.AddListener(UpdateCamera);
2022-02-25 23:38:09 +03:00
}
2022-02-27 11:03:05 +03:00
private void UpdateCamera()
2022-02-25 23:38:09 +03:00
{
2022-02-27 11:03:05 +03:00
if (LevelManager.Instance.CurrentLevel.FixedCameraPoint == null)
2022-02-27 00:43:46 +03:00
{
2022-02-27 11:03:05 +03:00
_cinemachineVirtualCamera.Follow = LevelManager.Instance.Player.transform;
pixelPerfectCamera.refResolutionX = FollowResolutionX;
pixelPerfectCamera.refResolutionY = FollowResolutionY;
2022-02-27 00:43:46 +03:00
}
2022-02-27 11:03:05 +03:00
else
2022-02-27 00:43:46 +03:00
{
_cinemachineVirtualCamera.Follow = LevelManager.Instance.CurrentLevel.FixedCameraPoint;
pixelPerfectCamera.refResolutionX = FixedResolutionX;
pixelPerfectCamera.refResolutionY = FixedResolutionY;
2022-02-27 00:43:46 +03:00
}
2022-02-25 23:38:09 +03:00
}
}
2022-02-27 00:43:46 +03:00
}