void ChangeCreateBlockSprite() { if (!HasBlock) { return; } byte thisTileMask = 0x00; byte neighborDirMask = 0x80; foreach (var neighborTile in neighborTiles) { if (neighborTile?.block?.BlockInfo.Name == block.BlockInfo.Name) { if (!block.BlockInfo.TileSet.OnlyCross || (block.BlockInfo.TileSet.OnlyCross && crossNeighborTiles.Contains(neighborTile))) { thisTileMask |= neighborDirMask; } } neighborDirMask >>= 1; } if (block.BlockInfo.TileSet.OnlyCross) { thisTileMask &= 0b_0101_1010; } block.Mask = thisTileMask; var e = new ChangeBlockSpriteArgs(Vector3Int, block.BlockInfo.TileSet[thisTileMask]); changedBlockSpriteEvent?.Invoke(this, e); }
void ChangeDestroyBlockSprite() { if (HasBlock) { return; } var changeBlockSpriteArgs = new ChangeBlockSpriteArgs(Vector3Int, null); changedBlockSpriteEvent?.Invoke(this, changeBlockSpriteArgs); }
void OnChangeBlockSprite(object sender, ChangeBlockSpriteArgs e) { if (e.Sprite == null) { tileMap.SetTile(e.Position, null); return; } if (!gridTiles.ContainsKey(e.Sprite)) { var gridTile = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>(); gridTile.sprite = e.Sprite; gridTiles[e.Sprite] = gridTile; } tileMap.SetTile(e.Position, gridTiles[e.Sprite]); }
void ChangeDestroyNeighborBlockSprite() { if (HasBlock) { return; } byte neighborDirMask = 0x7F; foreach (var neighborTile in neighborTiles) { if (neighborTile?.block != null) { neighborTile.block.Mask &= neighborDirMask; var e = new ChangeBlockSpriteArgs(neighborTile.Vector3Int, neighborTile.block.CurrentSprite); changedBlockSpriteEvent?.Invoke(this, e); } neighborDirMask >>= 1; neighborDirMask |= 0x80; } }
void ChangeCreateNeighborBlockSprite() { if (!HasBlock) { return; } byte neighborMask = 0x01; foreach (var neighborTile in neighborTiles) { if (neighborTile?.block?.BlockInfo.Name == block.BlockInfo.Name) { if (!block.BlockInfo.TileSet.OnlyCross || (block.BlockInfo.TileSet.OnlyCross && crossNeighborTiles.Contains(neighborTile))) { neighborTile.block.Mask |= neighborMask; var e = new ChangeBlockSpriteArgs(neighborTile.Vector3Int, neighborTile.block.CurrentSprite); changedBlockSpriteEvent?.Invoke(this, e); } } neighborMask <<= 1; } }