Version: 2017.1

描述

OnPreRender 在摄像机开始渲染场景前调用。

仅当该脚本附加到摄像机并且启用时,才调用该函数。

Note that if you change camera's viewing parameters (e.g. fieldOfView) here, they will only take effect the next frame. Do that in OnPreCull instead. OnPreRender can be a co-routine, simply use the yield statement in the function.

另请注意,当调用 OnPreRender 时,摄像机的渲染目标尚未设置,深度纹理 也尚未渲染。如果您想稍后(例如设置好渲染目标后)执行某些操作, 请尝试使用 CommandBuffer

另请参阅:OnPostRender

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { private bool revertFogState = false; void OnPreRender() { revertFogState = RenderSettings.fog; RenderSettings.fog = enabled; } void OnPostRender() { RenderSettings.fog = revertFogState; } }