fix: Scale Adjusters outside an avatar throw exceptions (#822)

* fix: Scale Adjusters outside an avatar throw exceptions

* fix: improve scale adjuster performance
This commit is contained in:
bd_ 2024-04-15 11:47:39 +09:00 committed by GitHub
parent 8d64c63f49
commit b25359a14a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -112,13 +112,15 @@ namespace nadena.dev.modular_avatar.core
trueParent = trueParent.parent;
}
// Clean up any additional parentage we might not want
if (proxyChild.parent != null)
{
Transform parent = proxyChild.parent;
// Reparent to root
proxyChild.SetParent(null, false);
// Destroy old hierarchy
Transform parent = proxyChild.parent;
while (parent.parent != null) parent = parent.parent;
DestroyImmediate(parent.gameObject);
}

View File

@ -31,6 +31,7 @@ namespace nadena.dev.modular_avatar.core
{
lock (_lock)
{
if (_adjusters.Contains(adjuster)) return;
_adjusters = _adjusters.Add(adjuster);
_dirty = true;
}
@ -121,7 +122,17 @@ namespace nadena.dev.modular_avatar.core
_dirty = false;
}
var avatarRoots = _capturedBones.Keys.Select(RuntimeUtil.FindAvatarTransformInParents).ToImmutableHashSet();
var avatarRoots = _capturedBones.Keys.Select(bone =>
{
var root = RuntimeUtil.FindAvatarTransformInParents(bone);
if (root == null)
{
root = bone;
while (root.parent != null) root = root.parent;
}
return root;
}).ToImmutableHashSet();
var potentialRenderers = avatarRoots.SelectMany(r => r.GetComponentsInChildren<SkinnedMeshRenderer>(true))
.ToList();