描述

在摄像机剔除场景前,将调用 OnPreCull。

剔除操作决定了摄像机能够看到哪些对象。 OnPreCull 在该过程即将开始前调用。

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

如果要更改摄像机的视图参数(例如,Camera.fieldOfView 或仅变换), 这就是进行此操作的位置。调用 OnPreCull 之后,场景对象的可见性将根据 摄像机参数确定。

// Attach this to a camera.
// Inverts the view of the camera so everything rendered by it, is flipped

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { Camera cam;

void Start() { cam = GetComponent<Camera>(); }

void OnPreCull() { cam.ResetWorldToCameraMatrix(); cam.ResetProjectionMatrix(); cam.projectionMatrix = cam.projectionMatrix * Matrix4x4.Scale(new Vector3(1, -1, 1)); }

void OnPreRender() { GL.invertCulling = true; }

void OnPostRender() { GL.invertCulling = false; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961