unity Graphics的一些方法介绍

https://docs.unity3d.com/ScriptReference/Graphics.html

第一个方法:Graphics.DrawMesh
Description
draw a mesh.
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.

Use DrawMesh in situations where you want to draw large amount of meshes, but don’t want the overhead of creating and managing game objects. Note that DrawMesh does not draw the mesh immediately; it merely “submits” it for rendering. The mesh will be rendered as part of normal rendering process. If you want to draw a mesh immediately, use Graphics.DrawMeshNow.

because DrawMesh does not draw mesh immediately, modifying material properties between calls to this function will not make the meshes pick up them. if u want to draw series of meshes with the same material, but slightly different properties (e.g. cange color of each mesh), use MaterialPropertyBlock parameter.

Note that this call will create some internal resources while the mesh is queued up for rendering. The allocation happens immediately and will be kept around until the end of frame (if the object was queued for all cameras) or until the specified camera renders itself.

举例:

using UnityEngine;

public class GraphicsDrawMeshDemo : MonoBehaviour
{
    public Camera camera1;
    public Camera camera2;
    public Mesh mesh;
    public Material material1;
    public Material material2;
    private int scale = 2;
    public void Update()
    {
        Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 0, 0), Vector3.one * scale);
        Graphics.DrawMesh(mesh, m, material1, 0, camera1);
        Graphics.DrawMesh(mesh, m, material2, 0, camera2);
    }
}

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值