public static List <T> TileRandomFill <T>(this T[,] tileArray, System.Random seed, TileAxis originAxis, Action <T> OnEachFill, Predicate <T> availableAxis, int fillCount) where T : class, ITileAxis { List <T> targetList = new List <T>(); T targetAdd = tileArray.Get(originAxis); OnEachFill(targetAdd); targetList.Add(targetAdd); for (int i = 0; i < fillCount; i++) { T temp = targetList[i]; m_EdgeDirections.TraversalRandomBreak((enum_TileDirection randomDirection) => { TileAxis axis = temp.m_Axis.DirectionAxis(randomDirection); if (axis.InRange(tileArray)) { targetAdd = tileArray.Get(axis); if (availableAxis(targetAdd)) { OnEachFill(targetAdd); targetList.Add(targetAdd); return(true); } } return(false); }, seed); } return(targetList); }
public static bool ArrayNearbyContains <T>(this T[,] tileArray, TileAxis origin, Predicate <T> predicate) where T : class, ITileAxis { TileAxis[] nearbyTiles = origin.nearbyFourTiles; for (int i = 0; i < nearbyTiles.Length; i++) { if (origin.InRange(tileArray) && !predicate(tileArray.Get(nearbyTiles[i]))) { return(false); } } return(true); }
public static void PathFindForClosestApproch <T>(this T[,] tileArray, T t1, T t2, List <T> tilePathsAdd, Action <T> OnEachTilePath = null, Predicate <T> stopPredicate = null, Predicate <T> invalidPredicate = null) where T : class, ITileAxis //Temporary Solution, Not Required Yet { if (!t1.m_Axis.InRange(tileArray) || !t2.m_Axis.InRange(tileArray)) { Debug.LogError("Error Tile Not Included In Array"); } tilePathsAdd.Add(t1); TileAxis startTile = t1.m_Axis; for (; ;) { TileAxis nextTile = startTile; float minDistance = (startTile - t2.m_Axis).SqrMagnitude; float offsetDistance; TileAxis offsetTile; TileAxis[] nearbyFourTiles = startTile.nearbyFourTiles; for (int i = 0; i < nearbyFourTiles.Length; i++) { offsetTile = nearbyFourTiles[i]; offsetDistance = (offsetTile - t2.m_Axis).SqrMagnitude; if (offsetTile.InRange(tileArray) && offsetDistance < minDistance) { nextTile = offsetTile; minDistance = offsetDistance; } } if (nextTile == t2.m_Axis || (stopPredicate != null && stopPredicate(tileArray.Get(nextTile)))) { tilePathsAdd.Add(tileArray.Get(nextTile)); break; } if (invalidPredicate != null && invalidPredicate(tileArray.Get(nextTile))) { tilePathsAdd.Clear(); break; } startTile = nextTile; T tilePath = tileArray.Get(startTile); OnEachTilePath?.Invoke(tilePath); tilePathsAdd.Add(tilePath); if (tilePathsAdd.Count > tileArray.Length) { Debug.LogError("Error Path Found Failed"); break; } } }
public static Dictionary <enum_TileDirection, T> GetDirectionAxies <T>(int width, int height, TileAxis centerAxis, List <enum_TileDirection> directions, Func <TileAxis, T> OnItemGet) { Dictionary <enum_TileDirection, T> axisList = new Dictionary <enum_TileDirection, T>(); directions.Traversal((enum_TileDirection direction) => { TileAxis targetAxis = centerAxis.DirectionAxis(direction); if (targetAxis.X < 0 || targetAxis.Y < 0 || targetAxis.X >= width || targetAxis.Y >= height) { return; } axisList.Add(direction, OnItemGet(targetAxis)); }); return(axisList); }
public static enum_TileDirection OffsetDirection(this TileAxis sourceAxis, TileAxis targetAxis) { TileAxis offset = targetAxis - sourceAxis; if (offset.Y == 0) { return(offset.X < 0 ? enum_TileDirection.Left : enum_TileDirection.Right); } if (offset.X == 0) { return(offset.Y > 0 ? enum_TileDirection.Top : enum_TileDirection.Bottom); } return(enum_TileDirection.Invalid); }
public static List <TileAxis> GetDirectionAxies(int width, int height, TileAxis centerAxis, List <enum_TileDirection> directions) { List <TileAxis> axisList = new List <TileAxis>(); directions.Traversal((enum_TileDirection direction) => { TileAxis targetAxis = centerAxis.DirectionAxis(direction); if (targetAxis.X < 0 || targetAxis.Y < 0 || targetAxis.X >= width || targetAxis.Y >= height) { return; } axisList.Add(targetAxis); }); return(axisList); }
public static bool Get <T>(this T[,] tileArray, TileAxis axis, TileAxis size, ref List <T> tileList) where T : class { tileList.Clear(); for (int i = 0; i < size.X; i++) { for (int j = 0; j < size.Y; j++) { if (!InRange(axis + new TileAxis(i, j), tileArray)) { return(false); } tileList.Add(tileArray.Get(axis + new TileAxis(i, j))); } } return(true); }
public static List <TileAxis> GetAxisRange(int width, int height, TileAxis start, TileAxis end) { List <TileAxis> axisList = new List <TileAxis>(); for (int i = start.X; i <= end.X; i++) { for (int j = start.Y; j <= end.Y; j++) { if (i < 0 || j < 0 || i >= width || j >= height) { continue; } axisList.Add(new TileAxis(i, j)); } } return(axisList); }
public static List <TileAxis> GetAxisRange(int width, int height, TileAxis centerAxis, int radius) { List <TileAxis> axisList = new List <TileAxis>(); int sqrRadius = radius * radius; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if ((centerAxis - new TileAxis(i, j)).SqrMagnitude > sqrRadius) { continue; } axisList.Add(new TileAxis(i, j)); } } return(axisList); }
public bool Intersects(TileBounds targetBounds) { TileAxis[] sourceAxies = new TileAxis[] { m_Origin, m_End, m_Origin + new TileAxis(m_Size.X, 0), m_Origin + new TileAxis(0, m_Size.Y) }; for (int i = 0; i < sourceAxies.Length; i++) { if (targetBounds.Contains(sourceAxies[i])) { return(true); } } TileAxis[] targetAxies = new TileAxis[] { targetBounds.m_Origin, targetBounds.m_End, targetBounds.m_Origin + new TileAxis(targetBounds.m_Size.X, 0), targetBounds.m_Origin + new TileAxis(0, targetBounds.m_Size.Y) }; for (int i = 0; i < targetAxies.Length; i++) { if (Contains(targetAxies[i])) { return(true); } } return(false); }
public static bool CheckIsEdge <T>(this T[,] tileArray, TileAxis axis) where T : class, ITileAxis => axis.X == 0 || axis.X == tileArray.GetLength(0) - 1 || axis.Y == 0 || axis.Y == tileArray.GetLength(1) - 1;
public static int Get1DAxisIndex(TileAxis axis, int width) => AxisDimensionTransformation(axis.X, axis.Y, width);
public static TileAxis DirectionAxis(this TileAxis sourceAxis, enum_TileDirection direction) => sourceAxis + m_DirectionAxies[direction];
public static Vector3 GetLocalPosBySizeAxis(TileAxis directionedSize) => new Vector3(directionedSize.X, 0, directionedSize.Y);
public static Vector3 GetUnitScaleBySizeAxis(TileAxis directionedSize, int tileSize) => new Vector3(directionedSize.X, 1, directionedSize.Y) * tileSize;
public static bool InRange <T>(this TileAxis originSize, TileAxis sizeAxis, T[,] range) => InRange <T>(originSize + sizeAxis, range);
public static T Get <T>(this T[,] tileArray, TileAxis axis) where T : class => axis.InRange(tileArray) ? tileArray[axis.X, axis.Y] : null;
public bool Contains(TileAxis axis) => axis.X >= m_Origin.X && axis.X <= m_End.X && axis.Y >= m_Origin.Y && axis.Y <= m_End.Y;
public static TileAxis GetDirectionedSize(TileAxis size, enum_TileDirection direction) => (int)direction % 2 == 0 ? size : size.Inverse();
public TileBounds(TileAxis origin, TileAxis size) { m_Origin = origin; m_Size = size; m_End = m_Origin + m_Size; }
public static bool InRange <T>(this TileAxis axis, T[,] range) => axis.X >= 0 && axis.X < range.GetLength(0) && axis.Y >= 0 && axis.Y < range.GetLength(1);