private static Collider RefershMeshCollider(MeshCollider msh) { if (!msh) { return(msh); } if (msh.sharedMesh) { if (msh.sharedMesh.isReadable) { Mesh mesh = msh.sharedMesh; msh.sharedMesh = null; string name = msh.gameObject.name; Transform parent = msh.gameObject.transform.parent; Vector3 localPosition = msh.gameObject.transform.localPosition; Quaternion localRoation = msh.gameObject.transform.localRotation; Vector3 localScale = msh.gameObject.transform.localScale; int layer = msh.gameObject.layer; GameObject go = msh.gameObject; SceneInfo info = go.GetComponent <SceneInfo>(); if (info) { Debug.LogWarning(go.name + "碰撞体上不能有:" + info.GetType() + "组件"); return(msh); } GameObject.DestroyImmediate(go); go = new GameObject(); go.name = name; go.transform.parent = parent; go.transform.localPosition = localPosition; go.transform.localRotation = localRoation; go.transform.localScale = localScale; go.layer = layer; go.AddComponent <MeshFilter>().sharedMesh = mesh; MeshRenderer re = go.AddComponent <MeshRenderer>(); re.enabled = ShowMeshColliderFlags; re.sharedMaterial = GetLayerMaterial(go.layer); currColliderMeshRender.Add(re); msh = go.AddComponent <MeshCollider>(); msh.sharedMesh = mesh; // Debug.Log("刷新MeshCollider:" + ",triangles:" + msh.sharedMesh.triangles.Length + ",vertexCout:" + msh.sharedMesh.vertexCount); } else { Debug.LogWarning("not readable:" + (msh.transform.parent ? msh.transform.parent.name : msh.gameObject.name)); } } else { Debug.LogWarning("missing Mesh:" + (msh.transform.parent ? msh.transform.parent.name : msh.gameObject.name)); } return(msh); }