Advertisement
dnnkeeper

Unity URP OnWillRenderObject current camera

Jul 7th, 2020
1,873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Rendering;
  5.  
  6. public class DetermineRenderCamera : MonoBehaviour
  7. {
  8.     Camera prevCamera;
  9.  
  10.     Camera currentCamera;
  11.  
  12.     private void Start()
  13.     {
  14.         RenderPipelineManager.beginCameraRendering += RenderPipelineManager_beginCameraRendering;
  15.     }
  16.  
  17.     private void RenderPipelineManager_beginCameraRendering(ScriptableRenderContext context, Camera renderCamera)
  18.     {
  19.         this.currentCamera = renderCamera;
  20.     }
  21.  
  22.     private void OnWillRenderObject()
  23.     {
  24.         if (currentCamera != null)
  25.         {
  26.             if (currentCamera != prevCamera)
  27.             {
  28.                 Debug.Log("new currentCamera = " + currentCamera);
  29.                 prevCamera = currentCamera;
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement