示例#1
0
        public TiledTexture(TiledTexture tiledTexture, List <Vector2Int> tiles)
        {
            deviceResources = tiledTexture.deviceResources;
            tilesCount      = tiles.Count;
            TilesList       = new List <Vector2Int>(tiles);
            List <int> indexs = new List <int>();

            if (tilesCount == 0)
            {
                return;
            }
            //for (int i = 0; i < tilesCount; i++)
            //{
            //    TilesStatus.Add(TilesList[i], i);
            //}

            for (int i = 0; i < tilesCount; i++)
            {
                //if (tiledTexture.TilesStatus.TryGetValue(tiles[i], out int tIndex))
                //{
                //    indexs.Add(tIndex);
                //}
                //else
                //{
                //    indexs.Add(magicNumber);
                //}
                int tIndex = tiledTexture.TilesStatus[tiles[i]];
                if (tIndex != -1)
                {
                    indexs.Add(tIndex);
                }
                else
                {
                    indexs.Add(magicNumber);
                }
            }
            BlocksOffsetsData = new ComputeBuffer(deviceResources, tilesCount, 8, tiles.ToArray());
            BlocksData        = new ComputeBuffer(deviceResources, tilesCount, 1024);
            if (tiledTexture.BlocksData != null)
            {
                ComputeBuffer indicates = new ComputeBuffer(deviceResources, tilesCount, 4, indexs.ToArray());
                TTPartCopy.SetBuffer(tiledTexture.BlocksData, 0);
                TTPartCopy.SetBuffer(indicates, 1);
                TTPartCopy.SetUAVBuffer(BlocksData, 0);

                TTPartCopy.Dispatch(1, 1, tilesCount);
                indicates.Dispose();
            }
            tileRect    = new TileRect(TilesList);
            TilesStatus = new TileIndexCollection(tileRect);
            for (int i = 0; i < TilesList.Count; i++)
            {
                TilesStatus.Add(TilesList[i], i);
            }
        }
示例#2
0
        //public static TiledTexture ReplaceTiles(TiledTexture source, TiledTexture target)
        //{
        //    if (source.tilesCount != 0)
        //    {
        //        List<int> indexs = new List<int>();
        //        List<Vector2Int> ofs = new List<Vector2Int>(source.TilesList);
        //        for (int i = 0; i < source.tilesCount; i++)
        //        {
        //            indexs.Add(i);
        //        }

        //        for (int i = 0; i < target.tilesCount; i++)
        //        {
        //            if (source.TilesStatus.TryGetValue(target.TilesList[i], out int ix))
        //            {
        //                indexs[ix] = i + magicNumber;
        //                ofs[ix] = target.TilesList[i];
        //            }
        //            else
        //            {
        //                indexs.Add(i + magicNumber);
        //                ofs.Add(target.TilesList[i]);
        //            }
        //        }
        //        TiledTexture ttOut = new TiledTexture(source.deviceResources, indexs.Count);
        //        ttOut.TilesList = ofs;
        //        ttOut.TilesStatus = new Dictionary<Vector2Int, int>(ofs.Count * 3);
        //        for (int i = 0; i < ofs.Count; i++)
        //        {
        //            ttOut.TilesStatus.Add(ofs[i], i);
        //        }

        //        ttOut.BlocksData = new ComputeBuffer(source.deviceResources, indexs.Count, 1024);
        //        ttOut.BlocksOffsetsData = new ComputeBuffer(source.deviceResources, indexs.Count, 8, ofs.ToArray());

        //        ComputeBuffer tempIndexs = new ComputeBuffer(source.deviceResources, indexs.Count, 4, indexs.ToArray());
        //        TTReplace.SetBuffer(source.BlocksData, 0);
        //        TTReplace.SetBuffer(target.BlocksData, 1);
        //        TTReplace.SetBuffer(tempIndexs, 2);
        //        TTReplace.SetUAVBuffer(ttOut.BlocksData, 0);
        //        TTReplace.Dispatch(1, 1, ttOut.cd16);
        //        tempIndexs.Dispose();

        //        return ttOut;
        //    }
        //    else
        //        return new TiledTexture(target);
        //}

        public static TiledTexture ReplaceTiles(TiledTexture source, TiledTexture target, RenderTexture tempTexture)
        {
            if (source.tilesCount != 0)
            {
                tempTexture.Clear();
                source.UnzipToTexture(tempTexture);
                target.UnzipToTexture(tempTexture);
                return(new TiledTexture(tempTexture));
            }
            else
            {
                return(new TiledTexture(target));
            }
        }
示例#3
0
 public TiledTexture(TiledTexture tiledTexture)
 {
     deviceResources = tiledTexture.deviceResources;
     tileRect        = tiledTexture.tileRect;
     if (tiledTexture.BlocksData == null)
     {
         TilesList   = new List <Vector2Int>(1);
         TilesStatus = new TileIndexCollection(new TileRect());
         tilesCount  = 0;
     }
     else
     {
         tilesCount        = tiledTexture.tilesCount;
         TilesList         = new List <Vector2Int>(tiledTexture.TilesList);
         TilesStatus       = new TileIndexCollection(tiledTexture.TilesStatus);
         BlocksData        = new ComputeBuffer(tiledTexture.BlocksData);
         BlocksOffsetsData = new ComputeBuffer(tiledTexture.BlocksOffsetsData);
     }
 }