Iuvo Unity 0.5.1
This is library containing a variety of helper classes and extension methods for the Unity gane engine.
GitHub | Iuvo Unity Updates | Creator
Loading...
Searching...
No Matches
IuvoUnity.ProceduralGeneration.Room Class Reference
Inheritance diagram for IuvoUnity.ProceduralGeneration.Room:

Public Member Functions

void Start ()
 Room (Vector3 position, int width, int height, int length, GameObject roomPrefab)
void InitializeRoom (Vector3 size, bool isBoundaryRoom)
 Sets up the room dimensions and other properties.
void DisableWall (int wallID)
void CountBoundaryWalls ()
void RemoveSharedWalls (List< Room > allRooms)
Wall GetWallFacingPosition (Vector3 position)

Static Public Member Functions

static Room CreateRoom (Vector3 position, Vector3 size, GameObject roomPrefab, bool isBoundaryRoom)
 Factory method to create a Room instance.

Public Attributes

BoxCollider roomBounds
Vector3 center
GameObject roomFloor
Wall northWall
Wall eastWall
Wall southWall
Wall westWall
List< Wallwalls = new List<Wall>()
Transform Top_Middle
Transform Bottom_Middle
Transform Left_Middle
Transform Right_Middle
int boundaryWalls = 0

Properties

bool IsBoundaryRoom = false [get, private set]
bool IsNextToBoundaryRoom [get, private set]

Constructor & Destructor Documentation

◆ Room()

IuvoUnity.ProceduralGeneration.Room.Room ( Vector3 position,
int width,
int height,
int length,
GameObject roomPrefab )
116 {
117 GameObject roomObject = Object.Instantiate(roomPrefab, position, Quaternion.identity);
118 Room room = roomObject.GetComponent<Room>();
119 room.roomBounds.size = new Vector3(width, height, length);
120 }
UnityEngine.Object Object
Definition InterfaceReference.cs:3

References Room().

Referenced by CreateRoom(), RemoveSharedWalls(), and Room().

Member Function Documentation

◆ CountBoundaryWalls()

void IuvoUnity.ProceduralGeneration.Room.CountBoundaryWalls ( )
529 {
530 int boundaryWalls = 0;
531
532 if (northWall.iAmBoundaryWall)
533 {
534 boundaryWalls++;
535 }
536
537 if (southWall.iAmBoundaryWall)
538 {
539
540 boundaryWalls++;
541
542 }
543
544 if (westWall.iAmBoundaryWall)
545 {
546 boundaryWalls++;
547
548 }
549 if (eastWall.iAmBoundaryWall)
550 {
551 boundaryWalls++;
552 }
553
554 if (boundaryWalls != 0)
555 {
556 IsBoundaryRoom = true;
557 }
558
559
560
561 }

References boundaryWalls, eastWall, IsBoundaryRoom, northWall, southWall, and westWall.

Referenced by Start().

◆ CreateRoom()

Room IuvoUnity.ProceduralGeneration.Room.CreateRoom ( Vector3 position,
Vector3 size,
GameObject roomPrefab,
bool isBoundaryRoom )
static

Factory method to create a Room instance.

Parameters
positionThe position of the room.
sizeThe size of the room.
roomPrefabThe room prefab.
isBoundaryRoomIndicates if this room is a boundary room.
Returns
A new Room instance.
152 {
153 if (roomPrefab == null)
154 {
155 IuvoDebug.DebugLogError("Room prefab is null.");
156 return null;
157 }
158
159 GameObject roomObject = Instantiate(roomPrefab, position, Quaternion.identity);
160 Room room = roomObject.GetComponent<Room>();
161
162 if (room == null)
163 {
164 IuvoDebug.DebugLogError("The provided prefab does not have a Room component.");
165 Destroy(roomObject);
166 return null;
167 }
168
169 room.InitializeRoom(size, isBoundaryRoom);
170 return room;
171 }

References IuvoUnity.Debug.IuvoDebug.DebugLogError(), InitializeRoom(), and Room().

