diff --git a/CHANGELOG.md b/CHANGELOG.md index d688799..375eb8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added toplevel menu for manual bake avatar, even when MA is also installed (#35) +- Added support for multiple ExportsPlugin declarations (#40) ### Fixed - Create ApplyOnPlayGlobalActivator correctly when creating and opening scenes (#31) diff --git a/Editor/API/Attributes/ExportsPlugin.cs b/Editor/API/Attributes/ExportsPlugin.cs index 115befc..6047b88 100644 --- a/Editor/API/Attributes/ExportsPlugin.cs +++ b/Editor/API/Attributes/ExportsPlugin.cs @@ -17,7 +17,7 @@ namespace nadena.dev.ndmf /// } /// /// - [AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] public sealed class ExportsPlugin : Attribute { public Type PluginType { get; } diff --git a/UnitTests~/PluginResolverTests.meta b/UnitTests~/PluginResolverTests.meta new file mode 100644 index 0000000..35c5b45 --- /dev/null +++ b/UnitTests~/PluginResolverTests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7f6546cd2a4385c4198d1331e973160e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnitTests~/PluginResolverTests/SupportsMultipleDeclarations.cs b/UnitTests~/PluginResolverTests/SupportsMultipleDeclarations.cs new file mode 100644 index 0000000..8313a20 --- /dev/null +++ b/UnitTests~/PluginResolverTests/SupportsMultipleDeclarations.cs @@ -0,0 +1,43 @@ +using System.Collections.Immutable; +using System.Linq; +using nadena.dev.ndmf; +using NUnit.Framework; +using UnitTests.ExportsPluginTest; + +[assembly: ExportsPlugin(typeof(PluginA))] +[assembly: ExportsPlugin(typeof(PluginB))] + +namespace UnitTests.ExportsPluginTest +{ + internal class PluginA : Plugin + { + protected override void Configure() + { + InPhase(BuildPhase.Transforming).Run("test", _ctx => { }); + } + } + + internal class PluginB : Plugin + { + protected override void Configure() + { + InPhase(BuildPhase.Transforming).Run("test", _ctx => { }); + } + } + + public class SupportsMultipleDeclarations + { + [Test] + public void TestSupportsMultipleDeclarations() + { + var resolver = new PluginResolver(); + var plugins = + resolver.Passes.SelectMany(kv => kv.Item2) // passes per phase + .Select(pass => pass.Plugin.GetType()) + .ToImmutableHashSet(); + + Assert.IsTrue(plugins.Contains(typeof(PluginA))); + Assert.IsTrue(plugins.Contains(typeof(PluginB))); + } + } +} \ No newline at end of file diff --git a/UnitTests~/PluginResolverTests/SupportsMultipleDeclarations.cs.meta b/UnitTests~/PluginResolverTests/SupportsMultipleDeclarations.cs.meta new file mode 100644 index 0000000..aae4775 --- /dev/null +++ b/UnitTests~/PluginResolverTests/SupportsMultipleDeclarations.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bb4d46b745854d2e8cb3922debd53797 +timeCreated: 1696331444 \ No newline at end of file