Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        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;
                }
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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;
Exemplo n.º 12
0
 public static int Get1DAxisIndex(TileAxis axis, int width) => AxisDimensionTransformation(axis.X, axis.Y, width);
Exemplo n.º 13
0
 public static TileAxis DirectionAxis(this TileAxis sourceAxis, enum_TileDirection direction) => sourceAxis + m_DirectionAxies[direction];
Exemplo n.º 14
0
 public static Vector3 GetLocalPosBySizeAxis(TileAxis directionedSize) => new Vector3(directionedSize.X, 0, directionedSize.Y);
Exemplo n.º 15
0
 public static Vector3 GetUnitScaleBySizeAxis(TileAxis directionedSize, int tileSize) => new Vector3(directionedSize.X, 1, directionedSize.Y) * tileSize;
Exemplo n.º 16
0
 public static bool InRange <T>(this TileAxis originSize, TileAxis sizeAxis, T[,] range) => InRange <T>(originSize + sizeAxis, range);
Exemplo n.º 17
0
 public static T Get <T>(this T[,] tileArray, TileAxis axis) where T : class => axis.InRange(tileArray) ? tileArray[axis.X, axis.Y] : null;
Exemplo n.º 18
0
 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;
Exemplo n.º 19
0
 public static TileAxis GetDirectionedSize(TileAxis size, enum_TileDirection direction) => (int)direction % 2 == 0 ? size : size.Inverse();
Exemplo n.º 20
0
 public TileBounds(TileAxis origin, TileAxis size)
 {
     m_Origin = origin;
     m_Size   = size;
     m_End    = m_Origin + m_Size;
 }
Exemplo n.º 21
0
 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);