private void AddSegmentToGrid(Vector2 start, Vector2 end, int segmentIndex) { if (this.grid != null) { Vector2 vector = Vector2.Min(start, end); Vector2 vector2 = Vector2.Max(start, end); AreaEmitter.Polygon.GridPosition gridPosition = this.CalculateGridPosition(Vector2.Min(start, end)); AreaEmitter.Polygon.GridPosition gridPosition2 = this.CalculateGridPosition(Vector2.Max(start, end)); for (int i = gridPosition.row; i <= gridPosition2.row; i++) { for (int j = gridPosition.column; j <= gridPosition2.column; j++) { if (this.grid[i, j] == null) { this.grid[i, j] = new List <int>(); } this.grid[i, j].Add(segmentIndex); } } } }
private void UpdateSegmentsWithGrid(Func <Vector3, Vector2> InverseTransformPoint) { Vector2 point = InverseTransformPoint(LocalPlayer.Transform.position); AreaEmitter.Polygon.GridPosition gridPosition = this.CalculateGridPosition(point); AreaEmitter.Polygon.GridPosition gridPosition2 = gridPosition; if (0 < gridPosition.row && point.y < this.bounds.yMax) { gridPosition.row--; } if (gridPosition2.row < this.grid.GetLength(0) - 1 && this.bounds.yMin < point.y) { gridPosition2.row++; } if (0 < gridPosition.column && point.x < this.bounds.xMax) { gridPosition.column--; } if (gridPosition2.column < this.grid.GetLength(1) - 1 && this.bounds.xMin < point.x) { gridPosition2.column++; } for (int i = gridPosition.row; i <= gridPosition2.row; i++) { for (int j = gridPosition.column; j <= gridPosition2.column; j++) { List <int> list = this.grid[i, j]; if (list != null) { for (int k = 0; k < list.Count; k++) { this.UpdateSegment(list[k]); } } } } }