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); }