From 0675266fac2d1b9b1af9b89b5830bc7efedfed21 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 19 Feb 2025 02:24:48 -0800 Subject: Fix upload Scripts must be wrapped in `#if UNITY_EDITOR` or build shits the bed. Also document config structs. --- YOTSNDMFGenerator.cs | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'YOTSNDMFGenerator.cs') diff --git a/YOTSNDMFGenerator.cs b/YOTSNDMFGenerator.cs index d8dba78..e6e0585 100644 --- a/YOTSNDMFGenerator.cs +++ b/YOTSNDMFGenerator.cs @@ -1,7 +1,10 @@ +#if UNITY_EDITOR + using UnityEngine; using nadena.dev.ndmf; -using nadena.dev.ndmf.VRChat; +using nadena.dev.ndmf.builtin; using nadena.dev.ndmf.localization; +using nadena.dev.ndmf.VRChat; using VRC.SDK3.Avatars.ScriptableObjects; using UnityEditor; using System; @@ -22,13 +25,31 @@ namespace YOTS protected override void Configure() { - // Use a different pass name in play mode to indicate temporary processing. + // First pass: Store config data + InPhase(BuildPhase.Resolving) + .Run("Cache YOTS Config", ctx => { + var config = ctx.AvatarRootObject.GetComponentInChildren(); + if (config == null || config.jsonConfig == null) { + ErrorReport.ReportError(localizer, ErrorSeverity.Error, "yots.error.no_config", + "No YOTS config found on the avatar."); + return; + } + ctx.GetState().jsonConfig = config.jsonConfig.text; + }) + // Shoutsout anatawa12/AvatarOptimizer + .BeforePass(RemoveEditorOnlyPass.Instance); + + // Second pass: Generate animator InPhase(BuildPhase.Transforming) .Run("Generate YOTS Animator", ctx => { - // ctx is a BuildContext - // https://ndmf.nadena.dev/api/nadena.dev.ndmf.BuildContext.html + var state = ctx.GetState(); + if (string.IsNullOrEmpty(state.jsonConfig)) { + ErrorReport.ReportError(localizer, ErrorSeverity.Error, "yots.error.no_config", + "No YOTS config found on the avatar."); + return; + } // Get config - var config = ctx.AvatarRootObject.GetComponentInChildren(); + var config = ctx.GetState(); if (config == null) { ErrorReport.ReportError(localizer, ErrorSeverity.Error, "yots.error.no_config", "No YOTS config component found on the avatar."); @@ -65,7 +86,7 @@ namespace YOTS descriptor.expressionsMenu = menu; descriptor.expressionParameters = parameters; RuntimeAnimatorController generatedAnimator = YOTSCore.GenerateAnimator( - config.jsonConfig.text, + state.jsonConfig, parameters, menu ); @@ -79,5 +100,12 @@ namespace YOTS } ); } + + private class YOTSBuildState + { + public string jsonConfig; + } } } + +#endif // UNITY_EDITOR -- cgit v1.2.3