Exemplo n.º 1
0
        public void fromSaveData(SaveData saveData)
        {
            ColonyData data = (ColonyData)saveData;

            Debug.Log("加载殖民地====!!");
            this.container = new Container(data.containerID);
            if (data.buildingIndexID != null)
            {
                Debug.Log("data.buildingIndexID : " + data.buildingIndexID.Count);
                foreach (var kv in data.buildingIndexID)
                {
                    SaveData originData = SaveManager.Instance.GetSaveData(kv.Value);
                    if (originData == null)
                    {
                        continue;
                    }
                    CreatableSaveData buildingData = (CreatableSaveData)originData;
                    BuildingBase      building     = buildingData.Create <BuildingBase>(kv.Value);
                    SetBuildingAtIndex(kv.Key, building);
                    if (kv.Value.Equals(data.controlCenterID))
                    {
                        controllCenter = building;
                    }
                }
            }
            Debug.Log("殖民地加载完毕====!!");
        }
Exemplo n.º 2
0
        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);
            }
        }