void InsertNewValuesParallel(object obj) { try { ThreadData data = obj as ThreadData; InfluenceSource source = data.source; // Get middle point for angle calculation var middle = new Vector2Int(); int count = 0; foreach (var pos in grid.ProjectGridPos(data.bounds)) { middle += pos; count++; } if (count == 0) { middle = data.gridPos; } else { middle.x /= count; middle.y /= count; } float angleCalc = 1; var dir = new Vector2(data.direction.x, data.direction.z); grid.BFS(grid.ProjectGridPos(data.bounds), source.range, (pos, it) => { if (dir != Vector2.zero) { float dot = (Vector2.Dot(dir.normalized, new Vector2(pos.x - middle.x, pos.y - middle.y).normalized) + 1) / 2; angleCalc = dot; } var addVal = source.GetValue(it, source.sourceValue, source.range) * angleCalc; Add(ref addMap[pos.x, pos.y], addVal); Interlocked.Exchange(ref decayMap[pos.x, pos.y], Mathf.Max(addMap[pos.x, pos.y], decayMap[pos.x, pos.y])); }, (neighbor) => { return(Mathf.Approximately(obstacleHeights.GetHeight(neighbor), 0)); }, (neighbor) => { return(dir != Vector2.zero ? angleCalc * directionModifier * data.direction.magnitude : 0); }); Interlocked.Increment(ref completed); } catch (Exception e) { Debug.LogException(e); } }
void Start() { if (grid == null) { Debug.LogError("Missing SharedGrid instance!"); } heightObstacleMap = new float[grid.GetWidth(), grid.GetHeight()]; foreach (Transform child in transform) { foreach (var gridPos in grid.ProjectGridPos(child.GetComponent <Renderer>().bounds)) { heightObstacleMap[gridPos.x, gridPos.y] = child.GetComponent <Renderer>().bounds.size.y; } } }