◆ DisableWall()

void IuvoUnity.ProceduralGeneration.Room.DisableWall ( int wallID)
174 {
175 if (wallID == 16)
176 {
177 if (northWall != null && !northWall.iAmBoundaryWall)
178 {
179 if (northWall.siblingWall != null)
180 {
181 Destroy(northWall.siblingWall);
182 }
183 northWall.Destroy();
184 }
185
186 if (eastWall != null && !eastWall.iAmBoundaryWall)
187 {
188 if (eastWall.siblingWall != null)
189 {
190 Destroy(eastWall.siblingWall);
191 }
192 eastWall.Destroy();
193 }
194
195 if (southWall != null && !southWall.iAmBoundaryWall)
196 {
197 if (southWall.siblingWall != null)
198 {
199 Destroy(southWall.siblingWall);
200 }
201 southWall.Destroy();
202 }
203
204 if (westWall != null && !westWall.iAmBoundaryWall)
205 {
206 if (westWall.siblingWall != null)
207 {
208 Destroy(westWall.siblingWall);
209 }
210 westWall.Destroy();
211 }
212 }
213 else if (wallID == 1)
214 {
215 if (northWall != null && !northWall.iAmBoundaryWall)
216 {
217 if (northWall.siblingWall != null)
218 {
219 Destroy(northWall.siblingWall);
220 }
221 northWall.Destroy();
222 }
223 }
224 else if (wallID == 2)
225 {
226 if (eastWall != null && !eastWall.iAmBoundaryWall)
227 {
228 if (eastWall.siblingWall != null)
229 {
230 Destroy(eastWall.siblingWall);
231 }
232 eastWall.Destroy();
233 }
234 }
235 else if (wallID == 3)
236 {
237 if (southWall != null && !southWall.iAmBoundaryWall)
238 {
239 if (southWall.siblingWall != null)
240 {
241 Destroy(southWall.siblingWall);
242 }
243 southWall.Destroy();
244 }
245 }
246 else if (wallID == 4)
247 {
248
249 if (westWall != null && !westWall.iAmBoundaryWall)
250 {
251 if (westWall.siblingWall != null)
252 {
253 Destroy(westWall.siblingWall);
254 }
255 westWall.Destroy();
256 }
257 }
258 else if (wallID == 5)
259 {
260 if (northWall != null && !northWall.iAmBoundaryWall)
261 {
262 if (northWall.siblingWall != null)
263 {
264 Destroy(northWall.siblingWall);
265 }
266 northWall.Destroy();
267 }
268
269
270
271 if (westWall != null && !westWall.iAmBoundaryWall)
272 {
273 if (westWall.siblingWall != null)
274 {
275 Destroy(westWall.siblingWall);
276 }
277 westWall.Destroy();
278 }
279 }
280 else if (wallID == 6)
281 {
282 if (eastWall != null && !eastWall.iAmBoundaryWall)
283 {
284 if (eastWall.siblingWall != null)
285 {
286 Destroy(eastWall.siblingWall);
287 }
288 eastWall.Destroy();
289 }
290
291
292 if (southWall != null && !southWall.iAmBoundaryWall)
293 {
294 if (southWall.siblingWall != null)
295 {
296 Destroy(southWall.siblingWall);
297 }
298 southWall.Destroy();
299 }
300 }
301 else if (wallID == 7)
302 {
303 if (southWall != null && !southWall.iAmBoundaryWall)
304 {
305 if (southWall.siblingWall != null)
306 {
307 Destroy(southWall.siblingWall);
308 }
309 southWall.Destroy();
310 }
311
312
313
314 if (westWall != null && !westWall.iAmBoundaryWall)
315 {
316 if (westWall.siblingWall != null)
317 {
318 Destroy(westWall.siblingWall);
319 }
320 westWall.Destroy();
321 }
322 }
323 else if (wallID == 8)
324 {
325 if (northWall != null && !northWall.iAmBoundaryWall)
326 {
327 if (northWall.siblingWall != null)
328 {
329 Destroy(northWall.siblingWall);
330 }
331 northWall.Destroy();
332 }
333
334
335
336 if (eastWall != null && !eastWall.iAmBoundaryWall)
337 {
338 if (eastWall.siblingWall != null)
339 {
340 Destroy(eastWall.siblingWall);
341 }
342 eastWall.Destroy();
343 }
344
345 }
346 else if (wallID == 9)
347 {
348 if (eastWall != null && !eastWall.iAmBoundaryWall)
349 {
350 if (eastWall.siblingWall != null)
351 {
352 Destroy(eastWall.siblingWall);
353 }
354 eastWall.Destroy();
355 }
356
357
358
359 if (westWall != null && !westWall.iAmBoundaryWall)
360 {
361 if (westWall.siblingWall != null)
362 {
363 Destroy(westWall.siblingWall);
364 }
365 westWall.Destroy();
366 }
367 }
368 else if (wallID == 10)
369 {
370 if (northWall != null && !northWall.iAmBoundaryWall)
371 {
372 if (northWall.siblingWall != null)
373 {
374 Destroy(northWall.siblingWall);
375 }
376 northWall.Destroy();
377 }
378
379
380 if (southWall != null && !southWall.iAmBoundaryWall)
381 {
382 if (southWall.siblingWall != null)
383 {
384 Destroy(southWall.siblingWall);
385 }
386 southWall.Destroy();
387 }
388 }
389 else if (wallID == 11)
390 {
391 if (northWall != null && !northWall.iAmBoundaryWall)
392 {
393 if (northWall.siblingWall != null)
394 {
395 Destroy(northWall.siblingWall);
396 }
397 northWall.Destroy();
398 }
399
400 if (southWall != null && !southWall.iAmBoundaryWall)
401 {
402 if (southWall.siblingWall != null)
403 {
404 Destroy(southWall.siblingWall);
405 }
406 southWall.Destroy();
407 }
408
409 if (eastWall != null && !eastWall.iAmBoundaryWall)
410 {
411 if (eastWall.siblingWall != null)
412 {
413 Destroy(eastWall.siblingWall);
414 }
415 eastWall.Destroy();
416 }
417
418
419 }
420 else if (wallID == 12)
421 {
422 if (northWall != null && !northWall.iAmBoundaryWall)
423 {
424 if (northWall.siblingWall != null)
425 {
426 Destroy(northWall.siblingWall);
427 }
428 northWall.Destroy();
429 }
430
431
432 if (southWall != null && !southWall.iAmBoundaryWall)
433 {
434 if (southWall.siblingWall != null)
435 {
436 Destroy(southWall.siblingWall);
437 }
438 southWall.Destroy();
439 }
440
441
442 if (westWall != null && !westWall.iAmBoundaryWall)
443 {
444 if (westWall.siblingWall != null)
445 {
446 Destroy(westWall.siblingWall);
447 }
448 westWall.Destroy();
449 }
450 }
451 else if (wallID == 13)
452 {
453 if (southWall != null && !southWall.iAmBoundaryWall)
454 {
455 if (southWall.siblingWall != null)
456 {
457 Destroy(southWall.siblingWall);
458 }
459 southWall.Destroy();
460 }
461
462 if (eastWall != null && !eastWall.iAmBoundaryWall)
463 {
464 if (eastWall.siblingWall != null)
465 {
466 Destroy(eastWall.siblingWall);
467 }
468 eastWall.Destroy();
469 }
470
471
472
473 if (westWall != null && !westWall.iAmBoundaryWall)
474 {
475 if (westWall.siblingWall != null)
476 {
477 Destroy(westWall.siblingWall);
478 }
479 westWall.Destroy();
480 }
481 }
482 else if (wallID == 14)
483 {
484 if (northWall != null && !northWall.iAmBoundaryWall)
485 {
486 if (northWall.siblingWall != null)
487 {
488 Destroy(northWall.siblingWall);
489 }
490 northWall.Destroy();
491 }
492
493
494
495 if (westWall != null && !westWall.iAmBoundaryWall)
496 {
497 if (westWall.siblingWall != null)
498 {
499 Destroy(westWall.siblingWall);
500 }
501 westWall.Destroy();
502 }
503
504
505 if (eastWall != null && !eastWall.iAmBoundaryWall)
506 {
507 if (eastWall.siblingWall != null)
508 {
509 Destroy(eastWall.siblingWall);
510 }
511 eastWall.Destroy();
512 }
513
514
515 }
516 else if (wallID == 15)
517 {
518 if (roomFloor != null)
519 {
520 roomFloor.gameObject.gameObject.SetActive(false);
521 }
522 }
523 else { return; }
524
525
526 }

