From 67492239e8344f7a25f15a865cd0addb9b931923 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 2 Feb 2022 13:49:29 +0900 Subject: [PATCH] [1.0] Migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * meta: unknown key で throw せずに warning メッセージ表示に留める * firstPersonBoneOffset: 無くても動くように修正 * KeyNotFoundException に key.ToString を追加 --- .../UniJSON/ListTreeNode/ListTreeNodeObjectExtensions.cs | 2 +- Assets/VRM10/Runtime/Migration/MigrationVector3.cs | 9 +++++++++ .../Migration/MigrationVrmFirstPersonAndLookAt.cs | 7 +++++-- Assets/VRM10/Runtime/Migration/MigrationVrmMeta.cs | 4 +++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNodeObjectExtensions.cs b/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNodeObjectExtensions.cs index 5f884988c..8cf8078fe 100644 --- a/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNodeObjectExtensions.cs +++ b/Assets/UniGLTF/Runtime/UniJSON/ListTreeNode/ListTreeNodeObjectExtensions.cs @@ -52,7 +52,7 @@ namespace UniJSON return kv.Value; } } - throw new KeyNotFoundException(); + throw new KeyNotFoundException(key.ToString()); } public static bool ContainsKey(this JsonNode self, Utf8String key) diff --git a/Assets/VRM10/Runtime/Migration/MigrationVector3.cs b/Assets/VRM10/Runtime/Migration/MigrationVector3.cs index 385461de4..1587e300b 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVector3.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVector3.cs @@ -21,5 +21,14 @@ namespace UniVRM10 vrm0["z"].GetSingle(), }; } + + public static float[] Migrate(JsonNode parent, string key) + { + if (!parent.ContainsKey(key)) + { + return new float[] { 0, 0, 0 }; + } + return Migrate(parent[key]); + } } } diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs b/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs index adecb3871..1313adf21 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrmFirstPersonAndLookAt.cs @@ -1,8 +1,10 @@ using System; +using System.Collections.Generic; using System.Linq; using UniGLTF; using UniGLTF.Extensions.VRMC_vrm; using UniJSON; +using UnityEngine; namespace UniVRM10 { @@ -39,14 +41,15 @@ namespace UniVRM10 { // VRM1 // firstPerson に同居していた LookAt は独立します - var lookAt = new LookAt + LookAt lookAt = default; + lookAt = new LookAt { RangeMapHorizontalInner = MigrateLookAtRangeMap(vrm0["lookAtHorizontalInner"]), RangeMapHorizontalOuter = MigrateLookAtRangeMap(vrm0["lookAtHorizontalOuter"]), RangeMapVerticalDown = MigrateLookAtRangeMap(vrm0["lookAtVerticalDown"]), RangeMapVerticalUp = MigrateLookAtRangeMap(vrm0["lookAtVerticalUp"]), Type = MigrateLookAtType(vrm0["lookAtTypeName"]), - OffsetFromHeadBone = MigrateVector3.Migrate(vrm0["firstPersonBoneOffset"]), + OffsetFromHeadBone = MigrateVector3.Migrate(vrm0, "firstPersonBoneOffset"), }; var firstPerson = new FirstPerson diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrmMeta.cs b/Assets/VRM10/Runtime/Migration/MigrationVrmMeta.cs index 5756bc275..3b87c2b9b 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrmMeta.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrmMeta.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using UniJSON; +using UnityEngine; namespace UniVRM10 { @@ -152,7 +153,8 @@ namespace UniVRM10 break; default: - throw new NotImplementedException(key); + Debug.LogWarning($"[meta migration] unknown key: {key}"); + break; } // switch } // foreach