Version: 2021.2

Camera.cullingMatrix

切换到手册
public Matrix4x4 cullingMatrix ;

描述

为摄像机设置一个自定义矩阵,以用于所有剔除查询。

通过调用 ResetCullingMatrix 禁用该设置以前,设置持续有效。

在必须以相同方式剔除多个摄像机以渲染反射等特效的情况下,自定义剔除矩阵非常有用。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { Camera cullingCamera;

void Awake() { cullingCamera = gameObject.AddComponent<Camera>(); SetMainCameraCustomCullingMatrix(new Vector3(10.0f, 10.0f, 10.0f), Vector3.zero); }

void SetMainCameraCustomCullingMatrix(Vector3 cameraPosition, Vector3 lookAtPosition) { transform.position = cameraPosition; transform.LookAt(lookAtPosition); Camera.main.cullingMatrix = cullingCamera.projectionMatrix * cullingCamera.worldToCameraMatrix; }

void ResetMainCameraCullingMatrix() { Camera.main.ResetCullingMatrix(); } }