質問編集履歴
1
Resourcesフォルダを使う場合とWWWを使う場合の比較を追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -96,6 +96,61 @@
|
|
96
96
|
|
97
97
|
MiniJSONで取得する方法も試してみましたがうまくいきませんでした。
|
98
98
|
|
99
|
+
【2020/2/28 追記】
|
100
|
+
Resources内のjsonファイルの場合はJsonNodeを用いて情報を取得することができます。Resourcesを使う場合とWWWを使う場合で何か異なる処理が必要になるのでしょうか?
|
101
|
+
|
102
|
+
```C#
|
103
|
+
using System.Collections;
|
104
|
+
using System.Collections.Generic;
|
105
|
+
using UnityEngine;
|
106
|
+
|
107
|
+
public class SampleClass : MonoBehaviour
|
108
|
+
{
|
109
|
+
void Start()
|
110
|
+
{
|
111
|
+
//Resourcesフォルダ内のjsonを読み込む場合
|
112
|
+
LoadSample1();
|
113
|
+
//WWWクラスで任意のフォルダ内のjsonを読み込む場合
|
114
|
+
LoadSample2();
|
115
|
+
}
|
116
|
+
|
117
|
+
void LoadSample1()
|
118
|
+
{
|
119
|
+
Debug.Log("Resourcesフォルダ内のjsonを読み込む場合");
|
120
|
+
|
121
|
+
string jsontext = Resources.Load<TextAsset>("Sample/Notes").ToString();
|
122
|
+
Debug.Log(jsontext);
|
123
|
+
|
124
|
+
JsonNode json = JsonNode.Parse(jsontext);
|
125
|
+
Debug.Log(json);
|
126
|
+
|
127
|
+
string title = json["name"].Get<string>();
|
128
|
+
Debug.Log("タイトル:" + title);
|
129
|
+
int bpm = (int)json["BPM"].Get<long>();
|
130
|
+
Debug.Log("BPM:" + bpm);
|
131
|
+
}
|
132
|
+
|
133
|
+
void LoadSample2()
|
134
|
+
{
|
135
|
+
Debug.Log("WWWクラスで任意のフォルダ内のjsonを読み込む場合");
|
136
|
+
|
137
|
+
WWW www = new WWW("file:///" + GameManager.MusicPath[0].Replace("\", "/") + "/Notes.json");
|
138
|
+
string jsontext = www.text;
|
139
|
+
Debug.Log(jsontext);
|
140
|
+
|
141
|
+
JsonNode json = JsonNode.Parse(jsontext);
|
142
|
+
Debug.Log(json);
|
143
|
+
|
144
|
+
string title = json["name"].Get<string>();
|
145
|
+
Debug.Log("タイトル:" + title);
|
146
|
+
int bpm = (int)json["BPM"].Get<long>();
|
147
|
+
Debug.Log("BPM:" + bpm);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
```
|
151
|
+
|
152
|
+

|
153
|
+
|
99
154
|
### 補足情報(FW/ツールのバージョンなど)
|
100
155
|
|
101
156
|
Unity 2019.2.18f1
|