์„ธ์ด๋ธŒ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ ํ•ด๋‹น ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.


ArgumentException: JSON parse error: The document root must not follow by other values


์ •ํ™•ํ•œ ์˜ค๋ฅ˜๋Š” ์œ— ์ค„๊ณผ ๊ฐ™์œผ๋ฉฐ ์ฆ์ƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.


์”ฌ ์ด๋™ํ•˜๋ฉด์„œ ์ €์žฅํ•˜๊ณ  ๋ถˆ๋Ÿฌ์˜ด (์ด ๋•Œ A, B ๋ผ๋Š” ์”ฌ์ด ์žˆ์œผ๋ฉด B->A ๋งŒ ๋ฌธ์ œ๊ฐ€ ์ƒ๊น€) -> ์„ธ์ด๋ธŒ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค์ง€ ๋ชปํ•จ

-> ์ด๊ฑธ ์ €์žฅํ•˜๋ฉด ์„ธ์ด๋ธŒ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ธ€์ž ํ•˜๋‚˜ ์—†์ด ๋‹ค ๋‚ ์•„๊ฐ€๋ฉฐ

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

ํ•ด๋‹น ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋กœ๋“œ ์Šคํฌ๋ฆฝํŠธ ์ชฝ์—์„œ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.


์„ธ์ด๋ธŒ๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋Š” ์›๋ž˜ A ์”ฌ์— ์žˆ์œผ๋ฉฐ DontDestroyOnLoad ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ A -> B ์”ฌ์œผ๋กœ ๋„˜์–ด๊ฐˆ ๋•Œ ํŒŒ๊ดด๋˜์ง€ ์•Š์œผ๋ฉฐ, B -> A๋กœ ๋„˜์–ด๊ฐˆ ๋• ํ•˜๋‚˜์”ฉ ๋Š˜์–ด๋‚˜๊ธธ๋ž˜ ์ด ๋•Œ Destroyํ•˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ํ•ด๋‹น ์Šคํฌ๋ฆฝํŠธ๋Š” 1๊ฐœ๋ฅผ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.


ํŠน์ดํ•œ ์ ์œผ๋กœ๋Š” ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋กœ๋Š” A <-> B๋ฅผ ์•„์ฃผ ๋น ๋ฅด๊ฒŒ ์ด๋™ํ•ด๋„ ์ด์ƒ์ด ์—†์œผ๋‚˜, A ์”ฌ์—์„œ ๋ณ€ํ™”๊ฐ€ ์žˆ์„ ๋•Œ๋งŒ B -> A์—์„œ ์ œ๋ชฉ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.


์˜ˆ์ƒ๋˜๋Š” ์›์ธ์œผ๋กœ๋Š” ์„ธ์ด๋ธŒ์™€ ๋กœ๋“œ๋ฅผ ๋งค์šฐ ์งง์€ ๊ฐ„๊ฒฉ์œผ๋กœ ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค๋งŒ, ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.


์›์ธ์„ ์•„๋Š” ๋ถ„์€ ๋Œ“๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.



