오보에블로그

[Unity] Json 파일 읽어오기 본문

GameEngine & CG/Unity

[Unity] Json 파일 읽어오기

(OBO) 2021. 8. 16. 18:09
728x90

 

아래의 코드와 같이 미리 구현해놓은 클래스에 매핑시킬수 있다.

 

[Serializable]
public class Stat
{
    public int level;
    public int hp;
    public int attack;

}


[Serializable]
public class StatData
{
    public List<Stat> stats = new List<Stat>();
}

public class DataManager
{
    public void Init()
    {
        TextAsset textAsset = Managers.Resource.Load<TextAsset>($"Data/StatData");
        StatData data = JsonUtility.FromJson<StatData>(textAsset.text);
    }
}

 

 

 

728x90

'GameEngine & CG > Unity' 카테고리의 다른 글

[Unity][Git] 유니티 프로젝트 추가시 .gitignore 수정  (0) 2021.11.13
[Unity]Cursor  (0) 2021.09.17
[Unity] Render Mode  (0) 2021.08.16
[Unity] UI Event Handler 만들기  (0) 2021.08.10
[Unity] IPointerClickHandler & IDragHandler  (0) 2021.08.10