{}!Google Tag Manager end}} beginCameraRendering 이벤트 사용 | Universal RP | 14.0.9
docs.unity3d.com
    목차 표시/숨기기

    beginCameraRendering 이벤트 사용

    이 페이지의 예제는 beginCameraRendering 이벤트를 사용하여 커스텀 메서드를 실행하는 방법을 보여줍니다.

    beginCameraRendering 이벤트 개요

    Unity는 프레임마다 각 활성 카메라를 렌더링하기 전에 beginCameraRendering 이벤트를 발생시킵니다. 카메라가 비활성(예: Camera 컴포넌트 체크박스가 카메라 게임 오브젝트에서 선택 해제) 상태이면 Unity는 이 카메라에 대한 beginCameraRendering 이벤트를 발생시키지 않습니다.

    이 이벤트에 대한 메서드를 구독하면 Unity가 카메라를 렌더링하기 전에 커스텀 로직을 실행할 수 있습니다. 커스텀 로직의 예로는 추가 카메라를 렌더 텍스처로 렌더링하고 해당 텍스처를 평면 반사 또는 감시 카메라 뷰 등의 효과에 사용하는 것을 들 수 있습니다.

    RenderPipelineManager 클래스의 다른 이벤트는 URP 커스터마이즈를 위한 더 많은 방식을 제공합니다. 또한 이 문서에 설명된 원칙을 해당 이벤트에 사용할 수도 있습니다.

    beginCameraRendering 이벤트 예제

    이 예제는 beginCameraRendering 이벤트에 대한 메서드를 구독하는 방법을 설명합니다. 이 예제의 단계를 따라하려면 유니버설 프로젝트 템플릿 을 사용하여 새로운 Unity 프로젝트를 생성하십시오.

    1. 씬에서 큐브를 생성하고, 'Example Cube'라고 이름을 지정합니다.
    2. 프로젝트에서 C# 스크립트를 만들고, URPCallbackExample이라고 지칭합니다.
    3. 다음 코드를 복사하여 스크립트에 붙여 넣습니다.

      using UnityEngine;
      using UnityEngine.Rendering;
      
      public class URPCallbackExample : MonoBehaviour
      {
          // Unity calls this method automatically when it enables this component
          private void OnEnable()
          {
              // Add WriteLogMessage as a delegate of the RenderPipelineManager.beginCameraRendering event
              RenderPipelineManager.beginCameraRendering += WriteLogMessage;
          }
      
          // Unity calls this method automatically when it disables this component
          private void OnDisable()
          {
              // Remove WriteLogMessage as a delegate of the  RenderPipelineManager.beginCameraRendering event
              RenderPipelineManager.beginCameraRendering -= WriteLogMessage;
          }
      
          // When this method is a delegate of RenderPipeline.beginCameraRendering event, Unity calls this method every time it raises the beginCameraRendering event
          void WriteLogMessage(ScriptableRenderContext context, Camera camera)
          {
              // Write text to the console
              Debug.Log($"Beginning rendering the camera: {camera.name}");
          }
      }
      

      참고: 이벤트를 구독하는 경우 핸들러 메서드(이 예제에서는 WriteLogMessage)가 이벤트 델리게이트에 정의된 파라미터를 허용해야 합니다. 이 예제에서 이벤트 델리게이트는 RenderPipeline.BeginCameraRendering이며 <ScriptableRenderContext, Camera> 파라미터를 요구합니다.

    4. URPCallbackExample 스크립트를 Example Cube에 연결합니다.

    5. Play 를 선택합니다. Unity가 beginCameraRendering 이벤트를 발생시킬 때마다 콘솔 창에 스크립트의 메시지를 출력합니다.

      Unity가 콘솔에 로그 메시지를 출력합니다.

    6. OnDisable() 메서드를 호출하려면 플레이 모드에서 Example Cube를 선택하고, 스크립트 컴포넌트 제목 옆의 체크박스를 선택 해제합니다. Unity가 RenderPipelineManager.beginCameraRendering 이벤트에서 WriteLogMessage의 구독을 해제하고 콘솔 창에 메시지 출력을 중지합니다.

      스크립트 컴포넌트를 비활성화합니다. 스크립트 컴포넌트 제목 옆의 체크박스를 선택 해제합니다.

    맨 위로
    Copyright © 2023 Unity Technologies —
    • Your Privacy Choices (Cookie Settings)