From c50b3526f621c4aae32284da8aa4f752aff9a0b2 Mon Sep 17 00:00:00 2001 From: bd_ Date: Sat, 3 Aug 2024 21:05:10 -0700 Subject: [PATCH] feat: expose per-component toggles to the NDMF plugin preview UI (#941) --- .github/ProjectRoot/vpm-manifest-2022.json | 2 +- Editor/PluginDefinition/PluginDefinition.cs | 2 ++ Editor/ReactiveObjects/ObjectTogglePreview.cs | 18 +++++++++++++++++- Editor/ReactiveObjects/ShapeChangerPreview.cs | 17 +++++++++++++++++ Editor/ScaleAdjuster/ScaleAdjusterPreview.cs | 16 ++++++++++++++++ package.json | 2 +- 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/.github/ProjectRoot/vpm-manifest-2022.json b/.github/ProjectRoot/vpm-manifest-2022.json index 3d49908a..9e90164d 100644 --- a/.github/ProjectRoot/vpm-manifest-2022.json +++ b/.github/ProjectRoot/vpm-manifest-2022.json @@ -19,7 +19,7 @@ "dependencies": {} }, "nadena.dev.ndmf": { - "version": "1.5.0-beta.0" + "version": "1.5.0-beta.2" } } } \ No newline at end of file diff --git a/Editor/PluginDefinition/PluginDefinition.cs b/Editor/PluginDefinition/PluginDefinition.cs index 775bbf99..ecd10290 100644 --- a/Editor/PluginDefinition/PluginDefinition.cs +++ b/Editor/PluginDefinition/PluginDefinition.cs @@ -1,12 +1,14 @@ #region using System; +using System.Collections.Generic; using nadena.dev.modular_avatar.animation; using nadena.dev.modular_avatar.core.ArmatureAwase; using nadena.dev.modular_avatar.core.editor.plugin; using nadena.dev.modular_avatar.editor.ErrorReporting; using nadena.dev.ndmf; using nadena.dev.ndmf.fluent; +using nadena.dev.ndmf.preview; using UnityEngine; using Object = UnityEngine.Object; diff --git a/Editor/ReactiveObjects/ObjectTogglePreview.cs b/Editor/ReactiveObjects/ObjectTogglePreview.cs index 413f17f2..ac793953 100644 --- a/Editor/ReactiveObjects/ObjectTogglePreview.cs +++ b/Editor/ReactiveObjects/ObjectTogglePreview.cs @@ -9,6 +9,22 @@ namespace nadena.dev.modular_avatar.core.editor { internal class ObjectSwitcherPreview : IRenderFilter { + static TogglablePreviewNode EnableNode = TogglablePreviewNode.Create( + () => "Object Switcher", + qualifiedName: "nadena.dev.modular-avatar/ObjectSwitcherPreview", + true + ); + + public IEnumerable GetPreviewControlNodes() + { + yield return EnableNode; + } + + public bool IsEnabled(ComputeContext context) + { + return context.Observe(EnableNode.IsEnabled); + } + public ImmutableList GetTargetGroups(ComputeContext context) { var allToggles = context.GetComponentsByType(); @@ -93,7 +109,7 @@ namespace nadena.dev.modular_avatar.core.editor { _controllers = controllers; } - + public Task Refresh(IEnumerable<(Renderer, Renderer)> proxyPairs, ComputeContext context, RenderAspects updatedAspects) { diff --git a/Editor/ReactiveObjects/ShapeChangerPreview.cs b/Editor/ReactiveObjects/ShapeChangerPreview.cs index 64e71b81..b2b6d8e5 100644 --- a/Editor/ReactiveObjects/ShapeChangerPreview.cs +++ b/Editor/ReactiveObjects/ShapeChangerPreview.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; +using nadena.dev.modular_avatar.core.editor.plugin; using nadena.dev.ndmf.preview; using UnityEngine; using Object = UnityEngine.Object; @@ -15,6 +16,22 @@ namespace nadena.dev.modular_avatar.core.editor { public class ShapeChangerPreview : IRenderFilter { + private static TogglablePreviewNode EnableNode = TogglablePreviewNode.Create( + () => "Shape Changer", + qualifiedName: "nadena.dev.modular-avatar/ShapeChangerPreview", + true + ); + + public IEnumerable GetPreviewControlNodes() + { + yield return EnableNode; + } + + public bool IsEnabled(ComputeContext context) + { + return context.Observe(EnableNode.IsEnabled); + } + public ImmutableList GetTargetGroups(ComputeContext ctx) { var allChangers = ctx.GetComponentsByType(); diff --git a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs index 65077489..7d45e254 100644 --- a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs +++ b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; +using nadena.dev.modular_avatar.core.editor.plugin; using nadena.dev.modular_avatar.core.editor.ScaleAdjuster; using nadena.dev.ndmf.preview; using UnityEditor; @@ -15,12 +16,27 @@ namespace nadena.dev.modular_avatar.core.editor { internal class ScaleAdjusterPreview : IRenderFilter { + private static TogglablePreviewNode EnableNode = TogglablePreviewNode.Create( + () => "Scale Adjuster", + qualifiedName: "nadena.dev.modular-avatar/ScaleAdjusterPreview", + true + ); [InitializeOnLoadMethod] private static void StaticInit() { } + public IEnumerable GetPreviewControlNodes() + { + yield return EnableNode; + } + + public bool IsEnabled(ComputeContext context) + { + return context.Observe(EnableNode.IsEnabled); + } + private static GameObject FindAvatarRootObserving(ComputeContext ctx, GameObject ptr) { while (ptr != null) diff --git a/package.json b/package.json index b7949f00..85fbed42 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,6 @@ }, "vpmDependencies": { "com.vrchat.avatars": ">=3.4.0", - "nadena.dev.ndmf": ">=1.5.0-beta.0 <2.0.0-a" + "nadena.dev.ndmf": ">=1.5.0-beta.2 <2.0.0-a" } }