References eastWall, northWall, roomFloor, southWall, and westWall.

◆ GetWallFacingPosition()

Wall IuvoUnity.ProceduralGeneration.Room.GetWallFacingPosition ( Vector3 position)
597 {
598 foreach (Wall wall in walls)
599 {
600 // Check if the wall faces the given position
601 if (Vector3.Dot(wall.transform.forward, position - wall.transform.position) > 0)
602 {
603 return wall;
604 }
605 }
606 return null;
607 }

References walls.

Referenced by RemoveSharedWalls().

◆ InitializeRoom()

void IuvoUnity.ProceduralGeneration.Room.InitializeRoom ( Vector3 size,
bool isBoundaryRoom )

Sets up the room dimensions and other properties.

Parameters
sizeThe size of the room.
129 {
130 if (roomBounds == null)
131 {
132 IuvoDebug.DebugLogError("BoxCollider is missing on the Room GameObject.");
133 return;
134 }
135
136 roomBounds.size = size;
137 center = roomBounds.center;
138 IsBoundaryRoom = isBoundaryRoom;
139 }

References center, IuvoUnity.Debug.IuvoDebug.DebugLogError(), IsBoundaryRoom, and roomBounds.

Referenced by CreateRoom().

◆ RemoveSharedWalls()

void IuvoUnity.ProceduralGeneration.Room.RemoveSharedWalls ( List< Room > allRooms)
564 {
565 foreach (Wall wall in walls)
566 {
567 Collider wallCollider = wall.GetComponent<Collider>();
568 if (wallCollider == null)
569 {
570 IuvoDebug.DebugLogError($"Wall {wall.name} has no collider. Skipping.");
571 continue;
572 }
573
574 // Calculate raycast length based on wall dimensions
575 float rayLength = wallCollider.bounds.size.z / 2f + 0.1f; // Add a small buffer to ensure overlap detection
576
577 RaycastHit hit;
578 if (Physics.Raycast(wall.transform.position, -wall.transform.forward, out hit, rayLength))
579 {
580 // Check if the ray hit another room
581 Room neighboringRoom = hit.transform.GetComponentInParent<Room>();
582 if (neighboringRoom != null && neighboringRoom != this)
583 {
584 // Remove the wall in both rooms
585 wall.gameObject.SetActive(false);
586 Wall correspondingWall = neighboringRoom.GetWallFacingPosition(wall.transform.position);
587 if (correspondingWall != null)
588 {
589 correspondingWall.gameObject.SetActive(false);
590 }
591 }
592 }
593 }
594 }

