From 7ed0179b915bb16d5177a7042f4dc85ad22429f1 Mon Sep 17 00:00:00 2001 From: bd_ Date: Wed, 20 Sep 2023 18:49:20 +0900 Subject: [PATCH] fix: null/missing expressions params/menus breaking builds (#441) --- .../FixupPasses/FixupExpressionsMenuPass.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Packages/nadena.dev.modular-avatar/Editor/FixupPasses/FixupExpressionsMenuPass.cs b/Packages/nadena.dev.modular-avatar/Editor/FixupPasses/FixupExpressionsMenuPass.cs index 29d0fae0..d18ebc13 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/FixupPasses/FixupExpressionsMenuPass.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/FixupPasses/FixupExpressionsMenuPass.cs @@ -6,17 +6,40 @@ using UnityEngine; using UnityEngine.Experimental.Rendering; using VRC.SDK3.Avatars.ScriptableObjects; +using Object = UnityEngine.Object; namespace nadena.dev.modular_avatar.core.editor { internal class FixupExpressionsMenuPass { + private const string DEFAULT_EXP_MENU_GUID = "024fb8ef5b3988c46b446863c92f4522"; + private const string DEFAULT_EXP_PARAM_GUID = "03a6d797deb62f0429471c4e17ea99a7"; + internal static void FixupExpressionsMenu(BuildContext context) { + context.AvatarDescriptor.customExpressions = true; + var expressionsMenu = context.AvatarDescriptor.expressionsMenu; - if (expressionsMenu == null) return; + if (expressionsMenu == null) + { + var defaultExpMenu = AssetDatabase.LoadAssetAtPath( + AssetDatabase.GUIDToAssetPath(DEFAULT_EXP_MENU_GUID) + ); + + expressionsMenu = Object.Instantiate(defaultExpMenu); + context.AvatarDescriptor.expressionsMenu = expressionsMenu; + } + + if (context.AvatarDescriptor.expressionParameters == null) + { + var defaultExpParam = AssetDatabase.LoadAssetAtPath( + AssetDatabase.GUIDToAssetPath(DEFAULT_EXP_PARAM_GUID) + ); + + context.AvatarDescriptor.expressionParameters = Object.Instantiate(defaultExpParam); + } - var parameters = context.AvatarDescriptor.expressionParameters?.parameters + var parameters = context.AvatarDescriptor.expressionParameters.parameters ?? new VRCExpressionParameters.Parameter[0]; var parameterNames = parameters.Select(p=> p.name).ToImmutableHashSet();