public SaveFile(int _gold, UnitData _fish, List <UnitData> _units, List <UnitData> _enemies, List <TotemData> _totems, float _totemPastCoolTime, List <ArtifactData> _artifacts, List <InventoryData> _inventoryDatas, StageData _stageData, List <QuestData> _questDatas, ArtifactSelectData _artifactSelectData) { gold = _gold; stageData = _stageData; fish = _fish; units = _units; enemies = _enemies; totems = _totems; totemPastCoolTime = _totemPastCoolTime; artifacts = _artifacts; inventoryDatas = _inventoryDatas; questDatas = _questDatas; artifactSelectData = _artifactSelectData; }
public void Save() { //Time.timeScale = 0f; try { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/MRDsaveInf.bin"; FileStream stream = new FileStream(path, FileMode.Create); // 골드 정보 int gold = Database.Instance.gold; // 유닛과 적군들 정보 UnitData fish = new UnitData(Heart.Instance.character); List <UnitData> units = new List <UnitData>(); List <UnitData> enemies = new List <UnitData>(); foreach (var character in UnitPool.Instance.GetActiveCharacters()) { if (character.characterInfo.unitName != UnitName.unit_fish && character.characterInfo.currentHP > 0) { units.Add(new UnitData(character)); } } foreach (var character in EnemyPool.Instance.GetActiveCharacters()) { if (character.characterInfo.currentHP > 0) { enemies.Add(new UnitData(character)); } } // 토템배치 쿨타임 정보 float pastTotemCoolTime = TotemManager.Instance.pastTime; // 배치된 토템들 정보 List <TotemData> totems = new List <TotemData>(); var placementedTotems = TotemManager.Instance.totems; foreach (var totem in placementedTotems) { if (totem.gameObject.activeInHierarchy) { totems.Add(new TotemData(totem.totemDataset.totemName, totem.totemDataset.pastingTime, totem.transform.position, totem.totemDataset.buff.amount)); } } // 유물 정보들 List <ArtifactData> artifacts = new List <ArtifactData>(); var havingArtifacts = ArtifactManager.Instance.artifactList; foreach (var artifact in havingArtifacts) { artifacts.Add(new ArtifactData(artifact.type, artifact.name)); } // 인벤토리 정보 List <InventoryData> inventoryDatas = new List <InventoryData>(); var havingInventoryItem = Slot.Instance.viewList.Keys; foreach (var item in havingInventoryItem) { inventoryDatas.Add(new InventoryData(item)); } // 스테이지 정보 StageData stageData = new StageData(); stageData.stage = InfiniteSpawnManager.Instance.stage; stageData.currentSpawnCount = InfiniteSpawnManager.Instance.currentSpawnCount; stageData.currentWaveCount = InfiniteSpawnManager.Instance.currentWaveCount; // 퀘스트정보 List <QuestData> questDatas = new List <QuestData>(); foreach (var quest in QuestEventManager.Instance.quests) { questDatas.Add(new QuestData(quest)); } // 유물 선택중인지 저장 var artifactSelectingData = new ArtifactSelectData(ArtifactSelect.Instance.isSelecting, ArtifactSelect.Instance.artifact); SaveFile saveFile = new SaveFile(gold, fish, units, enemies, totems, pastTotemCoolTime, artifacts, inventoryDatas, stageData, questDatas, artifactSelectingData); formatter.Serialize(stream, saveFile); stream.Close(); } catch (Exception e) { Debug.Log(e.Message); } }