From 55e363c1b20635ed5c74b4d9f0f52bbf9e653dea Mon Sep 17 00:00:00 2001 From: bd_ <64174065+bdunderscore@users.noreply.github.com> Date: Wed, 30 Nov 2022 12:49:21 -0800 Subject: [PATCH] [ui] prevent Setup Outfit from running on an avatar root (#121) Closes: #118 --- .../Editor/EasySetupOutfit.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Packages/nadena.dev.modular-avatar/Editor/EasySetupOutfit.cs b/Packages/nadena.dev.modular-avatar/Editor/EasySetupOutfit.cs index 646fd19c..12dec868 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/EasySetupOutfit.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/EasySetupOutfit.cs @@ -1,4 +1,5 @@ -using UnityEditor; +using System.Text; +using UnityEditor; using UnityEngine; namespace nadena.dev.modular_avatar.core.editor @@ -28,11 +29,24 @@ namespace nadena.dev.modular_avatar.core.editor { foreach (var obj in Selection.objects) { + if (!(obj is GameObject gameObj)) return false; + var xform = gameObj.transform; + if (!FindBones(obj, out var _, out var _, out var outfitHips) || outfitHips.transform.parent.GetComponent() != null) { return false; } + + // Some users have been accidentally running Setup Outfit on the avatar itself, and/or nesting avatar + // descriptors when transplanting outfits. Block this (and require that there be only one avdesc) by + // refusing to run if we detect multiple avatar descriptors above the current object (or if we're run on + // the avdesc object itself) + var nearestAvatar = RuntimeUtil.FindAvatarInParents(xform); + if (nearestAvatar == null || nearestAvatar.transform == xform) return false; + + var parent = nearestAvatar.transform.parent; + if (parent != null && RuntimeUtil.FindAvatarInParents(parent) != null) return false; } return true;