示例#1
0
        public void LoadLayer(Layer layer)
        {
            ChangeSortingOrder(layer.SortingOrder);
            ChangeCollisionLayer(layer.CollisionLayer);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Tile myTile   = GetTile(x, y);
                    Tile copyTile = layer.GetTile(x, y);

                    if (copyTile.TileAssetName == null)
                    {
                        continue;
                    }

                    myTile.Flip(copyTile.Flipped);
                    TileAsset asset = Resources.Load <TileAsset> ($@"TileAssets\LevelSet1\{copyTile.TileAssetName}");
                    myTile.ChangeTileAsset(asset);

                    if (copyTile.UseManualSprite)
                    {
                        myTile.ChangeManualSprite(((SpriteTileAsset)myTile.TileAsset).RuleSprites.First(s => s.name == copyTile.ManualSpriteName));
                    }
                }
            }
        }
示例#2
0
        public void ChangeTileAsset(TileAsset asset)
        {
            TileAsset     = asset;
            TileAssetName = TileAsset.name;

            UpdateNeighbourTiles();

            TileAsset.Initialize(this);
        }
示例#3
0
 public void Initialize(TileAsset asset)
 {
     TileAsset    = asset;
     image.sprite = TileAsset.PreviewSprite;
 }
示例#4
0
        /// <summary>
        /// Refreshes the graphic. Only gets called if the TileAsset is a SpriteTileAsset.
        /// </summary>
        public void RefreshGraphic()
        {
            if (TileAsset == null)
            {
                return;
            }
            if (TileAsset is SpriteTileAsset == false)
            {
                return;
            }

            SpriteTileAsset tileAsset = (SpriteTileAsset)TileAsset;

            if (UseManualSprite)
            {
                SpriteRenderer.sprite = tileAsset.RuleSprites.First(s => s.name == ManualSpriteName);
                return;
            }

            string spriteName = $"{TileAsset.name}_";

            Tile t = Layer.GetTile(X, Y + 1);

            if (t != null && t.TileAsset != null && t.TileAsset.name == TileAsset.name && tileAsset.IgnoreVerticalTiles == false)
            {
                spriteName += "U";
            }

            t = Layer.GetTile(X + 1, Y);
            if (t != null && t.TileAsset != null && t.TileAsset.name == TileAsset.name && tileAsset.IgnoreHorizontalTiles == false)
            {
                spriteName += "R";
            }

            t = Layer.GetTile(X, Y - 1);
            if (t != null && t.TileAsset != null && t.TileAsset.name == TileAsset.name && tileAsset.IgnoreVerticalTiles == false)
            {
                spriteName += "D";
            }

            t = Layer.GetTile(X - 1, Y);
            if (t != null && t.TileAsset != null && t.TileAsset.name == TileAsset.name && tileAsset.IgnoreHorizontalTiles == false)
            {
                spriteName += "L";
            }

            if (Flipped)
            {
                spriteName += "F";
            }

            Sprite sprite = tileAsset.RuleSprites.FirstOrDefault(s => s.name == spriteName);

            if (sprite == null)
            {
                sprite = tileAsset.DefaultSprite;
            }

            SpriteRenderer.sprite = sprite;

            TileAsset.Initialize(this);
        }