質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
ファイル

ファイルとは、文字列に基づいた名前又はパスからアクセスすることができる、任意の情報のブロック又は情報を格納するためのリソースです。

JSON

JSON(JavaScript Object Notation)は軽量なデータ記述言語の1つである。構文はJavaScriptをベースとしていますが、JavaScriptに限定されたものではなく、様々なソフトウェアやプログラミング言語間におけるデータの受け渡しが行えるように設計されています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

0回答

736閲覧

JSONファイルを上から順に読み込みたい

UJI

総合スコア0

ファイル

ファイルとは、文字列に基づいた名前又はパスからアクセスすることができる、任意の情報のブロック又は情報を格納するためのリソースです。

JSON

JSON(JavaScript Object Notation)は軽量なデータ記述言語の1つである。構文はJavaScriptをベースとしていますが、JavaScriptに限定されたものではなく、様々なソフトウェアやプログラミング言語間におけるデータの受け渡しが行えるように設計されています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2020/12/03 03:17

編集2020/12/04 04:52

今Unityを使って音楽ゲームを制作しています。
譜面のデータが記述されたJSONファイルを読み込み、
ノーツを生成することは出来たのですが、
たまにJSONファイルの後ろの方を先に読み込んで
ゲームが成り立ちません。
エラーメッセージは何も出ていません。
上から順番に読み込むにはどうしたらいいですか?

該当のソースコード

JSON