public static class SaveSystem { public static void SavePlayer (DiceDirector diceDirector) { string path = Application.persistentDataPath + "/savedata.json"; if(File.Exists(path)) File.Delete(path); using (FileStream stream = File.Create(path)) { SaveData data = new SaveData(diceDirector); AddText(stream, JsonUtility.ToJson(data, true)); } } public static SaveData LoadPlayer() { string path = Application.persistentDataPath + "/savedata.json"; if (File.Exists(path)) { using (FileStream stream = File.OpenRead(path)) { StringBuilder json = new StringBuilder(""); byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (stream.Read(b,0,b.Length) > 0) { json.Append(temp.GetString(b)); } SaveData data = JsonUtility.FromJson<SaveData>(json.ToString()); // ์˜ค๋ฅ˜ ๋ฐœ์ƒ ์ง€์ ์ž…๋‹ˆ๋‹ค. //Debug.Log(path); return data; } } else { Debug.LogError("Save file not found in " + path); return null; } } private static void AddText(FileStream fs, string value) { byte[] info = new UTF8Encoding(true).GetBytes(value); fs.Write(info, 0, info.Length); } }


์—ฌ๊ธฐ์„œ DiceDirector๊ฐ€ DontDestroyOnLoad ์ ์šฉ๋œ ์„ธ์ด๋ธŒ ๋‹ด๋‹น ์Šคํฌ๋ฆฝํŠธ์ž…๋‹ˆ๋‹ค.


์•„๋ž˜๋Š” ์„ธ์ด๋ธŒ ๋ฐ์ดํ„ฐ์ž…๋‹ˆ๋‹ค. "1,2,3,4,5,6" ์ด๋Ÿฐ ์‹์œผ๋กœ ๋˜์–ด์žˆ๋Š” ๊ฑด ๋ฐฐ์—ด์„ string์œผ๋กœ ๋ณ€ํ™˜ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

{

"fieldDicesLevelForSave": "3,2,2",

"dicePosForSave": "(-0.2, 2.1),(0.2, -2.1),(0.3, 1.5)",

"dicesAppearInRoll": "1,2,3,4,5,6",

"dicesAmountInHand": 15,

"maxDicesAmountInHand": 100,

"dicesAmountInField": 3,

"maxDicesAmountInField": 100,

"diceRollCoolDown": 0.8342360258102417,

"maxDiceRollCoolDown": 1.0,

"diceLayer": 7,

"totalDicesAmount": 8,

"boardType": "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,102,104,104,112,105,108,106,106,111,109,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,111,0,0,0,0,0,0,108,0,0,0,0,0,0,0,0,111,0,0,0,0,0,0,106,0,0,0,0,0,0,0,0,106,0,0,0,0,0,0,104,0,0,0,0,0,0,0,0,108,0,0,0,0,0,0,109,0,0,0,0,0,0,0,0,105,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,104,0,0,0,0,0,0,104,0,0,0,0,0,0,0,0,107,0,0,0,0,0,0,108,0,0,0,0,0,0,0,0,105,0,0,0,0,0,0,106,104,104,112,108,104,106,104,106,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",

"boardNumber": 1,

"boardLevel": 0

}





์˜ค๋ฅ˜ ๋ฐœ์ƒ ์‹œ ๋กœ๊ทธ์—์„œ ๋‚˜์˜จ ์„ธ์ด๋ธŒ ๋ฐ์ดํ„ฐ์ž…๋‹ˆ๋‹ค.


{

ย  ย  "fieldDicesLevelForSave": "1,1",

ย  ย  "dicePosForSave": "(-0.5, 0.9),(-0.8, -0.2)",

ย  ย  "dicesAppearInRoll": "1,2,3,4,5,6",

ย  ย  "dicesAmountInHand": 25,

ย  ย  "maxDicesAmountInHand": 100,

ย  ย  "dicesAmountInField": 2,

ย  ย  "maxDicesAmountInField": 100,

ย  ย  "diceRollCoolDown": 0.14612144231796266,

ย  ย  "maxDiceRollCoolDown": 1.0,

ย  ย  "diceLayer": 2,

ย  ย  "totalDicesAmount": 2,

ย  ย  "boardType": "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,102,106,109,104,109,109,112,111,104,111,0,0,0,0,0,0,110,0,0,0,0,0,0,0,0,108,0,0,0,0,0,0,112,0,0,0,0,0,0,0,0,108,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,104,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,112,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,104,0,0,0,0,0,0,110,0,0,0,0,0,0,0,0,109,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,109,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,104,0,0,0,0,0,0,109,106,108,109,110,106,106,108,104,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",

ย  ย  "boardNumber": 1,

ย  ย  "boardLevel": 0

}

ย  ย  "fieldDicesLevelForSave": "1,1",

ย  ย  "dicePosForSave": "(-0.5, 0.9),(-0.8, -0.2)",

ย  ย  "dicesAppearInRoll": "1,2,3,4,5,6",

ย  ย  "dicesAmountInHand": 25,

ย  ย  "maxDicesAmountInHand": 100,

ย  ย  "dicesAmountInField": 2,

ย  ย  "maxDicesAmountInField": 100,

ย  ย  "diceRollCoolDown": 0.14612144231796266,

ย  ย  "maxDiceRollCoolDown": 1.0,

ย  ย  "diceLayer": 2,

ย  ย  "totalDicesAmount": 2,

ย  ย  "boardType": "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,102,106,109,104,109,109,112,111,104,111,0,0,0,0,0,0,110,0,0,0,0,0,0,0,0,108,0,0,0,0,0,0,112,0,0,0,0,0,0,0,0,108,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,104,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,112,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,104,0,0,0,0,0,0,110,0,0,0,0,0,0,0,0,109,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,109,0,0,0,0,0,0,111,0,0,0,0,0,0,0,0,104,0,0,0,0,0,0,109,106,108,109,110,106,106,108,104,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",

ย  ย  "boardNumber": 1,

ย  ย  "boardLevel": 0


๋‘ ๋ฒˆ์งธ ๊บผ๊ฐ€ ์ค‘๊ด„ํ˜ธ๋„ ์—†์ด ์ถœ๋ ฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.