没有加批处理绘制次数很高 FPS 81
加批处理绘制次数降低 FPS 94
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StaticBatchProcessing : MonoBehaviour
{
public Texture2D texture;//纹理
public int wnum;
public int hnum;
int w = 128;
int h = 128;
// Start is called before the first frame update
void Start()
{
//顶点是有个数限制的最多65000个
//纹理尽力取2的次方
wnum =4;
hnum = 4;
//补缝用
int w2 = w + 2;
int h2 = h + 2;
for (int i = 0; i < wnum; i++)
{
for (int j = 0; j < hnum; j++)
{
for (int x = 0; x < w2; x++)
{
for (int z = 0; z < h2; z++)
{
//柏林噪声算法,传入两个坐标返回一个0-1的值(传入两个相同的值,返回结果一定相同)
float y = Mathf.PerlinNoise((i * w + x) * 0.02f, (j * h + z) * 0.02f);
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.parent = this.transform;
cube.transform.localPosition = new Vector3(w*i+x,y*5,h*j+z);
}
}
}
}
//gameObject得是静态的
StaticBatchingUtility.Combine(gameObject);//此代码就是静态批处理代码
}
// Update is called once per frame
void Update()
{
}
}