feat: improve handling of editoronly objects (#224)

This commit is contained in:
bd_ 2023-02-25 17:53:09 +09:00 committed by GitHub
parent db7be7107c
commit d39c098893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -150,6 +150,8 @@ namespace nadena.dev.modular_avatar.core.editor
AssetDatabase.StartAssetEditing();
nowProcessing = true;
ClearEditorOnlyTagComponents(avatarGameObject.transform);
BoneDatabase.ResetBones();
PathMappings.Init(vrcAvatarDescriptor.gameObject);
ClonedMenuMappings.Clear();
@ -216,6 +218,28 @@ namespace nadena.dev.modular_avatar.core.editor
}
}
private static void ClearEditorOnlyTagComponents(Transform obj)
{
// EditorOnly objects can be used for multiple purposes - users might want a camera rig to be available in
// play mode, for example. For now, we'll prune MA components from EditorOnly objects, but otherwise leave
// them in place when in play mode.
if (obj.CompareTag("EditorOnly"))
{
foreach (var component in obj.GetComponentsInChildren<AvatarTagComponent>(true))
{
UnityEngine.Object.DestroyImmediate(component);
}
}
else
{
foreach (Transform transform in obj)
{
ClearEditorOnlyTagComponents(transform);
}
}
}
[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
private static void FixupAnimatorDebugData(GameObject avatarGameObject)
{