Beispiel #1
0
        public PhysicsTile[] GetNearByTiles(Vector3 worldPoint, int radius)
        {
            Vector3Int         cell  = grid.WorldToCell(worldPoint);
            List <PhysicsTile> tiles = new List <PhysicsTile>();

            int minX = cell.x - radius;
            int maxX = cell.x + radius;

            for (int x = minX; x <= maxX; x++)
            {
                int dx = (cell.x - x);
                int dy = Mathf.RoundToInt(Mathf.Sqrt(radius * radius - dx * dx));

                int minY = cell.y - dy;
                int maxY = cell.y + dy;

                for (int y = minY; y <= maxY; y++)
                {
                    PhysicsTile tile = GetPhysicsTileAt(new Vector3Int(x, y, 0));
                    if (tile != null)
                    {
                        tiles.Add(tile);
                    }
                }
            }

            return(tiles.ToArray());
        }
Beispiel #2
0
        private void OnDespawnPhysicsTile(TileWorldEventData data)
        {
            PhysicsTile physicsTile = data.TileObject;

            physicsTile.transform.Reset();
            physicsTile.transform.position = OFF_SCREEN;

            physicsTile.Despawn();
            physicsTile.gameObject.SetActive(false);

            physicsTiles.Put(physicsTile);
        }
Beispiel #3
0
        private PhysicsTile GetPhysicsTileAt(Vector3Int cell)
        {
            TileBase tile = environment.GetTile(cell);

            if (tile == null)
            {
                return(null);
            }

            PhysicsTile physicsTile = physicsTiles.Take();

            physicsTile.transform.Reset();
            physicsTile.transform.parent   = physicsTileContainer;
            physicsTile.transform.position = environment.CellToWorld(cell) + (environment.cellSize * 0.5f);

            physicsTile.gameObject.SetActive(true);
            physicsTile.Spawn(environment.GetSprite(cell), environment.cellSize);

            environment.SetTile(cell, null);

            return(physicsTile);
        }
Beispiel #4
0
 private void DeallocatePhysicsTile(PhysicsTile tile)
 {
     Destroy(tile.gameObject);
 }