public void Init() { AIInformationZone component = GetComponent <AIInformationZone>(); if (component == null) { Debug.LogWarning("Unable to Init AIInformationGrid, no AIInformationZone found!"); return; } BoundingBox = component.bounds; BoundingBox.center = base.transform.position + component.bounds.center + new Vector3(0f, BoundingBox.extents.y, 0f); float num = BoundingBox.extents.x * 2f; float num2 = BoundingBox.extents.z * 2f; xCellCount = (int)Mathf.Ceil(num / (float)CellSize); zCellCount = (int)Mathf.Ceil(num2 / (float)CellSize); Cells = new AIInformationCell[xCellCount * zCellCount]; Vector3 vector = (origin = BoundingBox.min); vector.x = BoundingBox.min.x + (float)CellSize / 2f; vector.z = BoundingBox.min.z + (float)CellSize / 2f; for (int i = 0; i < zCellCount; i++) { for (int j = 0; j < xCellCount; j++) { Vector3 center = vector; Bounds bounds = new Bounds(center, new Vector3(CellSize, BoundingBox.extents.y * 2f, CellSize)); Cells[GetIndex(j, i)] = new AIInformationCell(bounds, base.gameObject, j, i); vector.x += CellSize; } vector.x = BoundingBox.min.x + (float)CellSize / 2f; vector.z += CellSize; } }
public AIInformationCell[] GetCellsInRange(Vector3 position, float maxRange, out int cellCount) { cellCount = 0; int num = (int)(maxRange / (float)CellSize); AIInformationCell cell = GetCell(position); if (cell == null) { return(resultCells); } int num2 = Mathf.Max(cell.X - num, 0); int num3 = Mathf.Min(cell.X + num, xCellCount - 1); int num4 = Mathf.Max(cell.Z - num, 0); int num5 = Mathf.Min(cell.Z + num, zCellCount - 1); for (int i = num4; i <= num5; i++) { for (int j = num2; j <= num3; j++) { resultCells[cellCount] = CellAt(j, i); cellCount++; if (cellCount >= 512) { return(resultCells); } } } return(resultCells); }