From 44bfec958cd7c8106c6abdb00e60b23c93d4c2fc Mon Sep 17 00:00:00 2001 From: bd_ Date: Sun, 15 Sep 2024 19:31:37 -0700 Subject: [PATCH] fix: ScaleAdjusterPreview breaks when avatar descriptors are nested --- Editor/ScaleAdjuster/ScaleAdjusterPreview.cs | 34 ++++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs index 31f3beb6..6ea4b838 100644 --- a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs +++ b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs @@ -61,27 +61,27 @@ namespace nadena.dev.modular_avatar.core.editor var avatarToRenderer = new Dictionary>(new ObjectIdentityComparer()); - foreach (var adjuster in scaleAdjusters) + foreach (var root in ctx.GetAvatarRoots()) { - if (adjuster == null) continue; - - // Find parent object - // TODO: Reactive helper - var root = FindAvatarRootObserving(ctx, adjuster.gameObject); - if (root == null) continue; - - if (!avatarToRenderer.TryGetValue(root, out var renderers)) + if (ctx.GetComponentsInChildren(root, true).Length == 0) { - renderers = new HashSet(new ObjectIdentityComparer()); - avatarToRenderer.Add(root, renderers); + continue; + } - foreach (var renderer in root.GetComponentsInChildren()) - { - // For now, the preview system only supports MeshRenderer and SkinnedMeshRenderer - if (renderer is not MeshRenderer and not SkinnedMeshRenderer) continue; + if (ctx.GetAvatarRoot(root?.transform?.parent?.gameObject) != null) + { + continue; // nested avatar descriptor + } + + var renderers = new HashSet(new ObjectIdentityComparer()); + avatarToRenderer.Add(root, renderers); - renderers.Add(renderer); - } + foreach (var renderer in root.GetComponentsInChildren()) + { + // For now, the preview system only supports MeshRenderer and SkinnedMeshRenderer + if (renderer is not MeshRenderer and not SkinnedMeshRenderer) continue; + + renderers.Add(renderer); } }