Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- python
- 문제풀이
- 시작해요 언리얼 2022
- dfs
- 프로그래밍
- Tutorial
- c++
- W3Schools
- Material
- Algorithm
- 오류
- 파이썬
- Unreal Engine 5
- Class
- Programming
- UE5
- dynamic
- Unity
- C#
- parameter
- 백준
- 기초
- String
- guide
- loop
- Basic
- github
- DP
- 재귀
- w3school
Archives
- Today
- Total
행복한 개구리
Unity GUI 21.04.22. 복습 본문
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.Linq;
public class DataManager
{
public Dictionary<int, ItemData> dicItemData;
private static DataManager instance;
public static DataManager GetInstance()
{
if(instance == null)
{
instance = new DataManager();
}
return instance;
}
public void LoadData()
{
var ta = Resources.Load<TextAsset>("Datas/item_data");
var json = ta.text;
this.dicItemData = JsonConvert.DeserializeObject<ItemData[]>(json).ToDictionary(x => x.id);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemInfo
{
public int id;
public int damage;
public ItemInfo(int id, int damage)
{
}
public ItemInfo Init(int id, int damage)
{
return new ItemInfo(id, damage);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemData
{
public int id;
public string name;
public int damage;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.IO;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
if (!File.Exists("./Assets/Resources/Datas/item_info.json"))
{
DataManager.GetInstance().LoadData();
Debug.Log("its Fine :D");
}
else if (File.Exists("./Assets/Resources/Datas/item_info.json"))
{
InfoManager.GetInstance().LoadInfo();
Debug.Log("its also Fine :D");
}
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.Linq;
public class InfoManager
{
public List<ItemInfo> listItemInfos;
public Dictionary<int, ItemInfo> dicItemInfos;
private static InfoManager instance;
public static InfoManager GetInstance()
{
if(instance == null)
{
instance = new InfoManager();
}
return instance;
}
public void LoadInfo()
{
var ta = Resources.Load<TextAsset>("Datas/item_info");
var json = ta.text;
this.dicItemInfos = JsonConvert.DeserializeObject<ItemInfo[]>(json).ToDictionary(x => x.id);
}
public void Save()
{
var itemInfo = JsonConvert.SerializeObject(this.listItemInfos);
Resources.
}
}
InfoManager에서 어떻게 해야 저장을 시킬지 잘 모르겠다.
그리고 Test가 가장 상위 객체인데 ItemInfo가 있는지 알아보는 FileExists가 당장은 오류가 나진 않았지만 저것도 맞는지는 모르겠다. (C#에선 저렇게 하는데.)
++ 검색해보니 GetFiles를 쓰라는 결과도 나오는데 역시 경로를 어떤식으로 적어야 하는지 모르겠다. C#에서는 동일한 계층의 폴더에 존재한다면 (./file_name) 이런식으로도 쓰고 그 하위 폴더면(./folder_name\file_name.json)이런식으로 사용했던 것 같은데 여기서는 \(백슬래시)를 사용하면 바로 에러가 나서 헷갈린다.
'Unity > 복습' 카테고리의 다른 글
Unity 21.04.26. 개념복습 (0) | 2021.04.26 |
---|---|
Unity 21.04.23. 데이터 불러오기 및 저장 복습 (0) | 2021.04.23 |
Unity GUI 21.04.21.복습 - 데이터 및 인벤토리 슬롯 불러오기 (0) | 2021.04.21 |
Unity 3D 21.04.15.복습 (0) | 2021.04.15 |
Unity 3D 21.04.14.복습 (0) | 2021.04.14 |