0

I'm new to unity3D and C# (and IOS :), but need to get things working with a legacy C library (.h & .a files) on iPhone. I've read some about Plugins from unity documentation, but still feel overwhelmed by the complicated procedures. Could any guru show me the correct way out of the mess? Thanks!

1
  • Did following method work for u..?? Commented Sep 21, 2013 at 6:46

1 Answer 1

4

Go through this link. This gives the idea for making plugins for iOS. If any doubt, ask.

A practical example for plugin

1) Make a C# file called AppControllerBinding.cs in the plugins folder in Unity and add the code as followed:

 using UnityEngine; using System.Collections; using System.Runtime.InteropServices; // All Objective-C exposed methods should be bound here public class AppControllerBinding { [DllImport("__Internal")] private static extern void _MyFunction(string myName); public static void MyFunction(string MyNameIN) { // Call plugin only when running on real device if( Application.platform == RuntimePlatform.IPhonePlayer ) _MyFunction(MyNameIN); } } 

2) Add the MyFunction() function to the bottom on the AppController.mm file inside Xcode as follows (after the @end statement):

extern "C" { void _MyFunction(const char* MyName) { NSString* s = [NSString stringWithUTF8String: MyName]; [Self logName:s]; //<-----logName is method which takes string parameter printf_console("_MyFunction() called in Appcontroller.mm in Xcode.\n"); } } 

3) When you want to use the logName function of AppController.mm inside Unity just make a call like this:

AppControllerBinding.MyFunction("Nick"); 
Sign up to request clarification or add additional context in comments.

1 Comment

AppControllerBinding.cs can be anywhere under Assets and IMO shoudn't be under Plugins. Everything under Plugins/iOS is meant to be copied (or symlinked) to Xcode project. Xcode don't know how to dal with C# files so Libraray file and header have to be put there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.