So you're making a Unity-based iOS game, and you want to use Pure Data as your audio engine? Great! Let me show you how it's done. Before starting, I suggest you read and understand this post on embedding libPd into an iOS app.
Step one: Create a wrapper for PdBase
The first thing you'll have to do is create a native wrapper for PdBase. As mentioned in my previous post, PdBase is the main interface between your application and libPd. So essentially what you're doing here, is creating a way to send messages to PdBase, which in turn sends messages to your Pure Data patches. You can find my example wrapper here, however be warned that this is just a proof-of-concept, it is not fully tested, nor production ready code. I'll explain how these wrapper functions work with an example:
The first thing you do with each of these strings is convert them into NSStrings, because that's what PdBase expects. To do so, initialize a new NSString object with the data sent from Unity, and make sure to specify the string is encoded as NSUTF16LittleEndianStringEncoding because that's the encoding that Unity uses.
Next, you call the appropriate PdBase function with our newly created strings, and release those strings because you're done with them.
Step two: Create an interface in Unity
Now that you've wrapped all the PdBase functions you're going to use, it's time to interface with your wrapper from Unity. My example interface can be seen here. There isn't much to explain, this code can be used more or less as-is, but I have a few notes to mention.
First, lists of arguments are sent as one long string separated by colons. For example, "arg1:arg2:arg3".
Second, I append %f to float arguments which are part of a list. This is so our native interface can differentiate between float and string arguments. I did this while debugging a particular issue, but I'm fairly sure it's unnecessary.
Finally, you'll notice when passing that when I pass the length of a string to the native code, I multiply it by two. This is because our C code is interested in the number of bytes a string is, not the number of characters, and since Unity strings are UTF-16 encoded, every character is made up of two bytes.
Step three: Embed Pd into an iOS App
When you build a Unity project for iOS, Unity creates a new XCode project with your game embedded in it. At this point you'll embed Pd into your project, the process of which is described in this post. Secondly, you'll want to add your PdBase wrapper, the first file we created, to this project.
Step four: Dance Party!
At this point you should have a Unity project and libPd embedded into a single application running on your iOS device. Try calling the functions from your Unity-to-native-code-interface and see if your patches react. If they do, great! Otherwise, leave a note in the comments so we can deduce what went wrong.