using UnityEngine; using System.IO; using Newtonsoft.Json; using UnityEngine.Playables; public class DataManager : MonoBehaviour { private string filePath; void Start() { filePath = Application.persistentDataPath + "SaveFile/saveFile.json"; } public void SaveData(Object data) //์ง๋ ฌํ™”, JsonํŒŒ์ผ๋กœ ์ €์žฅ { // Serialize the data to a JSON string string jsonData = JsonConvert.SerializeObject(data); // Write the JSON string to a file File.WriteAllText(filePath, jsonData); } public T LoadData() where T : new() //์—ญ์ง๋ ฌํ™”, //T๋Š” ๋งค๊ฐœ ๋ณ€์ˆ˜๊ฐ€ ์—†๋Š” ์ƒ์„ฑ์ž๊ฐ€ ์žˆ์–ด์•ผ ํ•จ { T data; // Check if the save file exists if (File.Exists(filePath)) { // Read the JSON string from the file string jsonData = File.ReadAllText(filePath); // Deserialize the JSON string to a GameData object data = JsonConvert.DeserializeObject(jsonData); } else { // If the save file doesn't exist, create a new GameData object data = new T(); } return data; } } ๋ชจ๋“  ๋ฐ์ดํ„ฐํƒ€์ž… ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฉ”๋‹ˆ์ € ์Šคํฌ๋ฆฝํŠธ์ธ๋ฐ LoadData ์ œ๋„ค๋ฆญ์—์„œ data = new T() ๋ช…๋ น์ค„์ด ์—๋Ÿฌ๊ฐ€ ๋‚ฌ์—ˆ์Œ. ๊ทธ๋ž˜์„œ ํ˜•์‹ ์ œ์•ฝ ์กฐ๊ฑด where ๊ฑธ์—ˆ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ํ•˜๋Š”๊ฒŒ ์•„๋‹Œ๊ฐ€,,? ์ฝ”๋“œ๊ฐ€ ์•ˆ๋Œ์•„๊ฐ€๋„ค