Make compatible with Unity 6 projects (#1232)

* 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ï~ <hai-vr@users.noreply.github.com>
Co-authored-by: bd_ <bd_@nadena.dev>
This commit is contained in:
Haï~ 2024-10-20 03:58:41 +02:00 committed by GitHub
parent 26153ea60d
commit 3b067e4664
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 86 additions and 35 deletions

View File

@ -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)

View File

@ -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
};
}
}
}
}
#endif

View File

@ -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();
}

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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

View File

@ -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");
}
}
}
}
#endif

View File

@ -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<VisibleHeadAccessoryPluginPass>
{
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<ReplaceObjectPluginPass>
{

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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);
}
}
}
}
#endif

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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
};
}
}
}
}
#endif

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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;
}
}
}
}
#endif

View File

@ -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
}
}
}

View File

@ -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
}
}
}
}
}
#endif

View File

@ -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

View File

@ -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).
/// </summary>
[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

View File

@ -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