public void SetPart(PartType type) { destroyOldData(); currentType = type; Part part = Part.MakePart(type); meshFilter.mesh.Clear(); meshFilter.mesh.vertices = part.GetVertices(partDirection, partRotation, 0, 0, 0); meshFilter.mesh.uv = part.GetUVs(partDirection, partRotation); meshFilter.mesh.triangles = part.GetTriangles(partDirection, partRotation, 0); meshFilter.mesh.RecalculateNormals(); //col.sharedMesh = null; //col.sharedMesh = meshFilter.mesh; // Create box colliders boundingBox = new BoundingBox(); connectionPoints = part.GetConnectionpoints(partDirection, partRotation); //connectionointInfos //createdBoxColliders = new BoxCollider[connectionointInfos.Length]; //connectionPoints = new Connectionpoint[connectionointInfos.Length]; for (int i = 0; i < connectionPoints.Length; i++) { for (int j = 0; j < connectionPoints[i].BoxCollidersAmount; j++) { BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>(); boxCollider.tag = "Connector"; boxCollider.isTrigger = true; connectionPoints[i].SetBoxCollider(boxCollider, j); } boundingBox.AddElement(connectionPoints[i].ConnectorPosition); //createdBoxColliders[i] = gameObject.AddComponent<BoxCollider>(); //createdBoxColliders[i].tag = "Connector"; //createdBoxColliders[i].isTrigger = true; //createdBoxColliders[i].center = connectionointInfos[i].relativePosition; //createdBoxColliders[i].size = connectionointInfos[i].size; // //connectionPoints[i] = Connectionpoint.MakeConnectionpoint(connectionointInfos[i].connectorType, connectionointInfos[i].direction, connectionointInfos[i].relativePosition); //connectionPoints[i].Boxcollider = createdBoxColliders[i]; } }
private void addBoxCollider(Vector3[] verts) { BoxCollider newBC = gameObject.AddComponent <BoxCollider>(); boundingBox = new BoundingBox(); //Connectionpoint[] connectionPoints = part.GetConnectionpoints(partDirection, partRotation); for (int i = 0; i < verts.Length; i++) { boundingBox.AddElement(new Vector3Int(verts[i]).Add(partPosition)); } Vector3 middle = new Vector3((boundingBox.MaxValues.x - boundingBox.MinValues.x) * 0.5f + boundingBox.MinValues.x , (boundingBox.MaxValues.y - boundingBox.MinValues.y) * 0.5f + boundingBox.MinValues.y , (boundingBox.MaxValues.z - boundingBox.MinValues.z) * 0.5f + boundingBox.MinValues.z); //Vector3 middle = partPosition.ToVector3(); newBC.center = middle; newBC.size = new Vector3(boundingBox.MaxValues.x + 1f - boundingBox.MinValues.x , boundingBox.MaxValues.y + 1f - boundingBox.MinValues.y , boundingBox.MaxValues.z + 1f - boundingBox.MinValues.z); }
public void SetPart(PartType type) { currentType = type; Part part = Part.MakePart(type); meshFilter.mesh.Clear(); meshFilter.mesh.vertices = part.GetVertices(partDirection, partRotation, 0, 0, 0); meshFilter.mesh.uv = part.GetUVs(partDirection, partRotation); meshFilter.mesh.triangles = part.GetTriangles(partDirection, partRotation, 0); meshFilter.mesh.RecalculateNormals(); BoxCollider attachedBC = GetComponentInParent <BoxCollider>(); if (attachedBC != null) { boundingBox = new BoundingBox(); //Connectionpoint[] connectionPoints = part.GetConnectionpoints(partDirection, partRotation); for (int i = 0; i < meshFilter.mesh.vertices.Length; i++) { boundingBox.AddElement(new Vector3Int(meshFilter.mesh.vertices[i]).Add(partPosition)); } Vector3 middle = new Vector3((boundingBox.MaxValues.x - boundingBox.MinValues.x) * 0.5f + boundingBox.MinValues.x , (boundingBox.MaxValues.y - boundingBox.MinValues.y) * 0.5f + boundingBox.MinValues.y , (boundingBox.MaxValues.z - boundingBox.MinValues.z) * 0.5f + boundingBox.MinValues.z); //Vector3 middle = partPosition.ToVector3(); attachedBC.center = middle; attachedBC.size = new Vector3(boundingBox.MaxValues.x + 1f - boundingBox.MinValues.x , boundingBox.MaxValues.y + 1f - boundingBox.MinValues.y , boundingBox.MaxValues.z + 1f - boundingBox.MinValues.z); } }