示例#1
0
        //Called when the left mouse button is initially held down
        public override bool OnClickDown(Point point, ScriptableTile tile, TileMap map)
        {
            //Return if the tilemap is null/empty
            if (map == null)
            {
                return(false);
            }
            //Gets the tile where you clicked
            ScriptableTile start = map.GetTileAt(point);

            //Return if ther tile specified is null
            if (tile == null)
            {
                return(false);
            }
            //The queue of points that need to be changed to the specified tile
            Queue <Point> open = new Queue <Point> ();
            //The list of points already changed to the specified tile
            List <Point> closed = new List <Point> ();
            //A number larger than the amount of tiles available
            int maxLoops = map.Width * map.Height * 10;

            //Add the specified point to the open queue
            open.Enqueue(point);
            //As long as there are items in the queue, keep this running
            while (open.Count > 0)
            {
                //Decrement the max loops value
                maxLoops--;
                //If we've executed this code more than the max loops then we've done something wrong :/
                if (maxLoops <= 0)
                {
                    Debug.LogError("Fill tool, max loops reached!");
                    return(false);
                }

                Point p = open.Dequeue();
                if (closed.Contains(p))
                {
                    continue;
                }

                closed.Add(p);
                ScriptableTile t = map.GetTileAt(p);

                if (!map.IsInBounds(p) || t != start)
                {
                    continue;
                }

                open.Enqueue(p.Up);
                open.Enqueue(p.Right);
                open.Enqueue(p.Down);
                open.Enqueue(p.Left);

                map.SetTileAt(p, tile);
            }

            return(true);
        }
示例#2
0
        public override Sprite GetSprite(TileMap tilemap = null, Point position = default(Point))
        {
            if (tilemap == null)
            {
                return(bitmaskSprites[15]);
            }

            ScriptableTile left  = tilemap.GetTileAt(position.Left);
            ScriptableTile up    = tilemap.GetTileAt(position.Up);
            ScriptableTile right = tilemap.GetTileAt(position.Right);
            ScriptableTile down  = tilemap.GetTileAt(position.Down);

            int index = 0;

            if ((!tilemap.IsInBounds(position.Up) && defaultIsFull) || (up && up.ID == this.ID))
            {
                index += 1;
            }
            if ((!tilemap.IsInBounds(position.Right) && defaultIsFull) || (right && right.ID == this.ID))
            {
                index += 8;
            }
            if ((!tilemap.IsInBounds(position.Down) && defaultIsFull) || (down && down.ID == this.ID))
            {
                index += 4;
            }
            if ((!tilemap.IsInBounds(position.Left) && defaultIsFull) || (left && left.ID == this.ID))
            {
                index += 2;
            }

            if (index < bitmaskSprites.Length && bitmaskSprites [index])
            {
                return(bitmaskSprites [index]);
            }

            return(bitmaskSprites [15]);
        }
示例#3
0
        public override Sprite GetSprite(TileMap tilemap = null, Point position = default(Point))
        {
            if (tilemap == null)
            {
                return(bitmaskSprites[15]);
            }

            ScriptableTile[] tiles = new ScriptableTile[] {
                tilemap.GetTileAt(position.Up),
                tilemap.GetTileAt(position.Left),
                tilemap.GetTileAt(position.Down),
                tilemap.GetTileAt(position.Right),
            };
            int[] bitmasks = new int[] {
                1, 2, 4, 8
            };
            Point[] points = new Point[] {
                position.Up,
                position.Left,
                position.Down,
                position.Right,
            };

            int index = 0;

            for (int i = 0; i < 4; i++)
            {
                bool exists = tiles[i] != null;
                bool isSame = exists && tiles[i].ID == this.ID;
                bool isEdge = !tilemap.IsInBounds(points[i]);

                if ((isEdge && edgesAreFull) || (exists && mode == AutoTileMode.Everything) || (exists && (mode == AutoTileMode.SameTile && isSame)))
                {
                    index += bitmasks[i];
                }
            }

            if (index < bitmaskSprites.Length && bitmaskSprites [index])
            {
                return(bitmaskSprites [index]);
            }

            return(bitmaskSprites [15]);
        }