Implemented new dungeon scene pipeline.
This commit is contained in:
parent
ec466ee6cd
commit
9633b70828
46 changed files with 7607 additions and 233439 deletions
|
|
@ -3,68 +3,72 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
using DungeonMapGenerator;
|
||||
using Unity.VisualScripting;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
|
||||
namespace DungeonGenerator
|
||||
{
|
||||
public class DungeonMapLoader : MonoBehaviour
|
||||
public class DungeonMapLoader
|
||||
{
|
||||
[SerializeField] private string pathToDungeonMap;
|
||||
[SerializeField] private GameObject roomsParent;
|
||||
[SerializeField] private GameObject monsterRoomPrefab;
|
||||
[SerializeField] private GameObject bossRoomPrefab;
|
||||
[SerializeField] private GameObject normalRoomPrefab;
|
||||
private const string ROOMS_PARENT = "RoomsParent";
|
||||
private const string MONSTER_ROOM = "Rooms\\MonsterRoom";
|
||||
private const string BOSS_ROOM = "Rooms\\BossRoom";
|
||||
private const string NORMAL_ROOM = "Rooms\\Room";
|
||||
|
||||
|
||||
private Dictionary<int, GameObject> roomIdToGameObject = new Dictionary<int, GameObject>();
|
||||
private Dictionary<int, GameObject> _roomIdToGameObject = new Dictionary<int, GameObject>();
|
||||
|
||||
private void Start()
|
||||
public void AddDungeonRoomsToGameObject(GameObject gameObject, string pathToDungeonFile)
|
||||
{
|
||||
DungeonMap map = DungeonMapSerializer.DeserializeFromFile(pathToDungeonMap);
|
||||
|
||||
GameObject bossRoomGO = Instantiate(bossRoomPrefab,
|
||||
DungeonMap map = DungeonMapSerializer.DeserializeFromFile(pathToDungeonFile);
|
||||
GameObject bossRoomPrefab = Resources.Load<GameObject>(BOSS_ROOM);
|
||||
GameObject monsterRoomPrefab = Resources.Load<GameObject>(MONSTER_ROOM);
|
||||
GameObject normalRoomPrefab = Resources.Load<GameObject>(NORMAL_ROOM);
|
||||
|
||||
GameObject bossRoomGO = Object.Instantiate(bossRoomPrefab,
|
||||
ConvertToUnityPosition(map.GetBossRoom().GetCenterOfRoom(), map.Width, map.Height),
|
||||
Quaternion.identity,
|
||||
roomsParent.transform);
|
||||
roomIdToGameObject[map.GetBossRoom().Id] = bossRoomGO;
|
||||
gameObject.transform);
|
||||
_roomIdToGameObject[map.GetBossRoom().Id] = bossRoomGO;
|
||||
|
||||
foreach (var monsterRoom in map.GetMonsterRooms())
|
||||
{
|
||||
GameObject monsterRoomGO = Instantiate(
|
||||
GameObject monsterRoomGO = Object.Instantiate(
|
||||
monsterRoomPrefab,
|
||||
ConvertToUnityPosition(monsterRoom.GetCenterOfRoom(), map.Width, map.Height),
|
||||
Quaternion.identity,
|
||||
roomsParent.transform);
|
||||
roomIdToGameObject[monsterRoom.Id] = monsterRoomGO;
|
||||
gameObject.transform);
|
||||
_roomIdToGameObject[monsterRoom.Id] = monsterRoomGO;
|
||||
}
|
||||
|
||||
foreach (var normalRoom in map.GetNormalRooms())
|
||||
{
|
||||
GameObject normalRoomGO = Instantiate(
|
||||
GameObject normalRoomGO = Object.Instantiate(
|
||||
normalRoomPrefab,
|
||||
ConvertToUnityPosition(normalRoom.GetCenterOfRoom(), map.Width, map.Height),
|
||||
Quaternion.identity,
|
||||
roomsParent.transform);
|
||||
roomIdToGameObject[normalRoom.Id] = normalRoomGO;
|
||||
gameObject.transform);
|
||||
_roomIdToGameObject[normalRoom.Id] = normalRoomGO;
|
||||
}
|
||||
|
||||
foreach (var entranceRoom in map.GetEntranceRooms())
|
||||
{
|
||||
GameObject entranceRoomGO = Instantiate(
|
||||
GameObject entranceRoomGO = Object.Instantiate(
|
||||
normalRoomPrefab,
|
||||
ConvertToUnityPosition(entranceRoom.GetCenterOfRoom(), map.Width, map.Height),
|
||||
Quaternion.identity,
|
||||
roomsParent.transform);
|
||||
gameObject.transform);
|
||||
entranceRoomGO.GetComponent<Room>().IsEntrance = true;
|
||||
roomIdToGameObject[entranceRoom.Id] = entranceRoomGO;
|
||||
_roomIdToGameObject[entranceRoom.Id] = entranceRoomGO;
|
||||
}
|
||||
|
||||
foreach (var mapRoom in map.GetAllRooms())
|
||||
{
|
||||
HashSet<int> adjacentRoomsIds = mapRoom.GetAdjacentRoomIds();
|
||||
Room roomComponent = roomIdToGameObject[mapRoom.Id].GetComponent<Room>();
|
||||
Room roomComponent = _roomIdToGameObject[mapRoom.Id].GetComponent<Room>();
|
||||
foreach (var id in adjacentRoomsIds)
|
||||
{
|
||||
roomComponent.AdjacentRooms.Add(roomIdToGameObject[id]);
|
||||
roomComponent.AdjacentRooms.Add(_roomIdToGameObject[id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue