public bool IsAvailable(int x, int y) { Define.Result result = IsInRange(x, y); if (result != Define.Result.OK) { return(false); } return(!blocks[y][x].Assigned); }
public Define.Result Init(ITruman truman) { this.truman = truman; if (truman == null) { return(Define.Result.NOT_INITIALIZED); } Define.Result result = ManageWorlds(worldStartPivot); return(result); }
private Define.Result ManageWorlds(Vector3 pivotPosition) { Define.Result result = Define.Result.NOT_INITIALIZED; int xRange = (int)activeChunkRange.x; int yRange = is2D ? 1 : Mathf.Max(1, (int)activeChunkRange.y); int zRange = (int)activeChunkRange.z; int unitPivotPosX = (int)(pivotPosition.x / unitChunkSize) * unitChunkSize; int unitPivotPosY = (int)(pivotPosition.y / unitChunkSize) * unitChunkSize; int unitPivotPosZ = (int)(pivotPosition.z / unitChunkSize) * unitChunkSize; float startXPos = unitPivotPosX + ((1 - xRange) / 2) * unitChunkSize; float currentXPos = startXPos; float startYPos = unitPivotPosY + ((0 - yRange) / 2) * unitChunkSize; float currentYPos = startYPos; float startZPos = unitPivotPosZ + ((1 - zRange) / 2) * unitChunkSize; float currentZPos = startZPos; for (int xIndex = 0; xIndex < xRange; xIndex++) { currentYPos = startYPos; for (int yIndex = 0; yIndex < yRange; yIndex++) { currentZPos = startZPos; for (int zIndex = 0; zIndex < zRange; zIndex++) { Tuple <int, int, int> key = new Tuple <int, int, int>((int)currentXPos, (int)currentYPos, (int)currentZPos); if (world.ContainsKey(key)) { world[key].SetAlive(true); } else { GameObject chunkObject = resourceManager.GetObject <GameObject>(resourceCategory, randomChunkPrefabs[Random.Range(0, randomChunkPrefabs.Count)].name); Chunk chunk = chunkObject.GetComponent <Chunk>(); // 기본적으로 청크의 월드 피봇은 청크의 중앙을 가정으로 하며, y는 중앙이 아닌 바닥 기준으로 본다. result = chunk.Init(key, unitChunkSize, chunkAliveTime, CollectChunk); if (result != Define.Result.OK) { return(result); } world.Add(key, chunk); } currentZPos += unitChunkSize; } currentYPos += unitChunkSize; } currentXPos += unitChunkSize; } if (collectedChunk.Count > 0) { foreach (var chunk in collectedChunk) { if (chunk.IsAlive) { continue; } chunk.Serialize(); // IO 생각하면 이건 좀 나이브 하다. world.Remove(chunk.Key); resourceManager.CollectGameObject(resourceCategory, chunk.gameObject); } collectedChunk.Clear(); } return(result); }