From 3b067e46640f902c3d297738818c2ad1c242266c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= <60819407+hai-vr@users.noreply.github.com> Date: Sun, 20 Oct 2024 03:58:41 +0200 Subject: [PATCH] Make compatible with Unity 6 projects (#1232) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Disable compilation for use in Unity 6 (6000.0.20f1): - Do not compile some classes and code paths in non-VRChat projects. - This has been tested in Unity 6 (6000.0.20f1). * Fix hide internal components in Unity 6: - [AddComponentMenu("")] does not work in Unity 6. - Replace it with [AddComponentMenu("/")] - This alternative is confirmed to also work in Unity 2022. --------- Co-authored-by: Haï~ Co-authored-by: bd_ --- Editor/Animation/AnimationServicesContext.cs | 4 ++++ Editor/Animation/GameObjectDisableDelayPass.cs | 6 ++++-- Editor/Animation/PathMappings.cs | 2 ++ Editor/ApplyAnimatorDefaultValuesPass.cs | 6 ++++-- Editor/Inspector/FirstPersonVisibleEditor.cs | 5 ++++- Editor/Inspector/Menu/ToggleCreatorShortcut.cs | 6 ++++-- Editor/PluginDefinition/PluginDefinition.cs | 11 ++++++++--- .../ReactiveObjectAnalyzer.LocateReactions.cs | 6 ++++-- .../AnimationGeneration/ReactiveObjectAnalyzer.cs | 6 ++++-- .../AnimationGeneration/ReactiveObjectPass.cs | 5 ++++- .../AnimationGeneration/ReactiveObjectPrepass.cs | 6 ++++-- Editor/ReactiveObjects/MaterialSetterPreview.cs | 6 ++++-- Editor/ReactiveObjects/MenuItemPreviewCondition.cs | 6 ++++-- Editor/ReactiveObjects/ObjectTogglePreview.cs | 6 ++++-- Editor/ReactiveObjects/ParameterAssignerPass.cs | 6 ++++-- Editor/ReactiveObjects/ShapeChangerPreview.cs | 6 ++++-- Editor/ReactiveObjects/Simulator/ROSimulator.cs | 6 ++++-- Editor/ReactiveObjects/Simulator/ROSimulatorButton.cs | 4 ++++ .../Simulator/StateOverrideController.cs | 7 +++++-- Editor/VisibleHeadAccessoryProcessor.cs | 5 ++++- Runtime/Activator.cs | 4 ++-- Runtime/ModularAvatarConvertConstraints.cs | 2 +- 22 files changed, 86 insertions(+), 35 deletions(-) diff --git a/Editor/Animation/AnimationServicesContext.cs b/Editor/Animation/AnimationServicesContext.cs index 95d68ec3..bc63cec9 100644 --- a/Editor/Animation/AnimationServicesContext.cs +++ b/Editor/Animation/AnimationServicesContext.cs @@ -7,7 +7,9 @@ using nadena.dev.ndmf; using UnityEditor; using UnityEditor.Animations; using UnityEngine; +#if MA_VRCSDK3_AVATARS using VRC.SDK3.Avatars.Components; +#endif #endregion @@ -89,12 +91,14 @@ namespace nadena.dev.modular_avatar.animation // HACK: This is a temporary crutch until we rework the entire animator services system public void AddPropertyDefinition(AnimatorControllerParameter paramDef) { +#if MA_VRCSDK3_AVATARS var fx = (AnimatorController) _context.AvatarDescriptor.baseAnimationLayers .First(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX) .animatorController; fx.parameters = fx.parameters.Concat(new[] { paramDef }).ToArray(); +#endif } public string GetActiveSelfProxy(GameObject obj) diff --git a/Editor/Animation/GameObjectDisableDelayPass.cs b/Editor/Animation/GameObjectDisableDelayPass.cs index 0eed02d2..87692657 100644 --- a/Editor/Animation/GameObjectDisableDelayPass.cs +++ b/Editor/Animation/GameObjectDisableDelayPass.cs @@ -1,4 +1,5 @@ -using System.Linq; +#if MA_VRCSDK3_AVATARS +using System.Linq; using nadena.dev.modular_avatar.core.editor; using nadena.dev.ndmf; using UnityEditor; @@ -124,4 +125,5 @@ namespace nadena.dev.modular_avatar.animation }; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/Animation/PathMappings.cs b/Editor/Animation/PathMappings.cs index 9546a063..8ea314bc 100644 --- a/Editor/Animation/PathMappings.cs +++ b/Editor/Animation/PathMappings.cs @@ -368,6 +368,7 @@ namespace nadena.dev.modular_avatar.animation } Profiler.EndSample(); +#if MA_VRCSDK3_AVATARS var layers = context.AvatarDescriptor.baseAnimationLayers .Concat(context.AvatarDescriptor.specialAnimationLayers); @@ -383,6 +384,7 @@ namespace nadena.dev.modular_avatar.animation ApplyMappingsToAvatarMask(acLayer.avatarMask); } Profiler.EndSample(); +#endif Profiler.EndSample(); } diff --git a/Editor/ApplyAnimatorDefaultValuesPass.cs b/Editor/ApplyAnimatorDefaultValuesPass.cs index 7b3c91ed..0f9cb15e 100644 --- a/Editor/ApplyAnimatorDefaultValuesPass.cs +++ b/Editor/ApplyAnimatorDefaultValuesPass.cs @@ -1,4 +1,5 @@ -#region +#if MA_VRCSDK3_AVATARS +#region using System; using System.Collections.Immutable; @@ -57,4 +58,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/Inspector/FirstPersonVisibleEditor.cs b/Editor/Inspector/FirstPersonVisibleEditor.cs index b9646ddb..8f7cedb9 100644 --- a/Editor/Inspector/FirstPersonVisibleEditor.cs +++ b/Editor/Inspector/FirstPersonVisibleEditor.cs @@ -1,4 +1,5 @@ -using UnityEditor; +#if MA_VRCSDK3_AVATARS +using UnityEditor; namespace nadena.dev.modular_avatar.core.editor { @@ -45,3 +46,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } + +#endif \ No newline at end of file diff --git a/Editor/Inspector/Menu/ToggleCreatorShortcut.cs b/Editor/Inspector/Menu/ToggleCreatorShortcut.cs index e549d319..d1027b95 100644 --- a/Editor/Inspector/Menu/ToggleCreatorShortcut.cs +++ b/Editor/Inspector/Menu/ToggleCreatorShortcut.cs @@ -1,4 +1,5 @@ -using nadena.dev.modular_avatar.ui; +#if MA_VRCSDK3_AVATARS +using nadena.dev.modular_avatar.ui; using UnityEditor; using UnityEngine; using VRC.SDK3.Avatars.ScriptableObjects; @@ -62,4 +63,5 @@ namespace nadena.dev.modular_avatar.core.editor Undo.RegisterCreatedObjectUndo(toggle, "Create Toggle"); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/PluginDefinition/PluginDefinition.cs b/Editor/PluginDefinition/PluginDefinition.cs index 2d258b23..4a31f17a 100644 --- a/Editor/PluginDefinition/PluginDefinition.cs +++ b/Editor/PluginDefinition/PluginDefinition.cs @@ -57,26 +57,29 @@ namespace nadena.dev.modular_avatar.core.editor.plugin #endif seq.WithRequiredExtension(typeof(AnimationServicesContext), _s2 => { +#if MA_VRCSDK3_AVATARS seq.Run("Shape Changer", ctx => new ReactiveObjectPass(ctx).Execute()) .PreviewingWith(new ShapeChangerPreview(), new ObjectSwitcherPreview(), new MaterialSetterPreview()); -#if MA_VRCSDK3_AVATARS + // TODO: We currently run this above MergeArmaturePlugin, because Merge Armature might destroy // game objects which contain Menu Installers. It'd probably be better however to teach Merge Armature // to retain those objects? maybe? seq.Run(MenuInstallPluginPass.Instance); #endif - + seq.Run(MergeArmaturePluginPass.Instance); seq.Run(BoneProxyPluginPass.Instance); +#if MA_VRCSDK3_AVATARS seq.Run(VisibleHeadAccessoryPluginPass.Instance); +#endif seq.Run("World Fixed Object", ctx => new WorldFixedObjectProcessor().Process(ctx) ); seq.Run(ReplaceObjectPluginPass.Instance); #if MA_VRCSDK3_AVATARS seq.Run(BlendshapeSyncAnimationPluginPass.Instance); -#endif seq.Run(GameObjectDelayDisablePass.Instance); +#endif seq.Run(ConstraintConverterPass.Instance); }); #if MA_VRCSDK3_AVATARS @@ -213,6 +216,7 @@ namespace nadena.dev.modular_avatar.core.editor.plugin } } +#if MA_VRCSDK3_AVATARS class VisibleHeadAccessoryPluginPass : MAPass { protected override void Execute(ndmf.BuildContext context) @@ -220,6 +224,7 @@ namespace nadena.dev.modular_avatar.core.editor.plugin new VisibleHeadAccessoryProcessor(MAContext(context)).Process(); } } +#endif class ReplaceObjectPluginPass : MAPass { diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs index 179e4ce4..7cc2e403 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.LocateReactions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if MA_VRCSDK3_AVATARS +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using nadena.dev.ndmf.preview; @@ -346,4 +347,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.cs index 9b64dde8..228f215c 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectAnalyzer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if MA_VRCSDK3_AVATARS +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using nadena.dev.modular_avatar.animation; @@ -304,4 +305,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs index 882f96bf..ae77c80f 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs @@ -1,4 +1,5 @@ -#region +#if MA_VRCSDK3_AVATARS +#region using System; using System.Collections.Generic; @@ -613,3 +614,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } + +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPrepass.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPrepass.cs index 82c5faa8..cec2bf17 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPrepass.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPrepass.cs @@ -1,4 +1,5 @@ -using nadena.dev.ndmf; +#if MA_VRCSDK3_AVATARS +using nadena.dev.ndmf; using UnityEditor.Animations; using UnityEngine; @@ -53,4 +54,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/MaterialSetterPreview.cs b/Editor/ReactiveObjects/MaterialSetterPreview.cs index a181429d..9b1a8e59 100644 --- a/Editor/ReactiveObjects/MaterialSetterPreview.cs +++ b/Editor/ReactiveObjects/MaterialSetterPreview.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if MA_VRCSDK3_AVATARS +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; @@ -144,4 +145,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/MenuItemPreviewCondition.cs b/Editor/ReactiveObjects/MenuItemPreviewCondition.cs index 1d8f8629..04ce486a 100644 --- a/Editor/ReactiveObjects/MenuItemPreviewCondition.cs +++ b/Editor/ReactiveObjects/MenuItemPreviewCondition.cs @@ -1,4 +1,5 @@ -using System; +#if MA_VRCSDK3_AVATARS +using System; using System.Collections.Generic; using nadena.dev.ndmf; using nadena.dev.ndmf.preview; @@ -70,4 +71,5 @@ namespace nadena.dev.modular_avatar.core.editor return _context.Observe(mami, _ => mami.isDefault); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/ObjectTogglePreview.cs b/Editor/ReactiveObjects/ObjectTogglePreview.cs index 45b4e9fa..3d138ed0 100644 --- a/Editor/ReactiveObjects/ObjectTogglePreview.cs +++ b/Editor/ReactiveObjects/ObjectTogglePreview.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if MA_VRCSDK3_AVATARS +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; @@ -104,4 +105,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/ParameterAssignerPass.cs b/Editor/ReactiveObjects/ParameterAssignerPass.cs index 9b891f84..b7afd0bf 100644 --- a/Editor/ReactiveObjects/ParameterAssignerPass.cs +++ b/Editor/ReactiveObjects/ParameterAssignerPass.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if MA_VRCSDK3_AVATARS +using System.Collections.Generic; using System.Linq; using nadena.dev.ndmf; using UnityEngine; @@ -236,4 +237,5 @@ namespace nadena.dev.modular_avatar.core.editor }; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/ShapeChangerPreview.cs b/Editor/ReactiveObjects/ShapeChangerPreview.cs index 58c09131..d3cde839 100644 --- a/Editor/ReactiveObjects/ShapeChangerPreview.cs +++ b/Editor/ReactiveObjects/ShapeChangerPreview.cs @@ -1,4 +1,5 @@ -#region +#if MA_VRCSDK3_AVATARS +#region using System; using System.Collections.Generic; @@ -294,4 +295,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/Simulator/ROSimulator.cs b/Editor/ReactiveObjects/Simulator/ROSimulator.cs index 40b9be8c..4d192515 100644 --- a/Editor/ReactiveObjects/Simulator/ROSimulator.cs +++ b/Editor/ReactiveObjects/Simulator/ROSimulator.cs @@ -1,4 +1,5 @@ -using System; +#if MA_VRCSDK3_AVATARS +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -637,4 +638,5 @@ namespace nadena.dev.modular_avatar.core.editor.Simulator ve_inactive.style.display = activeState ? DisplayStyle.None : DisplayStyle.Flex; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/ReactiveObjects/Simulator/ROSimulatorButton.cs b/Editor/ReactiveObjects/Simulator/ROSimulatorButton.cs index 285f4c6b..0d1eced6 100644 --- a/Editor/ReactiveObjects/Simulator/ROSimulatorButton.cs +++ b/Editor/ReactiveObjects/Simulator/ROSimulatorButton.cs @@ -1,5 +1,7 @@ using nadena.dev.modular_avatar.core.editor; +#if MA_VRCSDK3_AVATARS using nadena.dev.modular_avatar.core.editor.Simulator; +#endif using UnityEditor; using UnityEngine; using UnityEngine.UIElements; @@ -42,11 +44,13 @@ namespace nadena.dev.modular_avatar.core.editor private void OpenDebugger() { +#if MA_VRCSDK3_AVATARS GameObject target = Selection.activeGameObject; if (ReferenceObject is Component c) target = c.gameObject; else if (ReferenceObject is GameObject go) target = go; ROSimulator.OpenDebugger(target); +#endif } } } \ No newline at end of file diff --git a/Editor/ReactiveObjects/Simulator/StateOverrideController.cs b/Editor/ReactiveObjects/Simulator/StateOverrideController.cs index 74d9c45e..4392f953 100644 --- a/Editor/ReactiveObjects/Simulator/StateOverrideController.cs +++ b/Editor/ReactiveObjects/Simulator/StateOverrideController.cs @@ -1,4 +1,6 @@ -using nadena.dev.modular_avatar.core.editor.Simulator; +#if MA_VRCSDK3_AVATARS +using System; +using nadena.dev.modular_avatar.core.editor.Simulator; using UnityEditor; using UnityEngine.UIElements; @@ -74,4 +76,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Editor/VisibleHeadAccessoryProcessor.cs b/Editor/VisibleHeadAccessoryProcessor.cs index b5014d2d..54bbcb1a 100644 --- a/Editor/VisibleHeadAccessoryProcessor.cs +++ b/Editor/VisibleHeadAccessoryProcessor.cs @@ -1,4 +1,5 @@ -#region +#if MA_VRCSDK3_AVATARS +#region using System; using System.Collections.Generic; @@ -251,3 +252,5 @@ namespace nadena.dev.modular_avatar.core.editor } } } + +#endif \ No newline at end of file diff --git a/Runtime/Activator.cs b/Runtime/Activator.cs index 9d45d930..6825177e 100644 --- a/Runtime/Activator.cs +++ b/Runtime/Activator.cs @@ -19,7 +19,7 @@ namespace nadena.dev.modular_avatar.core /// initially inactive in the scene (which can have high overhead if the user has a lot of inactive avatars in the /// scene). /// - [AddComponentMenu("")] + [AddComponentMenu("/")] [ExecuteInEditMode] [DefaultExecutionOrder(-9998)] public class Activator : MonoBehaviour, IEditorOnly @@ -30,7 +30,7 @@ namespace nadena.dev.modular_avatar.core } } - [AddComponentMenu("")] + [AddComponentMenu("/")] [ExecuteInEditMode] [DefaultExecutionOrder(-9997)] public class AvatarActivator : MonoBehaviour, IEditorOnly diff --git a/Runtime/ModularAvatarConvertConstraints.cs b/Runtime/ModularAvatarConvertConstraints.cs index 1440fa25..f4f5ebdd 100644 --- a/Runtime/ModularAvatarConvertConstraints.cs +++ b/Runtime/ModularAvatarConvertConstraints.cs @@ -6,7 +6,7 @@ namespace nadena.dev.modular_avatar.core #if MA_VRCSDK3_AVATARS [AddComponentMenu("Modular Avatar/MA Convert Constraints")] #else - [AddComponentMenu("")] + [AddComponentMenu("/")] #endif [HelpURL("https://modular-avatar.nadena.dev/docs/reference/convert-constraints?lang=auto")] public class ModularAvatarConvertConstraints : AvatarTagComponent