|
2 | 2 |
|
3 | 3 | #if CINEMACHINE_URP || CINEMACHINE_PIXEL_PERFECT_2_0_3 |
4 | 4 |
|
| 5 | +#if CINEMACHINE_URP |
| 6 | + using PixelPerfectCamera = UnityEngine.Rendering.Universal.PixelPerfectCamera; |
| 7 | +#else |
| 8 | + using PixelPerfectCamera = UnityEngine.U2D.PixelPerfectCamera; |
| 9 | +#endif |
| 10 | + |
5 | 11 | namespace Unity.Cinemachine |
6 | 12 | { |
7 | 13 | /// <summary> |
@@ -35,28 +41,33 @@ protected override void PostPipelineStageCallback( |
35 | 41 | if (brain == null || !brain.IsLiveChild(vcam)) |
36 | 42 | return; |
37 | 43 |
|
38 | | -#if CINEMACHINE_URP |
39 | | - #if UNITY_2023_2_OR_NEWER |
40 | | - UnityEngine.Rendering.Universal.PixelPerfectCamera pixelPerfectCamera; |
41 | | - #else |
42 | | - UnityEngine.Experimental.Rendering.Universal.PixelPerfectCamera pixelPerfectCamera; |
43 | | - #endif |
44 | | -#elif CINEMACHINE_PIXEL_PERFECT_2_0_3 |
45 | | - UnityEngine.U2D.PixelPerfectCamera pixelPerfectCamera; |
46 | | -#endif |
47 | | - brain.TryGetComponent(out pixelPerfectCamera); |
48 | | - if (pixelPerfectCamera == null || !pixelPerfectCamera.isActiveAndEnabled) |
| 44 | + var pixelPerfectCamera = GetPixelPerfectCamera(vcam, true); |
| 45 | + if (pixelPerfectCamera == null) |
49 | 46 | return; |
50 | | - |
51 | 47 | #if UNITY_EDITOR |
52 | 48 | if (!UnityEditor.EditorApplication.isPlaying && !pixelPerfectCamera.runInEditMode) |
53 | 49 | return; |
54 | 50 | #endif |
55 | | - |
56 | 51 | var lens = state.Lens; |
57 | 52 | lens.OrthographicSize = pixelPerfectCamera.CorrectCinemachineOrthoSize(lens.OrthographicSize); |
58 | 53 | state.Lens = lens; |
59 | 54 | } |
| 55 | + |
| 56 | + PixelPerfectCamera GetPixelPerfectCamera(CinemachineVirtualCameraBase vcam, bool liveOnly) |
| 57 | + { |
| 58 | + var brain = CinemachineCore.FindPotentialTargetBrain(vcam); |
| 59 | + if (brain == null || (liveOnly && !brain.IsLiveChild(vcam))) |
| 60 | + return null; |
| 61 | + var camera = brain.OutputCamera; |
| 62 | + if (camera == null || !camera.TryGetComponent(out PixelPerfectCamera pixelPerfectCamera) |
| 63 | + || !pixelPerfectCamera.isActiveAndEnabled) |
| 64 | + return null; |
| 65 | + return pixelPerfectCamera; |
| 66 | + } |
| 67 | + |
| 68 | + // Used by inspector |
| 69 | + internal bool HasValidPixelPerfectCamera() |
| 70 | + => TryGetComponent<CinemachineVirtualCameraBase>(out var vcam) && GetPixelPerfectCamera(vcam, false) != null; |
60 | 71 | } |
61 | 72 | } |
62 | 73 | #else |
|
0 commit comments