|
3 | 3 | using UnityEngine;
|
4 | 4 | using Newtonsoft.Json;
|
5 | 5 | using System;
|
| 6 | +using Parabox.CSG; |
6 | 7 |
|
7 | 8 | [System.Serializable]
|
8 | 9 |
|
@@ -113,25 +114,17 @@ public void Add_MeshObject(GameObject InstanceML, float MLwidth, float MLlength,
|
113 | 114 |
|
114 | 115 | //ok na parzyste
|
115 | 116 | //float offset_l = -((length_*MLlength + ((length_/2)-1)*(MLlength + 16f))/2);
|
| 117 | + float offset_l = -((length_ * MLlength + (MLlength + 16f)) / 2); |
116 | 118 |
|
117 |
| - //Debug.Log($"Magazyn {this.Destination}: Lenght:{length_}, Offset: {offset_l}"); |
| 119 | + Debug.Log($"Magazyn {this.Destination}: Lenght:{length_}, Offset: {offset_l}"); |
118 | 120 |
|
119 | 121 | // TODO: fix with Ceiling i Floor
|
120 | 122 | //float offset_l = -((float)(Math.Ceiling((float)(length_ /2)) + (float)(Math.Floor((float)(length_ / 2))) * (MLlength + 16f)) / 2);
|
121 | 123 | //int temp_offset_l = -((int)(Math.Ceiling(length_ / 2) + (int)(Math.Floor(length_ / 2)) * (MLlength + 16))) / 2;
|
122 | 124 | //float offset_l = temp_offset_l;
|
123 |
| - float offset_w = 0f; |
124 |
| - float offset_l = 0f; |
125 | 125 |
|
126 |
| - if (length_ % 2 == 0) |
127 |
| - { |
128 |
| - offset_l = -((length_ * MLlength + (MLlength + 16f)) / 2); |
129 |
| - //-(length_ * MLlength + (MLlength + 16f) / 2); |
130 |
| - } |
131 |
| - else |
132 |
| - { |
133 |
| - offset_l = -((length_ * MLlength + (MLlength + 16f)/2 + MLlength) / 2); |
134 |
| - } |
| 126 | + |
| 127 | + float offset_w = 0f; |
135 | 128 | int path_l = length_ / 2;
|
136 | 129 | for (int l_index = 0; l_index < length_; l_index++)
|
137 | 130 | {
|
@@ -186,31 +179,63 @@ public void Add_MeshObject(GameObject InstanceML, float MLwidth, float MLlength,
|
186 | 179 | int wall_width = (int)(Mathf.RoundToInt(max_offset_w / 13.05f) + 1);
|
187 | 180 |
|
188 | 181 | //dluzsze sciany
|
189 |
| - GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); |
| 182 | + GameObject front_wall = GameObject.CreatePrimitive(PrimitiveType.Cube); |
190 | 183 | // x, y, z, gdzie y to wysokosc
|
191 |
| - cube.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f); |
192 |
| - cube.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f); |
193 |
| - cube.name = $"FrontWall"; |
194 |
| - cube.transform.SetParent(instantiatedObject.transform); |
195 |
| - |
| 184 | + front_wall.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f); |
| 185 | + front_wall.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f); |
| 186 | + front_wall.name = $"FrontWall"; |
| 187 | + front_wall.transform.SetParent(instantiatedObject.transform); |
| 188 | + |
| 189 | + // Create a hole within the wall |
| 190 | + GameObject hole = GameObject.CreatePrimitive(PrimitiveType.Cube); |
| 191 | + float holeWidth = 5.0f; |
| 192 | + float holeHeight = 10.0f; |
| 193 | + hole.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f); |
| 194 | + hole.transform.localScale = new Vector3(holeWidth, holeHeight, 1f); |
| 195 | + hole.transform.SetParent(cube.transform); |
| 196 | + |
| 197 | + Model result = CSG.Subtract(front_wall, hole); |
| 198 | + var composite = new GameObject(); |
| 199 | + composite.AddComponent<MeshFilter>().sharedMesh = result.mesh; |
| 200 | + composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray(); |
| 201 | + cube.transform.position = composite.transform.position; |
| 202 | + composite.transform.SetParent(instantiatedObject.transform); |
| 203 | + |
| 204 | + Destroy(front_wall); |
| 205 | + Destroy(hole); |
| 206 | + |
| 207 | + GameObject back_wall = GameObject.CreatePrimitive(PrimitiveType.Cube); |
| 208 | + back_wall.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + wall_width * 13.05f); |
| 209 | + back_wall.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f); |
| 210 | + back_wall.name = $"BackWall"; |
| 211 | + back_wall.transform.SetParent(instantiatedObject.transform); |
| 212 | + |
| 213 | + GameObject gate_hole = GameObject.CreatePrimitive(PrimitiveType.Cube); |
| 214 | + float gate_width = 10.0f; |
| 215 | + float gate_height = 10.0f; |
| 216 | + gate_hole.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + 6.75f); |
| 217 | + gate_hole.transform.localScale = new Vector3(holeWidth, holeHeight, 1f); |
| 218 | + gate_hole.transform.SetParent(cube.transform); |
| 219 | + |
| 220 | + Model result = CSG.Subtract(back_wall, gate_hole); |
| 221 | + var composite = new GameObject(); |
| 222 | + composite.AddComponent<MeshFilter>().sharedMesh = result.mesh; |
| 223 | + composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray(); |
| 224 | + cube.transform.position = composite.transform.position; |
| 225 | + composite.transform.SetParent(instantiatedObject.transform); |
196 | 226 |
|
197 |
| - GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube); |
198 |
| - cube2.transform.position = new Vector3(this.LocationX, 8f, this.LocationY + wall_width * 13.05f); |
199 |
| - cube2.transform.localScale = new Vector3(wall_length * 13.05f, 15f, 1f); |
200 |
| - cube2.name = $"BackWall"; |
201 |
| - cube2.transform.SetParent(instantiatedObject.transform); |
202 | 227 | //krotsze
|
203 |
| - GameObject cube3 = GameObject.CreatePrimitive(PrimitiveType.Cube); |
204 |
| - cube3.transform.position = new Vector3(this.LocationX + wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4); |
205 |
| - cube3.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1); |
206 |
| - cube3.name = $"LeftWall"; |
207 |
| - cube3.transform.SetParent(instantiatedObject.transform); |
208 |
| - |
209 |
| - GameObject cube4 = GameObject.CreatePrimitive(PrimitiveType.Cube); |
210 |
| - cube4.transform.position = new Vector3(this.LocationX - wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4); |
211 |
| - cube4.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1); |
212 |
| - cube4.name = $"RightWall"; |
213 |
| - cube4.transform.SetParent(instantiatedObject.transform); |
| 228 | + GameObject left_wall = GameObject.CreatePrimitive(PrimitiveType.Cube); |
| 229 | + left_wall.transform.position = new Vector3(this.LocationX + wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4); |
| 230 | + left_wall.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1); |
| 231 | + left_wall.name = $"LeftWall"; |
| 232 | + left_wall.transform.SetParent(instantiatedObject.transform); |
| 233 | + |
| 234 | + GameObject right_wall = GameObject.CreatePrimitive(PrimitiveType.Cube); |
| 235 | + right_wall.transform.position = new Vector3(this.LocationX - wall_length * 13.05f / 2, 8f, this.LocationY + wall_width * 13.05f / 2 + MLlength / 4); |
| 236 | + right_wall.transform.localScale = new Vector3(1f, 15f, wall_width * 13.05f - MLlength / 2 + 1); |
| 237 | + right_wall.name = $"RightWall"; |
| 238 | + right_wall.transform.SetParent(instantiatedObject.transform); |
214 | 239 |
|
215 | 240 | instantiatedObject.transform.rotation = Quaternion.Euler(new Vector3(0, this.rotation, 0));
|
216 | 241 |
|
|
0 commit comments