public static void CombineToMesh(GameObject _go)
{
SkinnedMeshRenderer[] _smr = _go.GetComponentsInChildren<SkinnedMeshRenderer>();
List<CombineInstance> lcom = new List<CombineInstance>();
List<Material> lmat = new List<Material>();
List<Transform> ltra = new List<Transform>();
for (int i = 0; i < _smr.Length; i++)
{
lmat.AddRange(_smr.materials);
ltra.AddRange(_smr.bones);
for (int sub = 0; sub < _smr.sharedMesh.subMeshCount; sub++ )
{
CombineInstance ci = new CombineInstance();
ci.mesh = _smr.sharedMesh;
ci.subMeshIndex = sub;
lcom.Add(ci);
}
Destroy(_smr.gameObject);
}
SkinnedMeshRenderer _r = _go.GetComponent<SkinnedMeshRenderer>();
if (_r == null)
_r = _go.AddComponent<SkinnedMeshRenderer>();
_r.sharedMesh = new Mesh();
_r.bones = ltra.ToArray();
_r.materials = new Material[] { lmat[0] };
_r.rootBone = _go.transform;