コード例 #1
0
ファイル: Tile.cs プロジェクト: opza/TileMapEditor
        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);
        }
コード例 #2
0
ファイル: Tile.cs プロジェクト: opza/TileMapEditor
        void ChangeDestroyBlockSprite()
        {
            if (HasBlock)
            {
                return;
            }

            var changeBlockSpriteArgs = new ChangeBlockSpriteArgs(Vector3Int, null);

            changedBlockSpriteEvent?.Invoke(this, changeBlockSpriteArgs);
        }
コード例 #3
0
        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]);
        }
コード例 #4
0
ファイル: Tile.cs プロジェクト: opza/TileMapEditor
        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;
            }
        }
コード例 #5
0
ファイル: Tile.cs プロジェクト: opza/TileMapEditor
        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;
            }
        }