From efa263b551166bb3d58ccff489caace4755e61ca Mon Sep 17 00:00:00 2001 From: kaikoga Date: Mon, 28 Oct 2024 02:06:35 +0900 Subject: [PATCH] chore: Fix non-VRChat support (for MA 1.10.5) (#1324) * feat: add version defines for VRCSDK * chore: early return if VRCSDK project but not VRChat avatar --- Editor/Animation/AnimationDatabase.cs | 1 + Editor/Animation/AnimationServicesContext.cs | 2 ++ Editor/Animation/AnimationUtil.cs | 2 ++ Editor/Animation/PathMappings.cs | 27 ++++++++++--------- .../FixupPasses/FixupExpressionsMenuPass.cs | 2 ++ Editor/MergeAnimatorProcessor.cs | 1 + .../OptimizationPasses/PruneParametersPass.cs | 2 ++ .../AnimationGeneration/ReactiveObjectPass.cs | 2 ++ Editor/RenameParametersHook.cs | 2 ++ .../AnimParameterPathRewritingTest.cs | 8 ++++-- .../Animation/AvatarMask/AvatarMaskTest.cs | 8 ++++-- .../BaseLayerReferenceCorrectionTest.cs | 8 ++++-- .../Animation/PlayAudio/PlayAudioRemapping.cs | 6 +++-- .../MergeAnimatorTests/MergeSingleTests.cs | 8 ++++-- .../PreexistingParamsTest.cs | 3 +++ .../ProxyAnim/ProxyAnimTest.cs | 8 ++++-- .../SyncedLayerOverrideInSubStateMachine.cs | 8 ++++-- .../TypeAdjustment/ConvertTransitionTypes.cs | 3 +++ .../MergeDBT/MergeDirectBlendTreeTests.cs | 4 +++ .../ReactiveComponent/BlendshapeSyncTest.cs | 8 ++++-- .../ReactiveComponent/ObjectToggleTests.cs | 8 ++++-- .../AutoValueAssignmentTests.cs | 8 ++++-- .../ParameterAssignment/ParameterTypeTests.cs | 8 ++++-- .../ShapeDeletionAnalysis.cs | 4 +++ .../InitialStates/SCDefaultAnimation.cs | 8 ++++-- .../VisibleHeadAccessoryTest.cs | 8 ++++-- 26 files changed, 119 insertions(+), 38 deletions(-) diff --git a/Editor/Animation/AnimationDatabase.cs b/Editor/Animation/AnimationDatabase.cs index dd594092..cb8a1a8d 100644 --- a/Editor/Animation/AnimationDatabase.cs +++ b/Editor/Animation/AnimationDatabase.cs @@ -158,6 +158,7 @@ namespace nadena.dev.modular_avatar.animation #if MA_VRCSDK3_AVATARS var avatarDescriptor = context.AvatarDescriptor; + if (!avatarDescriptor) return; foreach (var layer in avatarDescriptor.baseAnimationLayers) { diff --git a/Editor/Animation/AnimationServicesContext.cs b/Editor/Animation/AnimationServicesContext.cs index bc63cec9..57ad5dd0 100644 --- a/Editor/Animation/AnimationServicesContext.cs +++ b/Editor/Animation/AnimationServicesContext.cs @@ -92,6 +92,8 @@ namespace nadena.dev.modular_avatar.animation public void AddPropertyDefinition(AnimatorControllerParameter paramDef) { #if MA_VRCSDK3_AVATARS + if (!_context.AvatarDescriptor) return; + var fx = (AnimatorController) _context.AvatarDescriptor.baseAnimationLayers .First(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX) diff --git a/Editor/Animation/AnimationUtil.cs b/Editor/Animation/AnimationUtil.cs index aa026548..1016cba9 100644 --- a/Editor/Animation/AnimationUtil.cs +++ b/Editor/Animation/AnimationUtil.cs @@ -53,6 +53,8 @@ namespace nadena.dev.modular_avatar.animation // This helps reduce the risk that we'll accidentally modify the original assets. #if MA_VRCSDK3_AVATARS + if (!context.AvatarDescriptor) return; + context.AvatarDescriptor.baseAnimationLayers = CloneLayers(context, context.AvatarDescriptor.baseAnimationLayers); context.AvatarDescriptor.specialAnimationLayers = diff --git a/Editor/Animation/PathMappings.cs b/Editor/Animation/PathMappings.cs index 8ea314bc..4d53f6a2 100644 --- a/Editor/Animation/PathMappings.cs +++ b/Editor/Animation/PathMappings.cs @@ -369,21 +369,24 @@ namespace nadena.dev.modular_avatar.animation Profiler.EndSample(); #if MA_VRCSDK3_AVATARS - var layers = context.AvatarDescriptor.baseAnimationLayers - .Concat(context.AvatarDescriptor.specialAnimationLayers); - - Profiler.BeginSample("ApplyMappingsToAvatarMasks"); - foreach (var layer in layers) + if (context.AvatarDescriptor) { - ApplyMappingsToAvatarMask(layer.mask); + var layers = context.AvatarDescriptor.baseAnimationLayers + .Concat(context.AvatarDescriptor.specialAnimationLayers); - if (layer.animatorController is AnimatorController ac) - // By this point, all AnimationOverrideControllers have been collapsed into an ephemeral - // AnimatorController so we can safely modify the controller in-place. - foreach (var acLayer in ac.layers) - ApplyMappingsToAvatarMask(acLayer.avatarMask); + Profiler.BeginSample("ApplyMappingsToAvatarMasks"); + foreach (var layer in layers) + { + ApplyMappingsToAvatarMask(layer.mask); + + if (layer.animatorController is AnimatorController ac) + // By this point, all AnimationOverrideControllers have been collapsed into an ephemeral + // AnimatorController so we can safely modify the controller in-place. + foreach (var acLayer in ac.layers) + ApplyMappingsToAvatarMask(acLayer.avatarMask); + } + Profiler.EndSample(); } - Profiler.EndSample(); #endif Profiler.EndSample(); diff --git a/Editor/FixupPasses/FixupExpressionsMenuPass.cs b/Editor/FixupPasses/FixupExpressionsMenuPass.cs index f4b549ee..4f36ec2b 100644 --- a/Editor/FixupPasses/FixupExpressionsMenuPass.cs +++ b/Editor/FixupPasses/FixupExpressionsMenuPass.cs @@ -19,6 +19,8 @@ namespace nadena.dev.modular_avatar.core.editor internal static void FixupExpressionsMenu(BuildContext context) { + if (!context.AvatarDescriptor) return; + context.AvatarDescriptor.customExpressions = true; var expressionsMenu = context.AvatarDescriptor.expressionsMenu; diff --git a/Editor/MergeAnimatorProcessor.cs b/Editor/MergeAnimatorProcessor.cs index b0af81ac..aa4dbcbc 100644 --- a/Editor/MergeAnimatorProcessor.cs +++ b/Editor/MergeAnimatorProcessor.cs @@ -65,6 +65,7 @@ namespace nadena.dev.modular_avatar.core.editor mergeSessions.Clear(); var descriptor = avatarGameObject.GetComponent(); + if (!descriptor) return; if (descriptor.baseAnimationLayers != null) InitSessions(descriptor.baseAnimationLayers); if (descriptor.specialAnimationLayers != null) InitSessions(descriptor.specialAnimationLayers); diff --git a/Editor/OptimizationPasses/PruneParametersPass.cs b/Editor/OptimizationPasses/PruneParametersPass.cs index a38b3655..801fb3e9 100644 --- a/Editor/OptimizationPasses/PruneParametersPass.cs +++ b/Editor/OptimizationPasses/PruneParametersPass.cs @@ -9,6 +9,8 @@ namespace nadena.dev.modular_avatar.core.editor { protected override void Execute(ndmf.BuildContext context) { + if (!context.AvatarDescriptor) return; + var expParams = context.AvatarDescriptor.expressionParameters; if (expParams != null && context.IsTemporaryAsset(expParams)) { diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs index ae77c80f..2d73a816 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs @@ -34,6 +34,8 @@ namespace nadena.dev.modular_avatar.core.editor internal void Execute() { + if (!context.AvatarDescriptor) return; + // Having a WD OFF layer after WD ON layers can break WD. We match the behavior of the existing states, // and if mixed, use WD ON to maximize compatibility. _writeDefaults = MergeAnimatorProcessor.ProbeWriteDefaults(FindFxController().animatorController as AnimatorController) ?? true; diff --git a/Editor/RenameParametersHook.cs b/Editor/RenameParametersHook.cs index 5bd401c3..25ce41ef 100644 --- a/Editor/RenameParametersHook.cs +++ b/Editor/RenameParametersHook.cs @@ -159,6 +159,8 @@ namespace nadena.dev.modular_avatar.core.editor public void OnPreprocessAvatar(GameObject avatar, BuildContext context) { + if (!context.AvatarDescriptor) return; + _context = context; var syncParams = WalkTree(avatar); diff --git a/UnitTests~/Animation/AnimParameterPathRewrite/AnimParameterPathRewritingTest.cs b/UnitTests~/Animation/AnimParameterPathRewrite/AnimParameterPathRewritingTest.cs index cf51e6b2..426b9ad3 100644 --- a/UnitTests~/Animation/AnimParameterPathRewrite/AnimParameterPathRewritingTest.cs +++ b/UnitTests~/Animation/AnimParameterPathRewrite/AnimParameterPathRewritingTest.cs @@ -1,4 +1,6 @@ -using nadena.dev.modular_avatar.core.editor; +#if MA_VRCSDK3_AVATARS + +using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; using UnityEditor; using UnityEngine; @@ -36,4 +38,6 @@ namespace modular_avatar_tests Assert.AreEqual("x", curves[0].propertyName); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/Animation/AvatarMask/AvatarMaskTest.cs b/UnitTests~/Animation/AvatarMask/AvatarMaskTest.cs index 897e323f..09bf1825 100644 --- a/UnitTests~/Animation/AvatarMask/AvatarMaskTest.cs +++ b/UnitTests~/Animation/AvatarMask/AvatarMaskTest.cs @@ -1,4 +1,6 @@ -using System; +#if MA_VRCSDK3_AVATARS + +using System; using System.Collections.Generic; using System.Linq; using nadena.dev.ndmf; @@ -158,4 +160,6 @@ namespace modular_avatar_tests Assert.IsFalse(state.transformMaskElements.Any(e => e.Item1 == "Armature/Hips/UpperLeg.R")); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/Animation/BaseLayerReferenceCorrection/BaseLayerReferenceCorrectionTest.cs b/UnitTests~/Animation/BaseLayerReferenceCorrection/BaseLayerReferenceCorrectionTest.cs index e2bed491..2f9bb828 100644 --- a/UnitTests~/Animation/BaseLayerReferenceCorrection/BaseLayerReferenceCorrectionTest.cs +++ b/UnitTests~/Animation/BaseLayerReferenceCorrection/BaseLayerReferenceCorrectionTest.cs @@ -1,4 +1,6 @@ -using System.Linq; +#if MA_VRCSDK3_AVATARS + +using System.Linq; using nadena.dev.ndmf; using NUnit.Framework; using UnityEditor.Animations; @@ -26,4 +28,6 @@ namespace modular_avatar_tests Assert.AreEqual(desiredIndex, alc.layer); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/Animation/PlayAudio/PlayAudioRemapping.cs b/UnitTests~/Animation/PlayAudio/PlayAudioRemapping.cs index 9ccdc7e3..8bdf1489 100644 --- a/UnitTests~/Animation/PlayAudio/PlayAudioRemapping.cs +++ b/UnitTests~/Animation/PlayAudio/PlayAudioRemapping.cs @@ -1,9 +1,10 @@ -using nadena.dev.modular_avatar.core.editor; +#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER + +using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; using UnityEditor.Animations; using VRC.SDK3.Avatars.Components; -#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER namespace modular_avatar_tests { public class PlayAudioRemapping : TestBase @@ -28,4 +29,5 @@ namespace modular_avatar_tests } } } + #endif \ No newline at end of file diff --git a/UnitTests~/MergeAnimatorTests/MergeSingleTests.cs b/UnitTests~/MergeAnimatorTests/MergeSingleTests.cs index 1f546212..2da5afbf 100644 --- a/UnitTests~/MergeAnimatorTests/MergeSingleTests.cs +++ b/UnitTests~/MergeAnimatorTests/MergeSingleTests.cs @@ -1,4 +1,6 @@ -using modular_avatar_tests; +#if MA_VRCSDK3_AVATARS + +using modular_avatar_tests; using nadena.dev.modular_avatar.animation; using nadena.dev.modular_avatar.core; using nadena.dev.modular_avatar.core.editor; @@ -47,4 +49,6 @@ namespace UnitTests.MergeAnimatorTests Assert.IsTrue(state.motion.name.StartsWith("Anim2")); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/MergeAnimatorTests/PreexistingAnimatorParams/PreexistingParamsTest.cs b/UnitTests~/MergeAnimatorTests/PreexistingAnimatorParams/PreexistingParamsTest.cs index 8af5146e..3f1739d7 100644 --- a/UnitTests~/MergeAnimatorTests/PreexistingAnimatorParams/PreexistingParamsTest.cs +++ b/UnitTests~/MergeAnimatorTests/PreexistingAnimatorParams/PreexistingParamsTest.cs @@ -1,3 +1,5 @@ +#if MA_VRCSDK3_AVATARS + using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -35,3 +37,4 @@ public class PreexistingParamsTest : TestBase } } +#endif \ No newline at end of file diff --git a/UnitTests~/MergeAnimatorTests/ProxyAnim/ProxyAnimTest.cs b/UnitTests~/MergeAnimatorTests/ProxyAnim/ProxyAnimTest.cs index b67e30d1..974865d7 100644 --- a/UnitTests~/MergeAnimatorTests/ProxyAnim/ProxyAnimTest.cs +++ b/UnitTests~/MergeAnimatorTests/ProxyAnim/ProxyAnimTest.cs @@ -1,4 +1,6 @@ -using modular_avatar_tests; +#if MA_VRCSDK3_AVATARS + +using modular_avatar_tests; using nadena.dev.modular_avatar.core; using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; @@ -25,4 +27,6 @@ namespace UnitTests.MergeAnimatorTests.ProxyAnim Assert.AreEqual(originalClip, resultClip); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/MergeAnimatorTests/SyncedLayerOverrideInSubStatemachine/SyncedLayerOverrideInSubStateMachine.cs b/UnitTests~/MergeAnimatorTests/SyncedLayerOverrideInSubStatemachine/SyncedLayerOverrideInSubStateMachine.cs index 765e1333..ecf3c88a 100644 --- a/UnitTests~/MergeAnimatorTests/SyncedLayerOverrideInSubStatemachine/SyncedLayerOverrideInSubStateMachine.cs +++ b/UnitTests~/MergeAnimatorTests/SyncedLayerOverrideInSubStatemachine/SyncedLayerOverrideInSubStateMachine.cs @@ -1,4 +1,6 @@ -using modular_avatar_tests; +#if MA_VRCSDK3_AVATARS + +using modular_avatar_tests; using nadena.dev.ndmf; using NUnit.Framework; using UnityEditor.Animations; @@ -38,4 +40,6 @@ namespace UnitTests.MergeAnimatorTests.SyncedLayerOverrideInSubStatemachine Assert.NotNull(motion); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs b/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs index 0161235d..e0a024de 100644 --- a/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs +++ b/UnitTests~/MergeAnimatorTests/TypeAdjustment/ConvertTransitionTypes.cs @@ -1,3 +1,5 @@ +#if MA_VRCSDK3_AVATARS + using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -268,3 +270,4 @@ public class ConvertTransitionTypes : TestBase } } +#endif \ No newline at end of file diff --git a/UnitTests~/MergeDBT/MergeDirectBlendTreeTests.cs b/UnitTests~/MergeDBT/MergeDirectBlendTreeTests.cs index 188ef484..61c00154 100644 --- a/UnitTests~/MergeDBT/MergeDirectBlendTreeTests.cs +++ b/UnitTests~/MergeDBT/MergeDirectBlendTreeTests.cs @@ -1,3 +1,5 @@ +#if MA_VRCSDK3_AVATARS + using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; @@ -24,3 +26,5 @@ public class MergeDirectBlendTreeTests : TestBase Assert.AreEqual(0, parameters["DEF"]); } } + +#endif \ No newline at end of file diff --git a/UnitTests~/ReactiveComponent/BlendshapeSyncTest.cs b/UnitTests~/ReactiveComponent/BlendshapeSyncTest.cs index 19d61e6c..eb8bba90 100644 --- a/UnitTests~/ReactiveComponent/BlendshapeSyncTest.cs +++ b/UnitTests~/ReactiveComponent/BlendshapeSyncTest.cs @@ -1,4 +1,6 @@ -using System.Linq; +#if MA_VRCSDK3_AVATARS + +using System.Linq; using modular_avatar_tests; using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; @@ -58,4 +60,6 @@ namespace UnitTests.ReactiveComponent Assert.AreEqual(m3.actionGroups, m1.actionGroups); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/ReactiveComponent/ObjectToggleTests.cs b/UnitTests~/ReactiveComponent/ObjectToggleTests.cs index 6637ff05..30bbfe65 100644 --- a/UnitTests~/ReactiveComponent/ObjectToggleTests.cs +++ b/UnitTests~/ReactiveComponent/ObjectToggleTests.cs @@ -1,4 +1,6 @@ -using System.Linq; +#if MA_VRCSDK3_AVATARS + +using System.Linq; using modular_avatar_tests; using nadena.dev.modular_avatar.core; using nadena.dev.modular_avatar.core.editor; @@ -47,4 +49,6 @@ namespace UnitTests.ReactiveComponent Assert.IsFalse(obj.activeSelf); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs b/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs index d7eb71f5..a2c9b5b8 100644 --- a/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs +++ b/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs @@ -1,4 +1,6 @@ -using System; +#if MA_VRCSDK3_AVATARS + +using System; using System.Collections.Generic; using System.Linq; using modular_avatar_tests; @@ -112,4 +114,6 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment Assert.AreEqual(expectedDefaultValue, avDesc.expressionParameters.parameters.Single().defaultValue); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/ReactiveComponent/ParameterAssignment/ParameterTypeTests.cs b/UnitTests~/ReactiveComponent/ParameterAssignment/ParameterTypeTests.cs index 6a4a45b5..f16844c3 100644 --- a/UnitTests~/ReactiveComponent/ParameterAssignment/ParameterTypeTests.cs +++ b/UnitTests~/ReactiveComponent/ParameterAssignment/ParameterTypeTests.cs @@ -1,4 +1,6 @@ -using System; +#if MA_VRCSDK3_AVATARS + +using System; using System.Linq; using modular_avatar_tests; using nadena.dev.modular_avatar.core; @@ -82,4 +84,6 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment Assert.AreEqual(expected, descriptor.expressionParameters.parameters.Single().valueType); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/ReactiveComponent/ShapeDeletionAnalysis.cs b/UnitTests~/ReactiveComponent/ShapeDeletionAnalysis.cs index 7cb78e50..debfe8c9 100644 --- a/UnitTests~/ReactiveComponent/ShapeDeletionAnalysis.cs +++ b/UnitTests~/ReactiveComponent/ShapeDeletionAnalysis.cs @@ -1,3 +1,5 @@ +#if MA_VRCSDK3_AVATARS + using System.Collections; using System.Collections.Generic; using System.Linq; @@ -96,3 +98,5 @@ public class ShapeDeletionAnalysis : TestBase Assert.AreEqual(originalSharedMesh, mesh.sharedMesh); } } + +#endif \ No newline at end of file diff --git a/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs b/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs index c1061b3e..2651f178 100644 --- a/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs +++ b/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs @@ -1,4 +1,6 @@ -using modular_avatar_tests; +#if MA_VRCSDK3_AVATARS + +using modular_avatar_tests; using nadena.dev.modular_avatar.animation; using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; @@ -121,4 +123,6 @@ namespace ShapeChangerTests Assert.AreEqual(100.0f, smr.GetBlendShapeWeight(sharedMesh.GetBlendShapeIndex("key3")), 0.1f); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs b/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs index a85f2954..7685066b 100644 --- a/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs +++ b/UnitTests~/VisibleHeadAccessoryTest/VisibleHeadAccessoryTest.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +#if MA_VRCSDK3_AVATARS + +using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -57,4 +59,6 @@ namespace UnitTests.VisibleHeadAccessoryTest Assert.AreEqual(headchop.globalScaleFactor, 1); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file