/// <summary> /// Spawns the player inside. Be carefull, the name of the cell is not the same for each languages. /// Use it with the correct name. /// </summary> /// <param name="playerPrefab">The player prefab.</param> /// <param name="interiorCellName">The name of the desired cell.</param> /// <param name="position">The target position of the player.</param> public void SpawnPlayerInside(GameObject playerPrefab, string interiorCellName, Vector3 position) { _currentCell = _data.FindInteriorCellRecord(interiorCellName); Debug.Assert(_currentCell != null); CreatePlayer(playerPrefab, position, out _playerCameraObj); var cellInfo = _cellManager.StartCreatingInteriorCell(interiorCellName); _temporalLoadBalancer.WaitForTask(cellInfo.objectsCreationCoroutine); OnInteriorCell(_currentCell); }
private static void SpawnPlayer(GameObject playerPrefab, Vector3Int gridId, Vector3 position) { _currentCell = Data.FindCellRecord(gridId); Utils.Assert(_currentCell != null); CreatePlayer(playerPrefab, position, out _playerCameraObj); var cellInfo = CellManager.StartCreatingCell(gridId); LoadBalancer.WaitForTask(cellInfo.ObjectsCreationCoroutine); }
/// <summary> /// Spawns the player inside using the cell's grid coordinates. /// </summary> /// <param name="playerPrefab">The player prefab.</param> /// <param name="position">The target position of the player.</param> public void SpawnPlayer(GameObject playerPrefab, Vector3 position) { var cellId = CellManager.GetCellId(position, _currentWorld); _currentCell = Data.FindCellRecord(cellId); Debug.Assert(_currentCell != null); CreatePlayer(playerPrefab, position, out _playerCameraObj); var cellInfo = CellManager.StartCreatingCell(cellId); LoadBalancer.WaitForTask(cellInfo.ObjectsCreationCoroutine); if (cellId.z != -1) { OnExteriorCell(_currentCell); } else { OnInteriorCell(_currentCell); } }
public void UpdateCells(Vector3 currentPosition, int world, bool immediate = false, int cellRadiusOverride = -1) { var cameraCellId = GetCellId(currentPosition, world); var cellRadius = cellRadiusOverride >= 0 ? cellRadiusOverride : _cellRadius; var minCellX = cameraCellId.x - cellRadius; var maxCellX = cameraCellId.x + cellRadius; var minCellY = cameraCellId.y - cellRadius; var maxCellY = cameraCellId.y + cellRadius; // Destroy out of range cells. var outOfRangeCellIds = new List <Vector3Int>(); foreach (var x in _cellObjects) { if (x.Key.x < minCellX || x.Key.x > maxCellX || x.Key.y < minCellY || x.Key.y > maxCellY) { outOfRangeCellIds.Add(x.Key); } } foreach (var cellId in outOfRangeCellIds) { DestroyCell(cellId); } // Create new cells. for (var r = 0; r <= cellRadius; r++) { for (var x = minCellX; x <= maxCellX; x++) { for (var y = minCellY; y <= maxCellY; y++) { var cellId = new Vector3Int(x, y, world); var cellXDistance = Mathf.Abs(cameraCellId.x - cellId.x); var cellYDistance = Mathf.Abs(cameraCellId.y - cellId.y); var cellDistance = Mathf.Max(cellXDistance, cellYDistance); if (cellDistance == r && !_cellObjects.ContainsKey(cellId)) { var cellInfo = StartCreatingCell(cellId); if (cellInfo != null && immediate) { _loadBalancer.WaitForTask(cellInfo.ObjectsCreationCoroutine); } } } } } // Update LODs. foreach (var x in _cellObjects) { var cellIndices = x.Key; var cellInfo = x.Value; var cellXDistance = Mathf.Abs(cameraCellId.x - cellIndices.x); var cellYDistance = Mathf.Abs(cameraCellId.y - cellIndices.y); var cellDistance = Mathf.Max(cellXDistance, cellYDistance); if (cellDistance <= _detailRadius) { if (!cellInfo.ObjectsContainerGameObject.activeSelf) { cellInfo.ObjectsContainerGameObject.SetActive(true); } } else { if (cellInfo.ObjectsContainerGameObject.activeSelf) { cellInfo.ObjectsContainerGameObject.SetActive(false); } } } }