public static Vector2 ClosestPoint(this Rect rect, Vector2 point) { if (point.x < rect.xMin) { if (point.y < rect.yMin) { return(new Vector2(rect.xMin, rect.yMin)); } else if (point.y > rect.yMax) { return(new Vector2(rect.xMin, rect.yMax)); } else { return(point.AddX(rect.xMin - point.x)); } } else if (point.x > rect.xMax) { if (point.y < rect.yMin) { return(new Vector2(rect.xMax, rect.yMin)); } else if (point.y > rect.yMax) { return(new Vector2(rect.xMax, rect.yMax)); } else { return(point.AddX(point.x - rect.xMax)); } } else { if (point.y < rect.yMin) { return(point.AddY(rect.yMin - point.y)); } else if (point.y > rect.yMax) { return(point.AddY(point.y - rect.yMax)); } else { return(point); } } }
private void LerpLayoutYTranslation(float yDistance) { this.StopAllCoroutines(); Vector2 startPosition = layoutRectTransform_.anchoredPosition; Vector2 endPosition = startPosition.AddY(yDistance); this.DoEaseFor(kLerpDuration, EaseType.QuadraticEaseOut, (float p) => { layoutRectTransform_.anchoredPosition = Vector2.Lerp(startPosition, endPosition, p); }); }
public void add_y_test() { //Arrange Vector2 input = Vector2.one; //Act input = input.AddY(1); //Assert Assert.AreEqual(1, input.x); Assert.AreEqual(2, input.y); }
public Dictionary<Vector2, Tile> GetNeighbors(Vector2 center) { var toCheck = new Vector2[4]{ center.AddX(1f), center.AddX(-1f), center.AddY(1f), center.AddY(-1f) }; return CheckNeighbors(toCheck); }
public Dictionary<Vector2, Tile> GetKingNeighbors(Vector2 center) { var toCheck = new Vector2[8]{ center.AddX(1f), center.AddX(-1f), center.AddY(1f), center.AddY(-1f), center.Add(-1, -1), center.Add(-1, 1), center.Add(1, -1), center.Add(1, 1) }; return CheckNeighbors(toCheck); }
public Dictionary<Vector2, Tile> GetCrossTiles(Vector2 center, int distance) { var ret = new Dictionary<Vector2, Tile>() { { center, mapModel.tiles.Get(center) } }; Tile neighborTile = null; for (var d = 1; d <= distance; d++) { var toCheck = new Vector2[4] { center.AddX(d), center.AddX(-d), center.AddY(d), center.AddY(-d) }; foreach (var currentDirection in toCheck) { //check it's not off the map neighborTile = mapModel.tiles.Get(currentDirection); if (neighborTile != null) { ret[currentDirection] = neighborTile; } } } return ret; }