1{ 2 "maxBlock": "6", 3 "BPM": "120", 4 "offset": "0", 5 "notes": [ 6 { 7 "LPB": "16", 8 "num": "64", 9 "block": "4", 10 "type": "1", 11 "notes": [] 12 }, 13 { 14 "LPB": "16", 15 "num": "64", 16 "block": "2", 17 "type": "1", 18 "notes": [] 19 }, 20 { 21 "LPB": "16", 22 "num": "78", 23 "block": "2", 24 "type": "1", 25 "notes": [] 26 }, 27 { 28 "LPB": "16", 29 "num": "78", 30 "block": "4", 31 "type": "1", 32 "notes": [] 33 }, 34 { 35 "LPB": "16", 36 "num": "93", 37 "block": "4", 38 "type": "1", 39 "notes": [] 40 }, 41 { 42 "LPB": "16", 43 "num": "93", 44 "block": "2", 45 "type": "1", 46 "notes": [] 47 }, 48 { 49 "LPB": "16", 50 "num": "100", 51 "block": "3", 52 "type": "1", 53 "notes": [] 54 }, 55 { 56 "LPB": "16", 57 "num": "107", 58 "block": "3", 59 "type": "1", 60 "notes": [] 61 }, 62 { 63 "LPB": "16", 64 "num": "110", 65 "block": "2", 66 "type": "1", 67 "notes": [] 68 }, 69 { 70 "LPB": "16", 71 "num": "114", 72 "block": "3", 73 "type": "1", 74 "notes": [] 75 }, 76 { 77 "LPB": "16", 78 "num": "117", 79 "block": "2", 80 "type": "1", 81 "notes": [] 82 }, 83 { 84 "LPB": "16", 85 "num": "122", 86 "block": "1", 87 "type": "2", 88 "notes": [ 89 { 90 "LPB": "16", 91 "num": "137", 92 "block": "1", 93 "type": "2", 94 "notes": [] 95 } 96 ] 97 }, 98 { 99 "LPB": "16", 100 "num": "122", 101 "block": "4", 102 "type": "1", 103 "notes": [] 104 }, 105 { 106 "LPB": "16", 107 "num": "141", 108 "block": "2", 109 "type": "1", 110 "notes": [] 111 }, 112 113 { 114 "LPB": "16", 115 "num": "2005", 116 "block": "5", 117 "type": "2", 118 "notes": [ 119 { 120 "LPB": "16", 121 "num": "2012", 122 "block": "5", 123 "type": "2", 124 "notes": [] 125 } 126 ] 127 }, 128 129  (中略) 130 131 { 132 "LPB": "16", 133 "num": "2005", 134 "block": "2", 135 "type": "2", 136 "notes": [ 137 { 138 "LPB": "16", 139 "num": "2012", 140 "block": "2", 141 "type": "2", 142 "notes": [] 143 } 144 ] 145 }, 146 { 147 "LPB": "16", 148 "num": "2012", 149 "block": "4", 150 "type": "2", 151 "notes": [ 152 { 153 "LPB": "16", 154 "num": "2019", 155 "block": "4", 156 "type": "2", 157 "notes": [] 158 } 159 ] 160 }, 161 { 162 "LPB": "16", 163 "num": "2019", 164 "block": "5", 165 "type": "2", 166 "notes": [ 167 { 168 "LPB": "16", 169 "num": "2026", 170 "block": "5", 171 "type": "2", 172 "notes": [] 173 } 174 ] 175 }, 176 { 177 "LPB": "16", 178 "num": "2019", 179 "block": "3", 180 "type": "2", 181 "notes": [ 182 { 183 "LPB": "16", 184 "num": "2026", 185 "block": "3", 186 "type": "2", 187 "notes": [] 188 } 189 ] 190 }, 191 { 192 "LPB": "16", 193 "num": "2026", 194 "block": "1", 195 "type": "2", 196 "notes": [ 197 { 198 "LPB": "16", 199 "num": "2033", 200 "block": "1", 201 "type": "2", 202 "notes": [] 203 } 204 ] 205 }, 206 { 207 "LPB": "16", 208 "num": "2033", 209 "block": "2", 210 "type": "2", 211 "notes": [ 212 { 213 "LPB": "16", 214 "num": "2040", 215 "block": "2", 216 "type": "2", 217 "notes": [] 218 } 219 ] 220 }, 221 { 222 "LPB": "16", 223 "num": "2033", 224 "block": "4", 225 "type": "2", 226 "notes": [ 227 { 228 "LPB": "16", 229 "num": "2040", 230 "block": "4", 231 "type": "2", 232 "notes": [] 233 } 234 ] 235 }, 236 { 237 "LPB": "16", 238 "num": "2040", 239 "block": "3", 240 "type": "2", 241 "notes": [ 242 { 243 "LPB": "16", 244 "num": "2047", 245 "block": "3", 246 "type": "2", 247 "notes": [] 248 } 249 ] 250 }, 251 { 252 "LPB": "16", 253 "num": "2047", 254 "block": "2", 255 "type": "1", 256 "notes": [] 257 }, 258 { 259 "LPB": "16", 260 "num": "2047", 261 "block": "1", 262 "type": "1", 263 "notes": [] 264 }, 265 { 266 "LPB": "16", 267 "num": "2056", 268 "block": "1", 269 "type": "1", 270 "notes": [] 271 }, 272 { 273 "LPB": "16", 274 "num": "2056", 275 "block": "4", 276 "type": "1", 277 "notes": [] 278 }, 279 { 280 "LPB": "16", 281 "num": "2063", 282 "block": "1", 283 "type": "1", 284 "notes": [] 285 }, 286 { 287 "LPB": "16", 288 "num": "2063", 289 "block": "4", 290 "type": "1", 291 "notes": [] 292 }, 293 { 294 "LPB": "16", 295 "num": "2074", 296 "block": "4", 297 "type": "1", 298 "notes": [] 299 }, 300 { 301 "LPB": "16", 302 "num": "2074", 303 "block": "1", 304 "type": "1", 305 "notes": [] 306 }, 307 { 308 "LPB": "16", 309 "num": "2080", 310 "block": "3", 311 "type": "1", 312 "notes": [] 313 }, 314 { 315 "LPB": "16", 316 "num": "2084", 317 "block": "2", 318 "type": "1", 319 "notes": [] 320 }, 321 { 322 "LPB": "16", 323 "num": "2100", 324 "block": "1", 325 "type": "1", 326 "notes": [] 327 }, 328 { 329 "LPB": "16", 330 "num": "2100", 331 "block": "4", 332 "type": "1", 333 "notes": [] 334 }, 335 { 336 "LPB": "16", 337 "num": "2107", 338 "block": "2", 339 "type": "1", 340 "notes": [] 341 }, 342 { 343 "LPB": "16", 344 "num": "2114", 345 "block": "4", 346 "type": "1", 347 "notes": [] 348 }, 349 { 350 "LPB": "16", 351 "num": "2114", 352 "block": "1", 353 "type": "1", 354 "notes": [] 355 }, 356 { 357 "LPB": "16", 358 "num": "2121", 359 "block": "3", 360 "type": "1", 361 "notes": [] 362 }, 363 { 364 "LPB": "16", 365 "num": "2129", 366 "block": "3", 367 "type": "1", 368 "notes": [] 369 }, 370 { 371 "LPB": "16", 372 "num": "2133", 373 "block": "2", 374 "type": "1", 375 "notes": [] 376 }, 377 { 378 "LPB": "16", 379 "num": "2137", 380 "block": "3", 381 "type": "1", 382 "notes": [] 383 }, 384 { 385 "LPB": "16", 386 "num": "2141", 387 "block": "2", 388 "type": "1", 389 "notes": [] 390 }, 391 { 392 "LPB": "16", 393 "num": "2145", 394 "block": "3", 395 "type": "1", 396 "notes": [] 397 }, 398 { 399 "LPB": "16", 400 "num": "2149", 401 "block": "2", 402 "type": "1", 403 "notes": [] 404 }, 405 { 406 "LPB": "16", 407 "num": "2153", 408 "block": "3", 409 "type": "1", 410 "notes": [] 411 } 412 ] 413}

C#

1using System; 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.UI; 6 7public class scoregenerator : MonoBehaviour 8{ 9 public GameObject Tap; 10 public GameObject LongTap; 11 public GameObject long0; 12 public GameObject long1; 13 public GameObject long2; 14 public GameObject long3; 15 public GameObject long4; 16 public GameObject long5; 17 18 int bpm; 19 List<GameObject> Notes; 20 21 // Start is called before the first frame update 22 void Awake() 23 { 24 Notes = new List<GameObject>(); 25 26 string jsonText = Resources.Load<TextAsset>("yosioka1HARD").ToString(); 27 28 JsonNode json = JsonNode.Parse(jsonText); 29 bpm = int.Parse(json["BPM"].Get<string>()); 30 31 foreach(var note in json["notes"]) 32 { 33 string type = note["type"].Get<string>(); 34 float lpb = float.Parse(note["LPB"].Get<string>()); 35 float num = float.Parse(note["num"].Get<string>()); 36 int block = int.Parse(note["block"].Get<string>()); 37 38      //ノーツの生成 39 } 40 } 41

補足情報

Unity2019.3.15
JSONファイルは「NoteEditor」を使って作成

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問