Ejemplo n.º 1
0
 public LDtkNativePrefabAssets(LDtkProjectImporter importer, LDtkArtifactAssets assets, string path)
 {
     _importer   = importer;
     _path       = path;
     _assets     = assets;
     _oldSprite  = LDtkResourcesLoader.LoadDefaultTileSprite();
     _newTexture = Texture2D.whiteTexture;
 }
Ejemplo n.º 2
0
        private LDtkIntGridTile TryGetIntGridTile(string intGridValueKey)
        {
            LDtkIntGridTile intGridTile = Importer.GetIntGridValueTile(intGridValueKey);

            if (intGridTile == null)
            {
                intGridTile = LDtkResourcesLoader.LoadDefaultTile();
            }

            return(intGridTile);
        }
        public void BuildIntGridValues()
        {
            RoundTilemapPos();

            SortingOrder.Next();

            GameObject tilemapGameObject = LayerGameObject.CreateChildGameObject(Layer.Type);

            /*if (Importer.DeparentInRuntime)
             * {
             *  tilemapGameObject.AddComponent<LDtkDetachChildren>();
             * }*/

            Tilemap = tilemapGameObject.AddComponent <Tilemap>();


            if (Importer.IntGridValueColorsVisible)
            {
                TilemapRenderer renderer = tilemapGameObject.AddComponent <TilemapRenderer>();
                renderer.sortingOrder = SortingOrder.SortingOrderValue;
            }

            TilemapCollider2D collider = tilemapGameObject.AddComponent <TilemapCollider2D>();

            int[] intGridValues = Layer.IntGridCsv.Select(p => (int)p).ToArray();

            for (int i = 0; i < intGridValues.Length; i++)
            {
                int intGridValue = intGridValues[i];

                //all empty intgrid values are 0
                if (intGridValue == 0)
                {
                    continue;
                }

                LayerDefinition        intGridDef      = Layer.Definition;
                IntGridValueDefinition intGridValueDef = intGridDef.IntGridValues[intGridValue - 1];

                string          intGridValueKey = LDtkKeyFormatUtil.IntGridValueFormat(intGridDef, intGridValueDef);
                LDtkIntGridTile intGridTile     = Importer.GetIntGridValueTile(intGridValueKey);

                if (intGridTile == null)
                {
                    intGridTile = LDtkResourcesLoader.LoadDefaultTile();
                }

                BuildIntGridValue(intGridValueDef, i, intGridTile);
            }

            Tilemap.SetOpacity(Layer);
        }
Ejemplo n.º 4
0
        private void MainAssetGeneration()
        {
            LDtkIntGridTile oldDefaultTile = LDtkResourcesLoader.LoadDefaultTile();
            Tile            newDefaultTile = CreateNativeTile(oldDefaultTile);

            //export default texture
            Texture2D newDefaultTexture = CloneArtifact(_newTexture, "/Sprites", _oldSprite.name + "Texture");

            //export the default sprite
            Sprite newDefaultSprite = Sprite.Create(newDefaultTexture, _oldSprite.rect, GetNormalizedPivotOfSprite(_oldSprite), _oldSprite.pixelsPerUnit, 1, SpriteMeshType.Tight, _oldSprite.border, true);

            newDefaultSprite = CloneArtifact(newDefaultSprite, "/Sprites", _oldSprite.name);

            //clone art tile sprites
            _artTileSprites = CloneArtifacts(_assets.SpriteArtifacts, "/Sprites");

            //clone art tiles
            _artTiles = CloneArtifacts(_assets.TileArtifacts, "/ArtTiles").Cast <Tile>().ToList();

            //clone int grid tiles
            List <TileBase> oldIntGridArtifacts = _importer.GetIntGridTiles().Where(p => p != null).Append(newDefaultTile).ToList();

            _intGridTiles = CloneArtifacts(oldIntGridArtifacts, "/IntGridValues").Cast <Tile>().ToList();

            //clone background sprites
            _backgroundArtifacts = CloneArtifacts(_assets.BackgroundArtifacts, "/Backgrounds");

            EditorApplication.delayCall += TryCloneSpriteAtlas;

            //give each new native art tile a matching cloned sprite to reference
            foreach (Tile artTile in _artTiles)
            {
                string nameMatch        = artTile.name;
                Sprite oldArtTileSprite = _artTileSprites.Find(sprite => sprite.name == nameMatch);
                artTile.sprite = oldArtTileSprite;
            }

            //give the int grid tiles the clone sprite instead if they were using the default tile
            foreach (Tile intGridTile in _intGridTiles)
            {
                if (intGridTile.sprite == _oldSprite)
                {
                    intGridTile.sprite = newDefaultSprite;
                }
            }

            //we've generated the default sprite which is used by multiple, simply add to the list since it's already created
            _backgroundArtifacts.Add(newDefaultSprite);
        }
Ejemplo n.º 5
0
        private void TryBuildSimpleBgColor()
        {
            if (!_importer.CreateBackgroundColor)
            {
                return;
            }

            SpriteRenderer renderer = CreateGameObject("_BgColor");

            renderer.sprite = LDtkResourcesLoader.LoadDefaultTileSprite();
            renderer.color  = _level.UnityBgColor;

            _layerSortingOrder.Next();
            renderer.sortingOrder = _layerSortingOrder.SortingOrderValue;

            ManipulateColorTransform(renderer.transform);
        }