Notice
Recent Posts
Recent Comments
Link
스토리지
[3.25] 수정중인 코드 본문
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
namespace Study11
{
public class DataManager<T>
{
private static DataManager<T> instance;
public Dictionary<int, T> dicData;
private DataManager()
{
this.dicData = new Dictionary<int, T>();
}
public static DataManager<T> GetInstance()
{
if (DataManager<T>.instance == null)
{
DataManager<T>.instance = new DataManager<T>();
}
return DataManager<T>.instance;
}
public void LoadData(string path)
{
var json = File.ReadAllText(path);
var arr = JsonConvert.DeserializeObject<T[]>(json);
foreach(var item in arr)
{
string[] temp = item.ToString().Split(' ');
int key = Convert.ToInt32(temp[0]);
this.dicData.Add(key, item);
}
}
public void PrintData()
{
Console.WriteLine("Data Num : {0}\n", dicData.Count);
foreach(var item in dicData)
{
Console.WriteLine(item.Value);
}
Console.WriteLine();
}
}
}
딕셔너리가 두개가 아니라서 자꾸 충돌이 발생한다...
'Unity > 문제해결' 카테고리의 다른 글
[4.18] 게임오브젝트에 중력이 제대로 적용이 안되는 문제 (해결) (0) | 2021.04.18 |
---|---|
(문제) 씬에서 보이던게 게임뷰에서 안보이는 문제 (0) | 2021.04.13 |
json으로 직렬화할 때 문제점 (0) | 2021.03.26 |
객체를 출력할 때 하나하나 멤버를 안 호출하고 객체를 출력하기 (0) | 2021.03.16 |
while문, switch문 중첩 시, break가 while을 종료하는 법 (0) | 2021.03.10 |
Comments