Exemplo n.º 1
0
        //public bool a = true;

        public void GenUvData(int x, int y)
        {
            int tile = (layer.chunkSize_x * y * 4) + (x * 4);

            Vector2[] tileUV     = null;
            int       atlasLayer = 0;
            Color     tileColor  = Color.white;

            bool empty = false;

            Texture       texture     = null;
            TileBehaviour currentTile = grid[x, y];

            if (currentTile != null && (currentTile.sprite != null || (currentTile is IAdvancedSprite && ((IAdvancedSprite)currentTile).GetSprite(x, y, layer) != null)))
            {
                if (grid[x, y] is IAdvancedSprite)
                {
                    texture = ((IAdvancedSprite)currentTile).GetSprite(x, y, layer).texture;
                    tileUV  = ((IAdvancedSprite)currentTile).GetSprite(x, y, layer).uv;
                    //TODO: Change when IAdvancedSprite has color
                    tileColor = Color.white;
                }
                else
                {
                    texture   = currentTile.sprite.texture;
                    tileUV    = currentTile.sprite.uv;
                    tileColor = currentTile.color;
                }

                for (int k = 0; k < layer.map.referenceAtlases.Count; k++)
                {
                    if (layer.map.referenceAtlases[k] == texture)
                    {
                        atlasLayer = k;
                    }
                }
            }
            else
            {
                tileUV = TileMap.uvDef;
                empty  = true;
            }

            for (int i = 0; i < 4; i++)
            {
                uvChanges[tile + i]    = tileUV[i];
                colorChanges[tile + i] = tileColor;


                if (!empty)
                {
                    textureLayerChanges[tile + i] = new Vector2(atlasLayer, 0);
                }
                else
                {
                    textureLayerChanges[tile + i] = new Vector2(255, 255);
                }

                //Debug.Log("Layer: " + textureLayer[tile + i] + ", uv: " + uvChanges[tile + i]);
            }
        }