45 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Cinemachine;
 | |
| using Level;
 | |
| using UnityEngine;
 | |
| using UnityEngine.U2D;
 | |
| 
 | |
| 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;
 | |
| 
 | |
|         private CinemachineVirtualCamera _cinemachineVirtualCamera;
 | |
|         private PixelPerfectCamera pixelPerfectCamera = null;
 | |
| 
 | |
| 
 | |
|         private void Awake()
 | |
|         {
 | |
|             _cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
 | |
|             pixelPerfectCamera = GameObject.FindObjectOfType<PixelPerfectCamera>();
 | |
|         }
 | |
| 
 | |
|         private void Update()
 | |
|         {
 | |
|             if (LevelManager.Instance.CurrentLevel?.FixedCameraPoint == null)
 | |
|             {
 | |
|                 if (_cinemachineVirtualCamera.Follow == null)
 | |
|                 {
 | |
|                     _cinemachineVirtualCamera.Follow = LevelManager.Instance.Player.transform;
 | |
|                     pixelPerfectCamera.refResolutionX = FollowResolutionX;
 | |
|                     pixelPerfectCamera.refResolutionY = FollowResolutionY;
 | |
|                 }
 | |
|             }
 | |
|             else if (_cinemachineVirtualCamera.Follow != LevelManager.Instance.CurrentLevel.FixedCameraPoint)
 | |
|             {
 | |
|                 _cinemachineVirtualCamera.Follow = LevelManager.Instance.CurrentLevel.FixedCameraPoint;
 | |
|                 pixelPerfectCamera.refResolutionX = FixedResolutionX;
 | |
|                 pixelPerfectCamera.refResolutionY = FixedResolutionY;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |