任意摄像机开始渲染前触发的事件。
注意,当调用 onPreRender 时,摄像机的渲染目标尚未设置,深度纹理 也尚未渲染。如果您想稍后(在设置好渲染目标后)执行某些操作, 请尝试使用 CommandBuffer。
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
// callback to be called before any camera starts rendering
public void MyPreRender(Camera cam)
{
Debug.Log("PreRender " + gameObject.name + " from camera " + cam.gameObject.name);
}
public void OnEnable()
{
// register the callback when enabling object
Camera.onPreRender += MyPreRender;
}
public void OnDisable()
{
// remove the callback when disabling object
Camera.onPreRender -= MyPreRender;
}
}