Version: 2022.3
言語: 日本語
public static Camera.CameraCallback onPreRender ;

説明

Delegate that you can use to execute custom code before a Camera renders the scene.

In the Built-in Render Pipeline, Unity calls this onPreRender before any Camera begins rendering. To execute custom code at this point, create callbacks that match the signature of CameraCallback, and add them to this delegate.

For similar functionality that applies only to a single Camera and requires your script to be on the same GameObject, see MonoBehaviour.OnPreRender. For similar functionality in the Scriptable Render Pipeline, see RenderPipelineManager.

Unity calls onPreRender after the Camera performs its culling operation. This means that if you make a change that affects what the Camera sees, the change will take effect from the next frame. To make a change to what the Camera sees in the current frame, use Camera.onPreCull.

When Unity calls onPreRender, the Camera's render target and depth textures are not yet set up. If you need to access these, you can execute code later in the render loop using a CommandBuffer.

using UnityEngine;

public class CameraCallbackExample : MonoBehaviour { // Add your callback to the delegate's invocation list void Start() { Camera.onPreRender += OnPreRenderCallback; }

// Unity calls the methods in this delegate's invocation list before rendering any camera void OnPreRenderCallback(Camera cam) { Debug.Log("Camera callback: Camera name is " + cam.name);

// Unity calls this for every active Camera. // If you're only interested in a particular Camera, // check whether the Camera is the one you're interested in if (cam == Camera.main) { // Put your custom code here } }

// Remove your callback from the delegate's invocation list void OnDestroy() { Camera.onPreRender -= OnPreRenderCallback; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961