private void setBufferPoints(int width, Color[] flattenedColorMap, ref RectInt TextureWindow, ref Vector2Int nabourpoint, ref Vector2Int center, Texture2D doubleBuffer, ref FilterArgs filterArguments) { if (TextureWindow.Contains(center)) { filterArguments.color = flattenedColorMap[center.x + width * center.y]; filterArguments.nabours.Clear(); for (int dx = -1; dx < 2; dx++) { for (int dy = -1; dy < 2; dy++) { if (dx == 0 && dy == 0) { continue; } nabourpoint.x = center.x + dx; nabourpoint.y = center.y + dy; if (TextureWindow.Contains(nabourpoint)) { filterArguments.nabours.Add(flattenedColorMap[nabourpoint.x + width * nabourpoint.y]); } } } foreach (var pixelFilters in filters) { filterArguments = pixelFilters.applyFilter(filterArguments); } doubleBuffer.SetPixel(center.x, center.y, filterArguments.color); } }
public static bool AdjacentTo(this RectInt a, Vector2Int b) { return (a.Contains(b + Vector2Int.up) || a.Contains(b + Vector2Int.down) || a.Contains(b + Vector2Int.left) || a.Contains(b + Vector2Int.right)); }
public bool PathExist(Vector2 start, Vector2 destination) { if (!bounds.Contains(Vector2Int.RoundToInt(start)) || !bounds.Contains(Vector2Int.RoundToInt(destination))) { return(false); } if (!Graph[(int)start.x - bounds.xMin, (int)start.y - bounds.yMin].Walkable) { return(false); } return(GetPath(start, destination) == null); }
public ItemType GetItemType(Vector2Int pos) { if (map.TryGetValue(pos, out var obj)) { return(obj.GetComponent <ItemMapInfo>().type); } if (rect.Contains(pos)) { return(ItemType.Empty); } else { return(ItemType.Outside); } }
protected bool CheckGridMovable(Vector2Int grid) { foreach (var areaData in GameEntry.Database.FenceArea.FenceAreaList) { foreach (var fence in areaData.Fences) { if (fence == grid) { return(false); } } } foreach (var shopData in GameEntry.Database.Shop.ShopList) { var deploy = GameEntry.DataTable.GetDataTableRow <DRShop>(shopData.Id); RectInt rect = new RectInt(shopData.LeftBottom, new Vector2Int(deploy.Width, deploy.Height)); if (rect.Contains(grid)) { return(false); } } return(!(grid.x < 1 || grid.x >= 40 || grid.y < 1 || grid.y >= 40)); }
public void ModifyHeightsRect(RectInt area, bool detachMode, Action <Vector2, Cell> modifyAction) { var cells = GetCellData(); HasNeighborChanges = false; for (var x1 = area.xMin; x1 < area.xMax; x1++) { for (var y1 = area.yMin; y1 < area.yMax; y1++) { var cell = cells[x1 + y1 * Width]; var heights = cell.Heights; modifyAction(new Vector2Int(x1, y1), cell); for (var x = -1; x <= 1; x++) { for (var y = -1; y <= 1; y++) { if (x == 0 && y == 0) { continue; } var relation = new Vector2Int(x, y); var neighbor = new Vector2Int(x1 + x, y1 + y); if (!InBounds(neighbor.x, neighbor.y)) { //Debug.Log($"Neighbor {relation} out of bounds"); continue; } if (area.Contains(neighbor)) { //Debug.Log($"{relation} is already being modified"); continue; } var neighborCell = cells[neighbor.x + neighbor.y * Width]; if (!detachMode) { PropagateHeightChangeToNeighbor(cell, neighborCell, relation, heights); } UpdateNeighbors(cell, neighborCell, relation); } } } } if (WalkCellData != null) { UpdateWalkCellData(area); } hasChanges = true; EditorUtility.SetDirty(this); }
public override void Reroute(RectInt rect) { if (path == null) { return; } // TODO: move fallback code to somewhere it can be used anytime work is abandoned bool intersectsPath = false; foreach (var pos in path) { if (rect.Contains(pos)) { intersectsPath = true; } } if (!intersectsPath) { return; } if (!GetPath()) { path = new LinkedList <Vec2I>(); path.AddLast(agent.realPos.Floor()); onFallbackPath = true; } UpdatePathVis(); }
bool IsFloorForRegion(Vector2Int position) { return (_rect.Contains(position) && _game.IsInBounds(position) && _game.IsFloorForRegion(position)); }
private void PlaceTilesIntoNewlyLoadedChunk(MapChunk chunk) { var px = Position.X; var py = Position.Y; var bounds = new RectInt((int)chunk.ChunkX * 8, (int)chunk.ChunkY * 8, 8, 8); foreach (MultiComponentList.MultiItem item in _components.Items) { var x = px + item.OffsetX; var y = py + item.OffsetY; if (bounds.Contains(new Vector2Int(x, y))) { // would it be faster to get the tile from the chunk? var tile = Map.GetMapTile(x, y); if (tile != null) { if (!tile.ItemExists(item.ItemID, item.OffsetZ)) { var staticItem = new StaticItem(item.ItemID, 0, 0, Map); staticItem.Position.Set(x, y, Z + item.OffsetZ); } } } } }
public void SetPixels(IEnumerable <PixelData> data, bool alpha = false) { //Get a copy of the texture on the canvas Texture2D tex2D = (Texture2D)PaintingCanvas.material.mainTexture; tex2D.filterMode = FilterMode.Point; var boundary = new RectInt(0, 0, tex2D.width, tex2D.height); //For each pixel data variable, set the pixel on the texture foreach (var pixel in data) { if (pixel != null && boundary.Contains(pixel.Position)) { if (!alpha) { tex2D.SetPixel(pixel.Position.x, pixel.Position.y, pixel.color); } else { var baseColour = tex2D.GetPixel(pixel.Position.x, pixel.Position.y); baseColour = Color.Lerp(baseColour, pixel.color, pixel.color.a); tex2D.SetPixel(pixel.Position.x, pixel.Position.y, baseColour); } } } //Save the texture data and apply it back to the canvas tex2D.Apply(); PaintingCanvas.material.mainTexture = tex2D; }
protected override bool IsPointWithinControl(int x, int y) { x -= 5; var slider = new RectInt(0, (int)_sliderPosition, _gumpSlider.Width, _gumpSlider.Height); return(slider.Contains(new Vector2Int(x, y))); }
/// <summary> /// 判断瓦片是否与矩形相交(旋转某个角度后的矩形) /// </summary> /// <param name="tileRect">当前瓦片所在矩形</param> /// <param name="areaRect">大矩形</param> /// <param name="angle"></param> /// <returns></returns> public static bool CheckTileCrossRect(RectInt tileRect, RectInt areaRect, float angle) { bool b = false; if (tileRect != null && areaRect != null) { var centerPoint = new PointInt((int)areaRect.Center.X, (int)areaRect.Center.Y); var tPoint1 = GetRotatedPoint(tileRect.LeftTop, centerPoint, angle); var tPoint2 = GetRotatedPoint(tileRect.LeftTop.GetOffSet(tileRect.Width, 0), centerPoint, angle); var tPoint3 = GetRotatedPoint(tileRect.LeftTop.GetOffSet(tileRect.Width, tileRect.Height), centerPoint, angle); var tPoint4 = GetRotatedPoint(tileRect.LeftTop.GetOffSet(0, tileRect.Height), centerPoint, angle); List <PointInt> lstTP = new List <PointInt>() { tPoint1, tPoint2, tPoint3, tPoint4 }; foreach (var item in lstTP) { if (areaRect.Contains(item)) { b = true; break; } } } return(b); }
public void TestRoomTopRight() { var origin = new Vector2Int(0, 0); var size = new Vector2Int(10, 10); RectInt rect = new RectInt(origin, size); var room = new Room(origin, size, 5); Assert.IsTrue(rect.Contains(room.TopRight)); }
public void TestRectWithinBoundsWithinBoundsRight() { var origin = new Vector2Int(0, 0); var size = new Vector2Int(10, 10); var container = new RectInt(origin, size); RectInt rect = VectorHelper.RectWithinBounds(origin, size, 2); Assert.IsTrue(container.Contains(rect.max)); }
public int GetCaratIndexByPosition(Vector2Int pointInText) { var index = 0; if (_root == null) { return(index); } var rect = new RectInt(0, 0, 0, 0); for (var i = 0; i < _root.Children.Count; i++) { var e = _root.Children[i]; rect.width = e.Width; rect.height = e.Height; if (rect.Contains(pointInText)) { return(index); } if (e.IsThisAtomALineBreak) { rect.width = _maxWidth - rect.x; if (rect.Contains(pointInText)) { return(e.IsThisAtomInternalOnly ? index - 1 : index); } rect.x = 0; rect.y += e.Height; } if (e.IsThisAtomInternalOnly) { index--; } rect.x += e.Width; index++; } // check for click at bottom of page rect = new RectInt(0, rect.y, _maxWidth, 2000); if (rect.Contains(pointInText)) { return(index); // end of the last line } return(-1); // don't change }
public void VacateArea(RectInt area, string areaName) { foreach (Minion minion in minions) { if (!minion.hasWork && area.Contains(minion.pos)) { JobTransient.AssignWork(minion, "MapVacate", new TaskGoTo(this, $"Vacating {areaName}.", PathCfg.Vacate(area))); } } }
public void SetOccupied(Vector2Int position, CollisionLayer layer) { if (!_bounds.Contains(position)) { return; } var tile = AddOrGetTile(position); tile.OccupiedLayer |= (tile.CollisionLayerIncrement == CollisionLayer.None ? layer : tile.CollisionLayerIncrement); }
public static bool OnMap(int2 position) { RectInt mapBoundary = new RectInt { x = -Info.Map.Size, y = -Info.Map.Size, width = Info.Map.Width, height = Info.Map.Width, }; return(mapBoundary.Contains(new Vector2Int(position.x, position.y))); }
private void UpdateOccupiedTiles() { if (CurrentZone != null) { foreach (var position in _currentOccupiedTiles.allPositionsWithin) { if (!_previousOccupiedTiles.Contains(position)) { CurrentZone.Tilemap.SetOccupied(position, CollisionLayer); } } } }
/// <summary> /// Finds an item at a position /// </summary> /// <param name="position">The position to check</param> /// <returns>The item at the position, or null if there is none</returns> public Item ItemAt(Vector2Int position) { foreach (StoredItem storedItem in items) { var storedItemPlacement = new RectInt(storedItem.Position, storedItem.Item.Size); if (storedItemPlacement.Contains(position)) { return(storedItem.Item); } } return(null); }
int getOpenListIndexFromPoint(int x, int y) { var r = new RectInt(4, 5, _width - 20, _font.Height); for (var i = 0; i < _openLabels.Length; i++) { if (r.Contains(new Vector2Int(x, y))) { return(i); } r.y += _font.Height; } return(-1); }
public override void OnDrag(RectInt rect) { List <Vec2I> toRemove = new List <Vec2I>(); foreach (var kvp in dragOverlays) { if (!rect.Contains(kvp.Key)) { kvp.Value.Destroy(); toRemove.Add(kvp.Key); } } foreach (var v in toRemove) { dragOverlays.Remove(v); } // TODO: handle agents foreach (var v in rect.allPositionsWithin) { if (!dragOverlays.ContainsKey(v)) { // TODO: handle items // TODO: overlays will be a bit wierd for large buildings // but it should work out var tile = ctrl.game.Tile(v); if (tile.hasBuilding && selection.ApplicableToBuilding(tile.building)) { var overlay = ctrl.assets.CreateJobOverlay( ctrl.game.workOverlays, v, selection.GuiSprite()); dragOverlays.Add(v, overlay.transform); } if (tile.hasItems) { foreach (var item in ctrl.game.GUISelectItemsOnTile(tile)) { if (selection.ApplicableToItem(item)) { var overlay = ctrl.assets.CreateJobOverlay( ctrl.game.workOverlays, v, selection.GuiSprite()); dragOverlays.Add(v, overlay.transform); break; } } } } } }
public override void Calculate(OmniBehaviour t) { RectInt rec = new RectInt(t.Position.x, t.Position.y, Width, Height); if (rec.Contains(PlayerMovement.playerMovement.position)) { for (int i = 0; i < Message.Count; i++) { GameManager.manager.UpdateMessages(Message[i]); GameManager.manager.playerStats.__sanity -= 5; } GameManager.manager.enemies.Remove(t.gameObject); GameObject.Destroy(t.gameObject); } }
protected override void OnEraseTile(Vector2Int tileXY) { // Add game coordinates tileXY += Vector2Int.one; // Find structure on tile int playerIndex = 0; int unitIndex = -1; for (playerIndex = 0; playerIndex < UserData.current.selectedVariant.players.Count; ++playerIndex) { PlayerData.ResourceData resData = UserData.current.GetPlayerResourceData(playerIndex); for (int i = 0; i < resData.units.Count; ++i) { UnitData unit = resData.units[i]; RectInt structureArea = StructureData.GetStructureArea(new Vector2Int(unit.position.x, unit.position.y), unit.typeID); if (structureArea.Contains(tileXY)) { unitIndex = i; break; } } if (unitIndex >= 0) { break; } } if (unitIndex < 0) { return; } PlayerData.ResourceData playerResData = UserData.current.GetPlayerResourceData(playerIndex); UnitData structureToRemove = playerResData.units[unitIndex]; // Remove structure from tile playerResData.units.RemoveAt(unitIndex); UserData.current.SetUnsaved(); m_UnitRenderer.RemoveUnit(structureToRemove); m_MapRenderer.RefreshTiles(StructureData.GetBulldozedStructureArea(new Vector2Int(structureToRemove.position.x - 1, structureToRemove.position.y - 1), structureToRemove.typeID)); }
Vector2Int FindStartPos(Vector2Int start, Vector2Int dir) { // find nearest start point to direction var pos = start; if (dir == Vector2Int.up) { pos = new Vector2Int(start.x, 0); } else if (dir == Vector2Int.down) { pos = new Vector2Int(start.x, gameRect.yMax - 1); } else if (dir == Vector2Int.left) { pos = new Vector2Int(gameRect.xMax - 1, start.y); } else if (dir == Vector2Int.right) { pos = new Vector2Int(0, start.y); } var result = imposiblePosition; while (gameRect.Contains(pos)) { if (map.IsBorder(pos) && map.IsEmpty(pos + dir)) { if ((start - result).sqrMagnitude > (start - pos).sqrMagnitude) { result = pos; } } pos += dir; } if (result == imposiblePosition) { return(start); } return(result); }
public virtual void SetSize() { foreach (Vector2Int position in previousRect.allPositionsWithin) { if (!rect.Contains(position)) { RemoveRenderer(position); } } foreach (Vector2Int position in rect.allPositionsWithin) { if (!previousRect.Contains(position)) { MakeNewRenderer(position); } } previousRect = rect.DeepCopyByExpressionTree <RectInt>(); }
public override bool HitTest(MapLocation pos, InputEventType inputtype) { PointInt p1 = BingMapTileSystem.LatLngToPixelXY(pos1, pos.Level); PointInt p2 = BingMapTileSystem.LatLngToPixelXY(pos2, pos.Level); switch (inputtype) { case InputEventType.MouseMove: RectInt rect = RectInt.FromLTRB(p1.X, p1.Y, p2.X, p2.Y); if (rect.Contains(pos.Position)) { OnMouseMoveOn(); return(true); } OnMouseMoveNotOn(); return(false); } return(false); }
protected void SegmentPosition(Transform trans, int x, int y) { Vector2Int pos = new Vector2Int(x, y) - figure.GetCenterOffset(); RectInt gameRect = GameField.gameField.GetFieldRect(); Vector2Int worldPos = figure.FromFigureToWorldSpace(pos); if (!gameRect.Contains(worldPos)) { worldPos = ClampWorldPoint(worldPos, gameRect.size); trans.position = worldPos.ToVector3Float() + new Vector3(0.5f, 0.5f, 0f); } else { trans.localPosition = pos.ToVector3Float() + new Vector3(0.5f, 0.5f, 0f); } }
public bool isValidPosition(Piece piece, Vector3Int position) { RectInt bounds = this.Bounds; for (int i = 0; i < piece.cells.Length; i++) { Vector3Int tilePosition = piece.cells[i] + position; if (!bounds.Contains((Vector2Int)tilePosition)) { return(false); } if (this.tilemap.HasTile(tilePosition)) { return(false); } } return(true); }
private bool AreUnitsOnTile(Vector2Int tileXY) { // Add game coordinates tileXY += Vector2Int.one; MissionVariant variant = UserData.current.GetCombinedVariant(); foreach (PlayerData player in variant.players) { foreach (UnitData unit in UserData.current.GetCombinedResourceData(player).units) { RectInt otherArea = StructureData.GetStructureArea(new Vector2Int(unit.position.x, unit.position.y), unit.typeID); if (otherArea.Contains(tileXY)) { return(true); } } } return(false); }