private void SetupRoom(RoomGeneratorHelper generator, Vector3Int extents) { m_Extents = extents; GetComponent <MeshFilter>().mesh = generator.GeneratedMesh; GetComponent <MeshCollider>().sharedMesh = generator.GeneratedMesh; Vector2Int doorLoc; if (generator.GetDoor(RoomConnections.Top, out doorLoc)) { m_TopDoorLocation = transform.position + new Vector3(0.0f, m_RoomSettings.m_FloorHeight - 1.0f, m_Extents.z * 0.5f); } if (generator.GetDoor(RoomConnections.Bottom, out doorLoc)) { m_BottomDoorLocation = transform.position + new Vector3(0.0f, m_RoomSettings.m_FloorHeight - 1.0f, m_Extents.z * -0.5f); } if (generator.GetDoor(RoomConnections.Left, out doorLoc)) { m_LeftDoorLocation = transform.position + new Vector3(m_Extents.x * -0.5f, m_RoomSettings.m_FloorHeight - 1.0f, 0.0f); } if (generator.GetDoor(RoomConnections.Right, out doorLoc)) { m_RightDoorLocation = transform.position + new Vector3(m_Extents.x * 0.5f, m_RoomSettings.m_FloorHeight - 1.0f, 0.0f); } // Setup contains to make management easier for spawned stuff m_EnemyContentContainer = new GameObject(); m_EnemyContentContainer.transform.parent = transform; m_EnemyContentContainer.SetActive(false); m_FloorContentContainer = new GameObject(); m_FloorContentContainer.transform.parent = transform; m_FloorContentContainer.SetActive(false); m_WallContentContainer = new GameObject(); m_WallContentContainer.transform.parent = transform; m_WallContentContainer.SetActive(false); ProcessPlacementSettings(m_EnemyContentContainer, generator, GetEnemyPlacementSettings(), new Vector3(0, 1, 0), false, true); ProcessPlacementSettings(m_FloorContentContainer, generator, GetLootPlacementSettings(), new Vector3(0, 1, 0), true, true); ProcessPlacementSettings(m_FloorContentContainer, generator, GetFloorDressingSettings(), new Vector3(0, 0, 0), true, true); ProcessPlacementSettings(m_WallContentContainer, generator, GetWallDressingSettings(), new Vector3(0, 0, 0), true, false); // Only make barrier on one side if (HasTopDoor) { Instantiate(m_GatePrefab, m_TopDoorLocation, Quaternion.identity, transform); } if (HasLeftDoor) { Instantiate(m_GatePrefab, m_LeftDoorLocation, Quaternion.AngleAxis(90.0f, Vector3.up), transform); } }
public static RoomInstance PlaceRoom(RoomInstance prefab, bool isBossRoom, FloorSettings floorSettings, RoomSettings roomSettings, Vector3Int location, Vector3Int extents, RoomConnections connection) { RoomInstance instance = Instantiate(prefab, location, Quaternion.identity); instance.m_Connections = connection; instance.m_IsBossRoom = isBossRoom; instance.m_RoomSettings = roomSettings; instance.m_FloorSettings = floorSettings; RoomGeneratorHelper generator = new RoomGeneratorHelper(roomSettings, extents, connection); instance.SetupRoom(generator, extents); return(instance); }
private void ProcessPlacementSettings(GameObject targetContainer, RoomGeneratorHelper generator, PlacementSettings settings, Vector3 placeOffset, bool randomRotations, bool useAccessibleSlots) { int placeCount = Random.Range(settings.m_MinPlacements, settings.m_MaxPlacements); if (targetContainer == m_EnemyContentContainer && m_IsBossRoom) { placeCount = 1 + GameController.Main.CurrentLevel * 2; } if (m_IsBossRoom) //? { placeOffset += new Vector3(0, -1.62f, 0); } for (int n = 0; n < placeCount; ++n) { bool hasSlots = useAccessibleSlots ? generator.AccessibleSpots.Any() : generator.InaccessibleSpots.Any(); if (!hasSlots) { return; } GroupPlacementSettings groupSettings = settings.SelectRandomGroup(); int objectCount = Random.Range(groupSettings.m_MinElements, groupSettings.m_MaxElements) + groupSettings.m_AlwaysPlacedObjects.Length; var spots = useAccessibleSlots ? generator.GetFreeAccessibleSpot(objectCount) : generator.GetFreeInaccessibleSpot(objectCount); for (int i = 0; i < spots.Count(); ++i) { GameObject targetObj; if (i < groupSettings.m_AlwaysPlacedObjects.Length) { targetObj = groupSettings.m_AlwaysPlacedObjects[i]; } else { targetObj = groupSettings.SelectRandomObject().m_PlacedObject; } Vector3 offset = new Vector3(Random.Range(-1.0f, 1.0f), -1.0f, Random.Range(-1.0f, 1.0f)) + placeOffset; float angle = randomRotations ? Random.Range(0, 360f) : 0.0f; Vector3 spawnPosition = transform.position + offset + spots.ElementAt(i) - new Vector3(m_Extents.x, 0, m_Extents.z) * 0.5f; GameObject newObj = Instantiate(targetObj, spawnPosition, Quaternion.AngleAxis(angle, Vector3.up), targetContainer.transform); // Should spawn weapon too? CharacterController character = newObj.GetComponentInChildren <CharacterController>(); if (character != null) { foreach (GameObject weapon in GetDefaultWeapons()) { Instantiate(weapon, spawnPosition + Vector3.up * 1.5f, Quaternion.identity, targetContainer.transform); } AIController aiController = newObj.GetComponentInChildren <AIController>(); if (!aiController.HasDefaultProfile) { aiController.SetProfile(GetAIProfile()); } } } } }