public GameObject[] generateColliders() { GameObject[] colliders = new GameObject[faces]; float anglePerFace = 360f / (float)faces; float start = 0; float end = start + anglePerFace; float thickness = topRadius - topInnerRadius; Mesh mesh; MeshFilter mf; MeshCollider mc; ROTMeshBuilder builder = new ROTMeshBuilder(); GameObject collider; for (int i = 0; i < faces; i++) { collider = new GameObject("ProceduralCylinderCollider-" + i); colliders[i] = collider; start = (float)i * anglePerFace; end = start + anglePerFace; builder.generatePanelCollider(offset, start, end, 0, height, bottomRadius, topRadius, thickness); mesh = builder.buildMesh(); mf = collider.AddComponent <MeshFilter>(); mf.mesh = mesh; mc = collider.AddComponent <MeshCollider>(); mc.sharedMesh = mesh; mc.convex = true; builder.clear(); } return(colliders); }
public GameObject[] generateColliders(Vector3 center, int facesPerCollider) { float totalAngle = endAngle - startAngle; float anglePerFace = 360f / (float)faces; int localFaces = (int)Math.Round(totalAngle / anglePerFace); localFaces /= facesPerCollider; GameObject[] colliders = new GameObject[localFaces * (innerArcs.Count - 1)]; float localStart, localEnd, startY, height, topRadius, bottomRadius, thickness; Mesh colliderMesh; MeshFilter mf; //MeshRenderer mr; MeshCollider mc; thickness = outerArcs[0].radius - innerArcs[0].radius; ROTMeshBuilder builder = new ROTMeshBuilder(); int colliderIndex = 0; for (int i = 0; i < localFaces; i++) { localStart = startAngle + (float)i * anglePerFace; localEnd = localStart + (anglePerFace * facesPerCollider); for (int k = 0; k < innerArcs.Count - 1; k++, colliderIndex++) { startY = innerArcs[k].height; height = innerArcs[k + 1].height - startY; bottomRadius = outerArcs[k].radius; topRadius = outerArcs[k + 1].radius; builder.generatePanelCollider(center, localStart, localEnd, startY, height, bottomRadius, topRadius, thickness); colliderMesh = builder.buildMesh(); builder.clear(); colliders[colliderIndex] = new GameObject("PanelCollider" + i + "-" + k); mf = colliders[colliderIndex].AddComponent <MeshFilter>(); //mr = colliders[i].AddComponent<MeshRenderer>(); mc = colliders[colliderIndex].AddComponent <MeshCollider>(); mf.mesh = colliderMesh; //mr.enabled = true; mc.sharedMesh = colliderMesh; mc.enabled = mc.convex = true; } } return(colliders); }