Creating iOS plugins for Unity
Creating iOS plugins for Unity
This is just a quick starter tutorial on making a simple iOS plugin for Unity.In your Unity project, create a folder Assets/Plugin/iOS. Files directly in that folder (can’t be in a subfolder) automatically get added to your iOS project when you have Unity create an iOS build.
We’ll create a testplugin.mm file in that folder. In that file, we put the code for the iOS side of the plugin. Unity needs the plugins to be c named. So, we wrap it in an extern “C”.
Here is an example plugin:
|
Create a file called TestPlugin.cs in Unity.
|
Another option to pass back a value from your iOS code to Unity is at any time in your iOS code, you can call
UnitySendMessage("UnityObjectName", "UnityObject'sMethodName", "Some message here")
.
That makes Unity look for that object in your scene and then call that
method and give it that string. So, if you create a
TestPluginListener.cs script and have a method void ListenerMethod(string message)
, you could create a TestPluginListener object in your Scene, add that script component, then call UnitySendMessage("TestPluginListener", "ListenerMethod", "My test message");
in your iOS code. Your script would then get that message and you could process it however you want.