I want to know if there is a simple way to edit the import settings for a native file/plugin (.mm or .jar) from a script in Unity Editor. I have a lot of native plugins, and I’m tired of selecting them manually each time I update them.
Also, Is it possible to set from a script the Compile flags property for iOS native plugins?
I know all of this may be possible just by editing the .meta file of the plugin, but I have no idea how to parse it without breaking anything in it.
If you have any idea, let me know.
You can use editor scripting to modify the import settings for native plugins.
Every asset gets assigned an AssetImporter - a thing that is responsible for its importing. For plugins, the PluginImporter takes care of this.
In order to get an instance of an importer for a given asset, you can use the AssetImporter.GetAtPath method.
This returns an AssetImporter instance, so you should cast that (for native plugins) into a PluginImporter object and then use its methods / properties for what you want to achieve.
I think that plugin importers have a generic mechanism of storing data in key/value pairs, so with some hackery and reverse engineering you can figure out how the compiler flags property is saved and modify that.
By peeking into the iOSPluginImporterExtension class i could see that it defines a property called CompileFlags
Maybe if you query for that you could get what you’re looking for.
Thanks liortal for the info, everything seems clear now. I wish Unity documentation was a bit more clear.
Here is the sample code for everyone else:
PluginImporter facebookPlugin = AssetImporter.GetAtPath("Assets/Facebook/Editor/iOS/FbUnityInterface.mm") as PluginImporter;
facebookPlugin.SetCompatibleWithEditor(false);
facebookPlugin.SetCompatibleWithAnyPlatform(false);
facebookPlugin.SetCompatibleWithPlatform(BuildTarget.iOS, true);
facebookPlugin.SetPlatformData(BuildTarget.iOS, "CompileFlags", "-fno-objc-arc");
Thanks @liortal & @Victor_Kallai . Your discussion here was really helpful.
Hello,
thank you for the code, I am trying to do a similar thing by using
SetExcludeEditorFromAnyPlatform to exclude a DLL from editor based on some editor settings automatically.
Visually it works because I can see the checkmark that appears and disappears under Exclude Platforms → Editor
but the change does not affect the code because I cannot see the changes until I click “Apply” in the Import Settings of the DLL.
I tried to call:
-
SaveAndReimport of PluginImporter
-
AssetDatabase.ImportAsset with the path of DLL
-
CompilationPipeline.RequestScriptCompilation
but none of these worked even when all together.
Is there a correct way to apply the changes of the plugin?
Thank you in advance
mpaolis