你好,我正在使用这个家伙的脚本https://www.youtube.com/watch?v=wYAlky1aZn4来组合网格,因为游戏是“滞后”的,或者当它运行不顺利的时候叫它什么。我有两个不同网格的34*124个立方体,如果我把脚本放在一个有34*20个孩子的对象上(就是我之前提到的那个立方体),所有的效果都很完美,但如果我把它放在有32*124个孩子的对象上,它会把它们变成看起来有34*20个立方体的东西。
基本上,如果我把脚本放在有更多孩子的东西上,它会把它变得更小。
以下是视频中的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CombineMeshes : MonoBehaviour {
public void Combine(){
Quaternion oldRot = transform.rotation;
Vector3 oldPos = transform.position;
transform.rotation = Quaternion.identity;
transform.position = Vector3.zero;
MeshFilter[] filters = GetComponentsInChildren<MeshFilter> ();
Mesh finalMesh = new Mesh ();
CombineInstance[] combiners = new CombineInstance[filters.Length];
for (int a = 0; a < filters.Length; a++) {
if (filters [a].transform == transform) {
continue;
}
combiners [a].subMeshIndex = 0;
combiners [a].mesh = filters [a].sharedMesh;
combiners [a].transform = filters [a].transform.localToWorldMatrix;
}
finalMesh.CombineMeshes (combiners);
GetComponent<MeshFilter> ().sharedMesh = finalMesh;
transform.rotation = oldRot;
transform.position = oldPos;
for (int a= 0; a < transform.childCount; a++) {
transform.GetChild (a).gameObject.SetActive (false);
}
}
}发布于 2018-12-18 23:40:50
这就是你遇到的顶点限制问题。设置后,1个网格只能有34*20*96 = 65.280顶点。在此之后,您需要另一个网格。124*34*96制造了404,736,并且已经超过了限制。因此,需要将网格的格式更改为UInt32。如果延迟仍然存在,我可以尝试进一步提供帮助。
https://stackoverflow.com/questions/53835715
复制相似问题