From 8d0c7994e75a74d40191a24013eca5e9ac7cd385 Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sat, 30 Sep 2023 13:01:20 +0900 Subject: [PATCH 1/8] extract FindAvatarsInScene() into RuntimeUtil --- Runtime/ApplyOnPlayGlobalActivator.cs | 10 +++------- Runtime/RuntimeUtil.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Runtime/ApplyOnPlayGlobalActivator.cs b/Runtime/ApplyOnPlayGlobalActivator.cs index 6f1515d3..cf9245d2 100644 --- a/Runtime/ApplyOnPlayGlobalActivator.cs +++ b/Runtime/ApplyOnPlayGlobalActivator.cs @@ -6,7 +6,6 @@ using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.SceneManagement; -using VRC.SDK3.Avatars.Components; namespace nadena.dev.ndmf.runtime { @@ -76,13 +75,10 @@ private void Awake() } } - foreach (var root in gameObject.scene.GetRootGameObjects()) + foreach (var avatar in RuntimeUtil.FindAvatarsInScene(gameObject.scene)) { - foreach (var avatar in root.GetComponentsInChildren()) - { - // TODO: Check whether each avatar needs processing (activation components) - avatar.gameObject.GetOrAddComponent().hideFlags = HideFlags.HideInInspector; - } + // TODO: Check whether each avatar needs processing (activation components) + avatar.gameObject.GetOrAddComponent().hideFlags = HideFlags.HideInInspector; } } diff --git a/Runtime/RuntimeUtil.cs b/Runtime/RuntimeUtil.cs index 4aebd2b4..31196639 100644 --- a/Runtime/RuntimeUtil.cs +++ b/Runtime/RuntimeUtil.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using JetBrains.Annotations; using UnityEngine; +using UnityEngine.SceneManagement; using VRC.SDK3.Avatars.Components; namespace nadena.dev.ndmf.runtime @@ -101,5 +102,23 @@ internal static Transform FindAvatarInParents(Transform target) return null; } + + /// + /// Returns the component marking the root of the avatar. + /// + /// Internal for now as we need to refactor this to be less VRChat-specific. + /// + /// + /// + internal static IEnumerable FindAvatarsInScene(Scene scene) + { + foreach (var root in scene.GetRootGameObjects()) + { + foreach (var avatar in root.GetComponentsInChildren()) + { + yield return avatar.transform; + } + } + } } } \ No newline at end of file From 6b1cd7412daeaaf546ece06eefdadf8c5f7af983 Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sat, 30 Sep 2023 13:24:29 +0900 Subject: [PATCH 2/8] extract VRChat specific logic into RuntimeUtil.IsAvatarRoot(transform) --- Runtime/RuntimeUtil.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Runtime/RuntimeUtil.cs b/Runtime/RuntimeUtil.cs index 31196639..800fbf82 100644 --- a/Runtime/RuntimeUtil.cs +++ b/Runtime/RuntimeUtil.cs @@ -84,10 +84,19 @@ public static string AvatarRootPath(GameObject child) return RelativePath(avatar.gameObject, child); } + /// + /// Check whether the target component is the root of the avatar. + /// + /// + /// + public static bool IsAvatarRoot(Transform target) + { + // TODO: refactor this to be less VRChat-specific. + return target.GetComponent(); + } + /// /// Returns the component marking the root of the avatar. - /// - /// Internal for now as we need to refactor this to be less VRChat-specific. /// /// /// @@ -95,8 +104,7 @@ internal static Transform FindAvatarInParents(Transform target) { while (target != null) { - var av = target.GetComponent(); - if (av != null) return av.transform; + if (IsAvatarRoot(target)) return target; target = target.parent; } @@ -114,9 +122,9 @@ internal static IEnumerable FindAvatarsInScene(Scene scene) { foreach (var root in scene.GetRootGameObjects()) { - foreach (var avatar in root.GetComponentsInChildren()) + foreach (var avatar in root.GetComponentsInChildren()) { - yield return avatar.transform; + if (IsAvatarRoot(avatar.transform)) yield return avatar.transform; } } } From e7eabac431f3e94851f19c462a703f9cba0ef634 Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sat, 30 Sep 2023 13:42:06 +0900 Subject: [PATCH 3/8] Implement platform independent avatar root check --- Runtime/RuntimeUtil.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Runtime/RuntimeUtil.cs b/Runtime/RuntimeUtil.cs index 800fbf82..e470fb27 100644 --- a/Runtime/RuntimeUtil.cs +++ b/Runtime/RuntimeUtil.cs @@ -3,7 +3,6 @@ using JetBrains.Annotations; using UnityEngine; using UnityEngine.SceneManagement; -using VRC.SDK3.Avatars.Components; namespace nadena.dev.ndmf.runtime { @@ -91,8 +90,14 @@ public static string AvatarRootPath(GameObject child) /// public static bool IsAvatarRoot(Transform target) { - // TODO: refactor this to be less VRChat-specific. - return target.GetComponent(); +#if VRC_SDK_VRCSDK3 + return target.GetComponent(); +#else + var an = target.GetComponent(); + if (!an) return false; + var parent = target.transform.parent; + return !(parent && parent.GetComponentInParent()); +#endif } /// @@ -113,8 +118,6 @@ internal static Transform FindAvatarInParents(Transform target) /// /// Returns the component marking the root of the avatar. - /// - /// Internal for now as we need to refactor this to be less VRChat-specific. /// /// /// From 66009b74575509ea04c51dae76bb78a2ff1ea611 Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sat, 30 Sep 2023 13:30:42 +0900 Subject: [PATCH 4/8] expose FindAvatarInParents() --- Runtime/RuntimeUtil.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/RuntimeUtil.cs b/Runtime/RuntimeUtil.cs index e470fb27..4e3be01b 100644 --- a/Runtime/RuntimeUtil.cs +++ b/Runtime/RuntimeUtil.cs @@ -105,7 +105,7 @@ public static bool IsAvatarRoot(Transform target) /// /// /// - internal static Transform FindAvatarInParents(Transform target) + public static Transform FindAvatarInParents(Transform target) { while (target != null) { From a9c6a4f9087f32d7f5e4516a216d59f6fa6a5718 Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sat, 30 Sep 2023 15:20:51 +0900 Subject: [PATCH 5/8] use faster path finding avatars in scene when with VRCSDK --- Runtime/RuntimeUtil.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Runtime/RuntimeUtil.cs b/Runtime/RuntimeUtil.cs index 4e3be01b..81e6b1f0 100644 --- a/Runtime/RuntimeUtil.cs +++ b/Runtime/RuntimeUtil.cs @@ -4,6 +4,10 @@ using UnityEngine; using UnityEngine.SceneManagement; +#if VRC_SDK_VRCSDK3 +using VRC.SDK3.Avatars.Components; +#endif + namespace nadena.dev.ndmf.runtime { /// @@ -91,7 +95,7 @@ public static string AvatarRootPath(GameObject child) public static bool IsAvatarRoot(Transform target) { #if VRC_SDK_VRCSDK3 - return target.GetComponent(); + return target.GetComponent(); #else var an = target.GetComponent(); if (!an) return false; @@ -125,7 +129,11 @@ internal static IEnumerable FindAvatarsInScene(Scene scene) { foreach (var root in scene.GetRootGameObjects()) { +#if VRC_SDK_VRCSDK3 + foreach (var avatar in root.GetComponentsInChildren()) +#else foreach (var avatar in root.GetComponentsInChildren()) +#endif { if (IsAvatarRoot(avatar.transform)) yield return avatar.transform; } From 498875b1f415eefa36a80abb698c6199c3d900c3 Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sat, 30 Sep 2023 13:33:55 +0900 Subject: [PATCH 6/8] add version defines --- Editor/nadena.dev.ndmf.asmdef | 5 +++++ Runtime/nadena.dev.ndmf.runtime.asmdef | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Editor/nadena.dev.ndmf.asmdef b/Editor/nadena.dev.ndmf.asmdef index 6c0e5a11..36f20c53 100644 --- a/Editor/nadena.dev.ndmf.asmdef +++ b/Editor/nadena.dev.ndmf.asmdef @@ -20,6 +20,11 @@ "name": "nadena.dev.modular-avatar", "expression": "[1.7.0,99999.0.0]", "define": "MODULAR_AVATAR" + }, + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "NDMF_VRCSDK3_AVATARS" } ], "noEngineReferences": false diff --git a/Runtime/nadena.dev.ndmf.runtime.asmdef b/Runtime/nadena.dev.ndmf.runtime.asmdef index a3c1c942..f2a1dc8d 100644 --- a/Runtime/nadena.dev.ndmf.runtime.asmdef +++ b/Runtime/nadena.dev.ndmf.runtime.asmdef @@ -8,6 +8,12 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "NDMF_VRCSDK3_AVATARS" + } + ], "noEngineReferences": false } \ No newline at end of file From ae8937bce6b3784766760ad08c78efc81ef1e27b Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sun, 1 Oct 2023 10:30:28 +0900 Subject: [PATCH 7/8] use NDMF_VRCSDK3_AVATARS --- Runtime/RuntimeUtil.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Runtime/RuntimeUtil.cs b/Runtime/RuntimeUtil.cs index 81e6b1f0..dbc89c3a 100644 --- a/Runtime/RuntimeUtil.cs +++ b/Runtime/RuntimeUtil.cs @@ -4,7 +4,7 @@ using UnityEngine; using UnityEngine.SceneManagement; -#if VRC_SDK_VRCSDK3 +#if NDMF_VRCSDK3_AVATARS using VRC.SDK3.Avatars.Components; #endif @@ -94,7 +94,7 @@ public static string AvatarRootPath(GameObject child) /// public static bool IsAvatarRoot(Transform target) { -#if VRC_SDK_VRCSDK3 +#if NDMF_VRCSDK3_AVATARS return target.GetComponent(); #else var an = target.GetComponent(); @@ -129,7 +129,7 @@ internal static IEnumerable FindAvatarsInScene(Scene scene) { foreach (var root in scene.GetRootGameObjects()) { -#if VRC_SDK_VRCSDK3 +#if NDMF_VRCSDK3_AVATARS foreach (var avatar in root.GetComponentsInChildren()) #else foreach (var avatar in root.GetComponentsInChildren()) From e30b96ef0894366d7eab1add014164d642fd0a4b Mon Sep 17 00:00:00 2001 From: kaikoga Date: Thu, 5 Oct 2023 00:02:56 +0900 Subject: [PATCH 8/8] Add changelog --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc703613..1bc69303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Added +- Exposed APIs for finding avatar roots in RuntimeUtil (#34) + +### Fixed + +### Changed + +### Removed + +### Security + +## [1.1.0] - [2023-10-05] + ### Added - Added toplevel menu for manual bake avatar, even when MA is also installed (#35) - Added support for multiple ExportsPlugin declarations (#40)