private IEnumerator UpdateInsideRoutine() { for (;;) { Transform listener = this.GetListener(); if (listener == null) { yield return(YieldPresets.WaitForFixedUpdate); yield return(0); } else { InsideCheck.GridPosition position = InsideCheck.ToGridPosition(listener.position); if (this._forceRefresh || position != this._currentGridPosition) { this._forceRefresh = false; this._currentGridPosition = position; this._currentGridCells.Clear(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { InsideCheck.GridCell gridCell = InsideCheck.GetGridCell(position + new InsideCheck.GridPosition(i, j)); if (gridCell != null) { this._currentGridCells.Add(gridCell); } } } } for (int k = 0; k < this._occlusion.Count; k++) { this._occlusion[k] = false; } this._roofDetected = InsideCheck.IsAnyRoofAbove(listener.position); if (this._roofDetected) { for (int l = 0; l < this._currentGridCells.Count; l++) { InsideCheck.RenderWallsToOcclusion(this._currentGridCells[l], listener.position, this._occlusion); } } float occlusionPercent = 0f; for (int m = 0; m < this._occlusion.Count; m++) { if (this._occlusion[m]) { occlusionPercent += 1f; } } occlusionPercent *= 100f / (float)this._occlusion.Count; this.SetInside(occlusionPercent >= this.OCCLUSION_THRESHOLD); yield return(YieldPresets.WaitPointOneSeconds); } } yield break; }
private static bool IsAnyRoofAbove(Vector3 position) { InsideCheck.GridCell gridCell = InsideCheck.GetGridCell(InsideCheck.ToGridPosition(position)); if (gridCell != null && gridCell.roofs != null) { for (int i = 0; i < gridCell.roofs.Count; i++) { if (InsideCheck.IsRoofAbove(gridCell.roofs[i], position)) { return(true); } } } return(false); }
public static int AddWallChunk(Vector3 start, Vector3 end, float height) { if (end.y < start.y) { float y = start.y; start.y = end.y; end.y = y; } end.y += height; InsideCheck.WallChunk wallChunk = new InsideCheck.WallChunk(start, end, InsideCheck._nextGridToken); InsideCheck._nextGridToken++; InsideCheck.GridPosition gridPosition = InsideCheck.ToGridPosition(start); InsideCheck.AddWallChunk(gridPosition, wallChunk); InsideCheck.GridPosition gridPosition2 = InsideCheck.ToGridPosition(end); if (gridPosition2 != gridPosition) { InsideCheck.AddWallChunk(gridPosition2, wallChunk); } return(wallChunk.token); }
public static void AddRoof(IRoof roof) { List <Vector3> polygon = roof.GetPolygon(); if (polygon.Count <= 0) { return; } Bounds bounds = new Bounds(polygon[0], Vector3.zero); for (int i = 1; i < polygon.Count; i++) { bounds.Encapsulate(polygon[i]); } InsideCheck.GridPosition gridPosition = InsideCheck.ToGridPosition(bounds.min); InsideCheck.GridPosition gridPosition2 = InsideCheck.ToGridPosition(bounds.max); for (int j = gridPosition.x; j <= gridPosition2.x; j++) { for (int k = gridPosition.y; k <= gridPosition2.y; k++) { InsideCheck.AddRoof(new InsideCheck.GridPosition(j, k), roof); } } }