private static void GenerateObjects(GameObject prefab, BoundingBox bbox, int countW, int countH) { Vector3 org = bbox.position; float totalW = bbox.size[0]; float totalH = bbox.size[1]; float stepW = totalW / (float)countW; float stepH = totalH / (float)countH; print("stepW=" + stepW); print("stepH=" + stepH); Vector3 vectW = bbox.vects[0] * stepW; Vector3 vectH = bbox.vects[1] * stepH; Vector3 vectD = bbox.vects[2] * 1; for (int i = 0; i < countH; i++) { for (int j = 0; j < countW; j++) { Vector3 bp = org + (vectW * j) + (vectH * i); Vector3[] ptsi = new Vector3[2]; ptsi[0] = bp; ptsi[1] = ptsi[0] + vectW + vectH + vectD; BoundingBox bboxi = BoundingBox.CreateFromPoints(ptsi, vectW); ShapeObject shpo = ShapeObject.CreateBasic(prefab); shpo.ConformToBBoxTransform(bboxi); } } }
private int GenerateObjects(GameObject prefab, BoundingBox bbox, float stepW, float stepH, int totalObjectCount) { if (prefab == null) { prefab = Resources.Load(prefabPath) as GameObject; } Vector3 org = bbox.position; float totalW = bbox.size[0]; float totalH = bbox.size[1]; int countW = Mathf.RoundToInt(totalW / stepW); int countH = Mathf.RoundToInt(totalH / stepH); if (countW < 1) { countW = 1; } if (countH < 1) { countH = 1; } float astepW = totalW / (float)countW; float astepH = totalH / (float)countH; Vector3 vectW = bbox.vects[0] * astepW; Vector3 vectH = bbox.vects[1] * astepH; Vector3 vectD = bbox.vects[2] * 1; for (int i = 0; i < countH; i++) { for (int j = 0; j < countW; j++) { Vector3 bp = org + (vectW * j) + (vectH * i); Vector3[] ptsi = new Vector3[2]; ptsi[0] = bp; ptsi[1] = ptsi[0] + vectW + vectH + vectD; BoundingBox bboxi = BoundingBox.CreateFromPoints(ptsi, vectW); if (totalObjectCount >= outputs.shapes.Count) { ShapeObject nso = ShapeObject.CreateBasic(prefab, true); nso.parentRule = this; outputs.shapes.Add(nso); } ShapeObject shpo = outputs.shapes[totalObjectCount]; shpo.ConformToBBoxTransform(bboxi); totalObjectCount += 1; } } return(totalObjectCount); }