public unit_info(unit_info other) { this.unit_name = other.unit_name; this.x = other.x; this.y = other.y; this.z = other.z; this.color = other.color; }
void StageData() { // 스토리 스테이지 데이타 StoryStageData storyStageData = new StoryStageData(); // 아이디를 입력한다. if (!int.TryParse(ifStageID.text, out storyStageData.id)) { onSaveGo.SetActive(false); Debug.LogError("아이디를 확인하세요."); return; } // 타이틀을 입력한다. storyStageData.desc = ifStageDesc.text; // 코스트를 넣는다. if (!int.TryParse(ifStageCost.text, out storyStageData.cost)) { onSaveGo.SetActive(false); Debug.LogError("코스트를 확인하세요."); return; } storyStageData.map_id = mapData.map_id; // 유닛 배열 Unit[] arrUnit = GameObject.FindObjectsOfType <Unit>(); for (int i = 0; i < arrUnit.Length; i++) { unit_info info = new unit_info(); info.unit_name = arrUnit[i].status.name; info.color = UnitColor.PaseToInt(arrUnit[i].tag.ToString()); info.x = arrUnit[i].transform.position.x; info.y = arrUnit[i].transform.position.y; info.z = 0; storyStageData.listUnitInfos.Add(info); } string path = Application.dataPath + "/Resources/Data/StoryStageData/"; string fileName = string.Format("story_stage_{0}.json", storyStageData.id); if (File.Exists(path + fileName)) { Debug.LogError("중복된 파일 명 입니다."); onSaveGo.SetActive(false); return; } string json = JsonConvert.SerializeObject(storyStageData); File.WriteAllText(path + fileName, json); onSaveGo.SetActive(false); }