Пример #1
0
        Component _CreateTileGO(GameObject prefab, int x, int y, PositionCallback callback)
        {
            GameObject tile = Object.Instantiate(prefab);

            tile.transform.SetParent(container.transform);
            tile.transform.localPosition = new Vector2(x + 0.5f, y + 0.5f);

            TileBehaviour tileBehaviour = tile.GetComponent <TileBehaviour> ();

            if (tileBehaviour != null)
            {
                tileBehaviour._x = x;
                tileBehaviour._y = y;

                x += tileBehaviour.areaBottomLeftXOffset;
                y += tileBehaviour.areaBottomLeftYOffset;

                bool[,] area = tileBehaviour.area;

                for (int i = 0; i < area.GetLength(0); i++)
                {
                    for (int j = 0; j < area.GetLength(1); j++)
                    {
                        if (area [i, j])
                        {
                            componentGrid.Set(x + i, y + j, tileBehaviour);

                            callback(x + i, y + j);
                        }
                    }
                }

                componentGrid.Set(
                    tileBehaviour._x,
                    tileBehaviour._y,
                    tileBehaviour
                    );

                return(tileBehaviour);
            }
            else
            {
                componentGrid.Set(x, y, tile.transform);

                return(tile.transform);
            }
        }
Пример #2
0
        /// <summary>
        /// Checks if the specified TileBehaviour would overlap any other tileGO if placed at the specified location.
        /// </summary>
        /// <param name="x">The x tile coordinate.</param>
        /// <param name="y">The y tile coordinate.</param>
        public bool HasOverlap(int x, int y, TileBehaviour behaviour)
        {
            x += behaviour.areaBottomLeftXOffset;
            y += behaviour.areaBottomLeftYOffset;

            bool[,] area = behaviour.area;

            for (int i = 0; i < area.GetLength(0); i++)
            {
                for (int j = 0; j < area.GetLength(1); j++)
                {
                    if (area [i, j] && GetTileGO(x + i, y + j) != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }