Version: 2022.3

MonoBehaviour.OnRenderObject()

切换到手册

描述

在摄像机渲染场景后,将调用 OnRenderObject。

This can be used to render your own objects using Graphics.RenderMesh or other functions. This function is similar to OnPostRender, except OnRenderObject is called on any object that has a script with the function; no matter if it's attached to a Camera or not. You should only use this function to draw and not to change any high level rendering states.

请注意,此函数可能会影响性能,因为它会对具有使用此回调的脚本的每个 GameObject 运行。

using System.Collections;
using UnityEngine;

public class ExampleClass : MonoBehaviour { public Mesh mainMesh; public Mesh miniMapMesh;

void OnRenderObject() { // Render different meshes for the object depending on whether // the main camera or minimap camera is viewing. if (Camera.current.name == "MiniMapcam") { Graphics.DrawMeshNow(miniMapMesh, transform.position, transform.rotation); } else { Graphics.DrawMeshNow(mainMesh, transform.position, transform.rotation); } } }