diff --git a/3D blobici/Assets/Scenes/GenTest.unity b/3D blobici/Assets/Scenes/GenTest.unity index 7bf0044..67c58ad 100644 --- a/3D blobici/Assets/Scenes/GenTest.unity +++ b/3D blobici/Assets/Scenes/GenTest.unity @@ -156,7 +156,9 @@ MonoBehaviour: EndPoint: {fileID: 819094401162878122, guid: 03f2147e5a186fc408b959faa2f97e86, type: 3} Player: {fileID: 6983871523237736218, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} CorridorStraight: {fileID: 8047827979703692770, guid: 1a5d554c0c76caf4195cae47e098b79d, type: 3} - RoomDistance: 70 + CorridorStraightUnlit: {fileID: 2016417306107577256, guid: 92d9025262a022a499862d352c2724ee, type: 3} + DoorCorridor: {fileID: 5603417387143431118, guid: 9eccbf5a500a0d2429e6008a713a49fd, type: 3} + RoomDistance: 40 minRoomsNumber: 3 maxRoomsNumber: 7 --- !u!4 &23489964 diff --git a/3D blobici/Assets/Scenes/Objekty.unity b/3D blobici/Assets/Scenes/Objekty.unity index 654a8a0..08f3c0d 100644 --- a/3D blobici/Assets/Scenes/Objekty.unity +++ b/3D blobici/Assets/Scenes/Objekty.unity @@ -779,21 +779,53 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1872598832695960773, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6983871523237736218, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} propertyPath: m_Name value: PlayerContainer objectReference: {fileID: 0} + - target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalScale.x + value: 1.5 + objectReference: {fileID: 0} + - target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalScale.y + value: 1.5 + objectReference: {fileID: 0} + - target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} + propertyPath: m_LocalScale.z + value: 1.5 + objectReference: {fileID: 0} - target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} propertyPath: m_LocalPosition.x value: 0 objectReference: {fileID: 0} - target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} propertyPath: m_LocalPosition.y - value: 0 + value: 4.49 objectReference: {fileID: 0} - target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} propertyPath: m_LocalPosition.z - value: 0 + value: 15.09 objectReference: {fileID: 0} - target: {fileID: 7001416999833331379, guid: f0df263e5be65a041848d5a8bab85af1, type: 3} propertyPath: m_LocalRotation.w diff --git a/3D blobici/Assets/Scripts/MapGen/MapGenManager.cs b/3D blobici/Assets/Scripts/MapGen/MapGenManager.cs index f67c72e..be4dde9 100644 --- a/3D blobici/Assets/Scripts/MapGen/MapGenManager.cs +++ b/3D blobici/Assets/Scripts/MapGen/MapGenManager.cs @@ -14,13 +14,15 @@ public class MapGenManager : MonoBehaviour [Header("Corridor Prefabs")] [SerializeField] private GameObject CorridorStraight; + [SerializeField] private GameObject CorridorStraightUnlit; + [SerializeField] private GameObject DoorCorridor; /*[SerializeField] private GameObject CorridorL; [SerializeField] private GameObject CorridorT; [SerializeField] private GameObject CorridorCross; [SerializeField] private GameObject CorridorEnd;*/ [Header("Generation Settings")] - [SerializeField] private int RoomDistance = 5; + [SerializeField] private int RoomDistance = 3; [SerializeField] private int minRoomsNumber = 3; [SerializeField] private int maxRoomsNumber = 7; @@ -53,15 +55,15 @@ public class MapGenManager : MonoBehaviour // Place Generate Rooms for (int i = 0; i < roomCount; i++) { - Vector3 roomPos = GetGridPosition(); GameObject roomPrefab = mapPrefab[Random.Range(0, mapPrefab.Count)]; + Vector3 roomPos = GetGridPosition(roomPrefab); GameObject room = Instantiate(roomPrefab, roomPos, Quaternion.identity, transform); placedRooms.Add(room); roomPositions.Add(roomPos); } // Add End Point - GameObject endPoint = Instantiate(EndPoint, GetGridPosition(), Quaternion.identity, transform); + GameObject endPoint = Instantiate(EndPoint, GetGridPosition(EndPoint), Quaternion.identity, transform); roomPositions.Add(endPoint.transform.position); placedRooms.Add(endPoint); @@ -73,31 +75,31 @@ public class MapGenManager : MonoBehaviour Vector3 endRoomPos = roomPositions[i + 1]; PrefabSize endRoom = placedRooms[i + 1].GetComponent(); Vector3 firstCorridorPos = new Vector3( - startRoomPos.x + startRoom.prefabSize.x / 2, + startRoomPos.x, startRoomPos.y, - startRoomPos.z + startRoomPos.z + startRoom.prefabSize.y / 2 ); Vector3 lastCorridorPos = new Vector3( - endRoomPos.x - endRoom.prefabSize.x / 2, + endRoomPos.x, endRoomPos.y, - endRoomPos.z + endRoomPos.z - endRoom.prefabSize.y / 2 ); CreateCorridor(firstCorridorPos, lastCorridorPos); } } - private Vector3 GetGridPosition() + private Vector3 GetGridPosition(GameObject roomPrefab) { Vector3 lastRoomPos = roomPositions[roomPositions.Count - 1]; + PrefabSize lastRoom = placedRooms[placedRooms.Count - 1].GetComponent(); + PrefabSize roomSize = roomPrefab.GetComponent(); - // Convert grid units to world position Vector3 roomPos = new Vector3( - lastRoomPos.x + RoomDistance, + lastRoomPos.x, lastRoomPos.y, - lastRoomPos.z + lastRoomPos.z + lastRoom.prefabSize.y / 2f + roomSize.prefabSize.y / 2f + RoomDistance ); - return roomPos; } @@ -106,21 +108,53 @@ public class MapGenManager : MonoBehaviour // Calculate the distance float distance = Vector3.Distance(start, end); PrefabSize corridorSize = CorridorStraight.GetComponent(); + PrefabSize corridorUnlitSize = CorridorStraightUnlit.GetComponent(); + PrefabSize doorSize = DoorCorridor.GetComponent(); // Calculate the number of corridors needed - int corridorCount = Mathf.FloorToInt(distance / corridorSize.prefabSize.x); + int corridorCount = Mathf.FloorToInt(distance / corridorSize.prefabSize.y); Debug.Log($"Creating {corridorCount} corridors from {start} to {end}"); // Create corridors - for (int i = 0; i < corridorCount; i++) + //Start with door + if (corridorCount > 0) { - Vector3 pos = new Vector3( - start.x + i * corridorSize.prefabSize.x + corridorSize.prefabSize.x * 0.5f, + Vector3 doorPos = new Vector3( + start.x, start.y, - start.z + start.z + doorSize.prefabSize.y * 0.5f ); - Quaternion rotation = Quaternion.Euler(0, 90, 0); - GameObject corridor = Instantiate(CorridorStraight, pos, rotation, transform); + Quaternion doorRotation = Quaternion.Euler(0, 0, 0); + GameObject doorCorridor = Instantiate(DoorCorridor, doorPos, doorRotation, transform); + + + for (int i = 1; i < corridorCount; i++) + { + if(i % 2 != 0) + { + // Create straight corridor + Vector3 pos = new Vector3( + start.x, + start.y, + start.z + i * corridorSize.prefabSize.y + corridorSize.prefabSize.y * 0.5f + ); + Quaternion rotation = Quaternion.Euler(0, 0, 0); + GameObject corridor = Instantiate(CorridorStraight, pos, rotation, transform); + } + else + { + // Create unlit corridor + Vector3 pos = new Vector3( + start.x, + start.y, + start.z + i * corridorUnlitSize.prefabSize.y + corridorUnlitSize.prefabSize.y * 0.5f + ); + Quaternion rotation = Quaternion.Euler(0, 0, 0); + GameObject corridorUnlit = Instantiate(CorridorStraightUnlit, pos, rotation, transform); + } + } } + // If there is not enough space to create corridors, throw an exception + else throw new System.Exception("Not enough space to create corridors"); } } \ No newline at end of file diff --git a/3D blobici/Assets/Scripts/Menu/MenuController.cs b/3D blobici/Assets/Scripts/Menu/MenuController.cs index 6619de8..9cdb194 100644 --- a/3D blobici/Assets/Scripts/Menu/MenuController.cs +++ b/3D blobici/Assets/Scripts/Menu/MenuController.cs @@ -7,7 +7,7 @@ public class MenuController : MonoBehaviour public void PlayButton() { - SceneManager.LoadScene("Podzemi"); + SceneManager.LoadScene("GenTest"); } public void SettingButtonn() diff --git a/3D blobici/ProjectSettings/EditorBuildSettings.asset b/3D blobici/ProjectSettings/EditorBuildSettings.asset index 5ed9cac..9e8c014 100644 --- a/3D blobici/ProjectSettings/EditorBuildSettings.asset +++ b/3D blobici/ProjectSettings/EditorBuildSettings.asset @@ -11,5 +11,8 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/Objekty.unity guid: 9fc0d4010bbf28b4594072e72b8655ab + - enabled: 1 + path: Assets/Scenes/GenTest.unity + guid: aaa0d7a56cbb4e24b851ccae66aa8925 m_configObjects: {} m_UseUCBPForAssetBundles: 0