Version: 2022.2
public static void DrawMesh (Mesh mesh, Vector3 position, Quaternion rotation, Material material, int layer, Camera camera= null, int submeshIndex= 0, MaterialPropertyBlock properties= null, bool castShadows= true, bool receiveShadows= true, bool useLightProbes= true);
public static void DrawMesh (Mesh mesh, Vector3 position, Quaternion rotation, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows= true, Transform probeAnchor= null, bool useLightProbes= true);
public static void DrawMesh (Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera= null, int submeshIndex= 0, MaterialPropertyBlock properties= null, bool castShadows= true, bool receiveShadows= true, bool useLightProbes= true);
public static void DrawMesh (Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows= true, Transform probeAnchor= null, bool useLightProbes= true);
public static void DrawMesh (Mesh mesh, Matrix4x4 matrix, Material material, int layer, Camera camera, int submeshIndex, MaterialPropertyBlock properties, Rendering.ShadowCastingMode castShadows, bool receiveShadows, Transform probeAnchor, Rendering.LightProbeUsage lightProbeUsage, LightProbeProxyVolume lightProbeProxyVolume= null);

参数

mesh 要绘制的 Mesh
position 网格的位置。
rotation 网格的旋转。
matrix 网格的变换矩阵(组合了位置、旋转和其他变换)。
material 要使用的 Material
layer Layer the mesh is drawn on.
camera If null (default), the mesh will be drawn in all cameras. Otherwise it will be rendered in the given Camera only.
submeshIndex 要绘制网格的哪个子集。这只适用于由若干种材质构成的网格。
properties 在绘制此网格之前应用于材质的其他材质属性。请参阅 MaterialPropertyBlock
castShadows 确定网格是否可以投射阴影。
receiveShadows 确定网格是否可以接受阴影。
useLightProbes 网格是否应使用光照探针?
probeAnchor 如果使用,网格将使用该变换组件的位置对光照探针进行采样,并找到匹配的反射探针。
lightProbeUsage 网格的 LightProbeUsage

描述

绘制一个网格。

This function is now obsolete. Use Graphics.RenderMesh instead.

DrawMesh draws a mesh for one frame. The mesh will be affected by the lights, can cast and receive shadows and be affected by Projectors - just like it was part of some game object. It can be drawn for all cameras or just for some specific camera.

如果您需要绘制大量网格但又不希望出现创建和管理游戏对象的开销, 则可以使用 DrawMesh。注意,DrawMesh 不立即绘制网格;它只“提交”网格以进行渲染。网格 将作为正常渲染过程的一部分进行渲染。若要立即绘制网格,请使用 Graphics.DrawMeshNow

Because DrawMesh does not draw mesh immediately, modifying material properties between calls to this function won't make the meshes pick them up. If you want to draw series of meshes with the same material, but slightly different properties (e.g. change color of each mesh), use MaterialPropertyBlock parameter.

注意,在网格排队等待渲染时,该调用将创建一些内部资源。该分配立即执行,并将保留到帧结束(如果对象排队等待所有摄像机),或直到指定摄像机渲染自身。

See Also: Graphics.RenderMesh, MaterialPropertyBlock.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Mesh mesh; public Material material; public void Update() { // will make the mesh appear in the Scene at origin position Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, material, 0); } }