Esempio n. 1
0
        private void InitializeGrid()
        {
            mapTiles.Clear();

            tilemap2D = properties.tilemap;
            ITilemap tilemap = GetITilemap(tilemap2D);

            foreach (Vector3Int position in tilemap2D.cellBounds.allPositionsWithin)
            {
                TileData tileData = new TileData();

                TileBase tilebase = tilemap2D.GetTile(position);

                if (tilebase != null)
                {
                    tilebase.GetTileData(position, tilemap, ref tileData);

                    LightTile lightTile = new LightTile();

                    lightTile.gridPosition = position;

                    if (shadowOptimization)
                    {
                        bool left  = GetTile(position + new Vector3Int(1, 0, 0));
                        bool up    = GetTile(position + new Vector3Int(0, 1, 0));
                        bool right = GetTile(position + new Vector3Int(-1, 0, 0));
                        bool down  = GetTile(position + new Vector3Int(0, -1, 0));

                        lightTile.occluded = left && right && up && down;
                    }

                    lightTile.rotation = tilemap2D.GetTransformMatrix(position).rotation.eulerAngles.z;

                    lightTile.SetOriginalSprite(tileData.sprite);
                    lightTile.GetPhysicsShapePolygons();

                    lightTile.colliderType = tileData.colliderType;

                    mapTiles.Add(lightTile);
                }
            }
        }
Esempio n. 2
0
        public override void Initialize()
        {
            base.Initialize();

            if (UpdateProperties() == false)
            {
                return;
            }

            mapTiles.Clear();

            tilemap2D = properties.tilemap;

            ITilemap tilemap = (ITilemap)FormatterServices.GetUninitializedObject(typeof(ITilemap));

            typeof(ITilemap).GetField("m_Tilemap", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(tilemap, tilemap2D);

            foreach (Vector3Int position in tilemap2D.cellBounds.allPositionsWithin)
            {
                TileData tileData = new TileData();

                TileBase tilebase = tilemap2D.GetTile(position);

                if (tilebase != null)
                {
                    tilebase.GetTileData(position, tilemap, ref tileData);

                    LightTile lightTile = new LightTile();
                    lightTile.gridPosition = new Vector3Int(position.x, position.y, position.z);

                    lightTile.scale = tilemap.GetTransformMatrix(position).lossyScale;

                    lightTile.SetOriginalSprite(tileData.sprite);
                    lightTile.GetPhysicsShapePolygons();

                    mapTiles.Add(lightTile);
                }
            }

            chunkManager.Update(mapTiles, this);
        }