From f70f9e8202ae1def2e914cb98616ef28b49d9106 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 15 Mar 2022 20:48:34 +0900 Subject: [PATCH] Add null JSON checks. --- .../Migration/MigrationVrmFirstPersonAndLookAt.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs b/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs index b42803b61..b07da8ffb 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UniGLTF; using UniGLTF.Extensions.VRMC_vrm; using UniJSON; @@ -66,19 +67,22 @@ namespace UniVRM10 // VRM1 // firstPersonBoneOffset は廃止されます。LookAt.OffsetFromHeadBone を使ってください。 // firstPersonBone は廃止されます。Head 固定です。 - MeshAnnotations = new System.Collections.Generic.List(), + MeshAnnotations = new List(), }; - if (vrm0.TryGet("meshAnnotations", out JsonNode meshAnnotations)) + if (vrm0.TryGet("meshAnnotations", out var meshAnnotationArrayNode)) { - foreach (var x in meshAnnotations.ArrayItems()) + foreach (var x in meshAnnotationArrayNode.ArrayItems()) { - var renderNodeIndex = FindRenderNodeIndexFromMeshIndex(gltf, x["mesh"].GetInt32()); + if (!x.TryGet("mesh", out var meshIndexNode)) continue; + if (!x.TryGet("firstPersonFlag", out var firstPersonFlagNode)) continue; + + var renderNodeIndex = FindRenderNodeIndexFromMeshIndex(gltf, meshIndexNode.GetInt32()); if (renderNodeIndex.HasValue) { firstPerson.MeshAnnotations.Add(new MeshAnnotation { Node = renderNodeIndex.Value, - Type = MigrateFirstPersonType(x["firstPersonFlag"]), + Type = MigrateFirstPersonType(firstPersonFlagNode), }); } }