onPreRender
Delegate that you can use to execute custom code before a Camera renders the scene.
読み終わるまでの所要時間 2 分最終更新 5日前
Definition
- Type: Field
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public static Camera.CameraCallback onPreRender
Remarks
onPreRenderonPreRenderFor similar functionality that applies only to a single Camera and requires your script to be on the same GameObject, see MonoBehaviour.OnPreRender().
If you're using a Scriptable Render Pipeline, for example the Universal Render Pipeline, use RenderPipelineManager instead.
Unity calls 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.
onPreRenderWhen Unity calls , 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.
onPreRenderusing 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; }}