From 00054c1a525bd21674a731da85ee9dceeac46115 Mon Sep 17 00:00:00 2001 From: Narazaka Date: Mon, 10 Apr 2023 20:18:59 +0900 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8B=95=E7=94=9F=E6=88=90=E3=81=AA?= =?UTF-8?q?=E3=81=A9=E3=81=A7subParameters=E3=81=8Cnull=E3=81=AE=E3=83=A1?= =?UTF-8?q?=E3=83=8B=E3=83=A5=E3=83=BC=E3=82=A2=E3=82=BB=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=97=E3=81=9F=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AB=E3=82=A8=E3=83=A9=E3=82=8B=E3=81=AE=E3=82=92=E5=9B=9E?= =?UTF-8?q?=E9=81=BF=20(#263)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 自動生成などでsubParametersがnullのメニューアセットを指定した場合にエラるのを回避 * chore: add test for null subparameter field issue --------- Co-authored-by: bd_ --- .../EditModeTests/NullSubparameterTest.cs | 24 +++++++++++++++++++ .../NullSubparameterTest.cs.meta | 3 +++ .../Editor/ParameterPolicy.cs | 11 +++++---- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs create mode 100644 Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs.meta diff --git a/Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs b/Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs new file mode 100644 index 00000000..50cd97e9 --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs @@ -0,0 +1,24 @@ +using nadena.dev.modular_avatar.core.editor; +using NUnit.Framework; +using UnityEngine; +using VRC.SDK3.Avatars.Components; +using VRC.SDK3.Avatars.ScriptableObjects; + +namespace modular_avatar_tests +{ + public class NullSubparameterTest : TestBase + { + [Test] + public void TestNullSubparametersField() + { + VRCExpressionsMenu menu = ScriptableObject.CreateInstance(); + var root = CreateRoot("root"); + + var avatar = root.GetComponent(); + avatar.expressionsMenu = menu; + + // This should not throw an exception + ParameterPolicy.ProbeParameters(root); + } + } +} \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs.meta b/Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs.meta new file mode 100644 index 00000000..19a7d2c3 --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/NullSubparameterTest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: af0baf421bd9450d974871db9d25c2c4 +timeCreated: 1681041544 \ No newline at end of file diff --git a/Packages/nadena.dev.modular-avatar/Editor/ParameterPolicy.cs b/Packages/nadena.dev.modular-avatar/Editor/ParameterPolicy.cs index 57045db8..6e80883d 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/ParameterPolicy.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/ParameterPolicy.cs @@ -171,11 +171,14 @@ namespace nadena.dev.modular_avatar.core.editor AddParam(control.parameter.name); } - foreach (var subParam in control.subParameters) + if (control.subParameters != null) { - if (!string.IsNullOrWhiteSpace(subParam.name)) + foreach (var subParam in control.subParameters) { - AddParam(subParam.name); + if (!string.IsNullOrWhiteSpace(subParam.name)) + { + AddParam(subParam.name); + } } } @@ -314,4 +317,4 @@ namespace nadena.dev.modular_avatar.core.editor parameters = newParams; } } -} \ No newline at end of file +}