References IuvoUnity.Debug.IuvoDebug.DebugLogError(), GetWallFacingPosition(), Room(), and walls.

◆ Start()

void IuvoUnity.ProceduralGeneration.Room.Start ( )
25 {
26 if (roomFloor == null)
27 {
28 IuvoDebug.DebugLogError("Room floor prefab is null. Cannot create room.");
29 return;
30 }
31
32 roomBounds = GetComponent<BoxCollider>();
33 if (roomBounds == null)
34 {
35 IuvoDebug.DebugLogError("BoxCollider is missing on the Room GameObject.");
36 return;
37 }
38 center = roomBounds.center;
39 //CheckBoundaryWalls();
40 northWall.myNumber = 1;
41 eastWall.myNumber = 2;
42 southWall.myNumber = 3;
43 westWall.myNumber = 4;
44
45
46
47 // Assigning this room to each of the present room's walls
48 // North Wall
49 if (northWall != null)
50 {
51 northWall.myRoom = this;
52 walls.Add(northWall);
53 }
54 else
55 {
56 IuvoDebug.DebugLogError("Room is missing North Wall.");
57 }
58 //South Wall
59 if (southWall != null)
60 {
61
62 southWall.myRoom = this;
63 walls.Add(southWall);
64 }
65 else
66 {
67 IuvoDebug.DebugLogError("Room is missing South Wall.");
68 }
69 //East Wall
70 if (eastWall != null)
71 {
72 eastWall.myRoom = this;
73 walls.Add(eastWall);
74 }
75 else
76 {
77 IuvoDebug.DebugLogError("Room is missing East Wall.");
78 }
79 //West Wall
80 if (westWall != null)
81 {
82 westWall.myRoom = this;
83 walls.Add(westWall);
84 }
85 else
86 {
87 IuvoDebug.DebugLogError("Room is missing West Wall.");
88 }
89
90 // Counts the number of walls that identify as boundaries
91 // if that number is greater than zero the room is
92 // marked as a boundary room as well
93 CountBoundaryWalls();
94
95 for (int i = 0; i < walls.Count; i++)
96 {
97 if (walls[i].iAmBoundaryWall)
98 {
99 for (int j = 0; j < walls[i].myContacts.Count; j++)
100 {
101 if (walls[i].myContacts[j].transform == walls[i].transform)
102 {
103 var wall = walls[i].myContacts[j].GetComponent<Wall>();
104 if (wall != null)
105 { wall.Destroy(); }
106 }
107 }
108
109 walls.RemoveAt(i);
110 }
111 }
112 }

