コード例 #1
0
ファイル: Chunk.cs プロジェクト: rabiribi/OrbitII
 void ShowBlockTile(BlockBase block, Tilemap tilemap)
 {
     tilemap.SetTile(new Vector3Int(block.position.x, block.position.y, 0), block);
 }
コード例 #2
0
ファイル: Chunk.cs プロジェクト: rabiribi/OrbitII
 void HideBlockTile(BlockBase block, Tilemap tilemap)
 {
     tilemap.SetTile(new Vector3Int(block.position.x, block.position.y, 0), null);
 }
コード例 #3
0
ファイル: Chunk.cs プロジェクト: rabiribi/OrbitII
        public void fromSaveData(SaveData chunkData)
        {
            ChunkData data = (ChunkData)chunkData;

            this.childObjects = new List <IChunkObject>();
            this.frontBlocks  = new BlockBase[TILE_SIZE, TILE_SIZE];
            this.bkBlocks     = new BlockBase[TILE_SIZE, TILE_SIZE];

            this.childObjectIDs = data.childObjectIDs;
            this.frontBlockIDs  = data.frontBlockIDs;
            this.bkBlockIDs     = data.bkBlockIDs;
            this.position       = data.position.GetData();

            // 通过 ID 获得 CreatableSaveData , 然后创建Block
            for (int i = 0; i < TILE_SIZE; i++)
            {
                for (int j = 0; j < TILE_SIZE; j++)
                {
                    ID blockId = frontBlockIDs[i, j];
                    if (blockId == null)
                    {
                        continue;
                    }
                    SaveData originData = SaveManager.Instance.GetSaveData(blockId);
                    if (originData == null)
                    {
                        continue;
                    }
                    CreatableSaveData blockData = (CreatableSaveData)originData;
                    BlockBase         block     = blockData.Create <BlockBase>(blockId);
                    frontBlocks[i, j] = block;
                }
            }
            for (int i = 0; i < TILE_SIZE; i++)
            {
                for (int j = 0; j < TILE_SIZE; j++)
                {
                    ID blockId = bkBlockIDs[i, j];
                    if (blockId == null)
                    {
                        continue;
                    }
                    SaveData originData = SaveManager.Instance.GetSaveData(blockId);
                    if (originData == null)
                    {
                        continue;
                    }
                    CreatableSaveData blockData = (CreatableSaveData)originData;
                    BlockBase         block     = blockData.Create <BlockBase>(blockId);
                    bkBlocks[i, j] = block;
                }
            }
            // childObjects
            foreach (ID childID in childObjectIDs)
            {
                Debug.Log("加载ChunkObjects : " + childID.ToString());
                CreatableSaveData childData = (CreatableSaveData)SaveManager.Instance.GetSaveData(childID);
                if (childData == null)
                {
                    break;
                }
                IChunkObject child = childData.Create <IChunkObject>(childID);
                childObjects.Add(child);
            }
        }