summaryrefslogtreecommitdiffstats
path: root/YOTSNDMFGenerator.cs
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-02-19 02:24:48 -0800
committeryum <yum.food.vr@gmail.com>2025-02-19 02:24:48 -0800
commit0675266fac2d1b9b1af9b89b5830bc7efedfed21 (patch)
treebe94c1665757f53f0becf4a7fa9ab078d08e911a /YOTSNDMFGenerator.cs
parent6b5018777d9cc7c362fafa3c673659770a6a5bca (diff)
Fix upload
Scripts must be wrapped in `#if UNITY_EDITOR` or build shits the bed. Also document config structs.
Diffstat (limited to 'YOTSNDMFGenerator.cs')
-rw-r--r--YOTSNDMFGenerator.cs40
1 files changed, 34 insertions, 6 deletions
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<YOTSNDMFConfig>();
+ 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<YOTSBuildState>().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<YOTSBuildState>();
+ 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<YOTSNDMFConfig>();
+ var config = ctx.GetState<YOTSBuildState>();
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