References center, CountBoundaryWalls(), IuvoUnity.Debug.IuvoDebug.DebugLogError(), eastWall, northWall, roomBounds, roomFloor, southWall, walls, and westWall.

Member Data Documentation

◆ Bottom_Middle

Transform IuvoUnity.ProceduralGeneration.Room.Bottom_Middle

◆ boundaryWalls

int IuvoUnity.ProceduralGeneration.Room.boundaryWalls = 0

Referenced by CountBoundaryWalls().

◆ center

Vector3 IuvoUnity.ProceduralGeneration.Room.center

Referenced by InitializeRoom(), and Start().

◆ eastWall

◆ Left_Middle

Transform IuvoUnity.ProceduralGeneration.Room.Left_Middle

◆ northWall

◆ Right_Middle

Transform IuvoUnity.ProceduralGeneration.Room.Right_Middle

◆ roomBounds

BoxCollider IuvoUnity.ProceduralGeneration.Room.roomBounds

Referenced by InitializeRoom(), and Start().

◆ roomFloor

GameObject IuvoUnity.ProceduralGeneration.Room.roomFloor

◆ southWall

◆ Top_Middle

Transform IuvoUnity.ProceduralGeneration.Room.Top_Middle

◆ walls

List<Wall> IuvoUnity.ProceduralGeneration.Room.walls = new List<Wall>()

◆ westWall

Property Documentation

◆ IsBoundaryRoom

bool IuvoUnity.ProceduralGeneration.Room.IsBoundaryRoom = false
getprivate set
20{ get; private set; } = false;

Referenced by CountBoundaryWalls(), and InitializeRoom().

◆ IsNextToBoundaryRoom

bool IuvoUnity.ProceduralGeneration.Room.IsNextToBoundaryRoom
getprivate set
21{ get; private set; }

The documentation for this class was generated from the following file:
  • D:/Unity/IuvoUnityCore/Assets/IuvoUnity/Runtime/ProceduralGenerationBases/Dungeons/Room.cs