Search Unity

Writing plugin for iPhone

Discussion in 'Multiplayer' started by xcoder, Feb 10, 2010.

  1. xcoder

    xcoder

    Joined:
    Sep 26, 2009
    Posts:
    7
    Hi All,

    I am developing multiplayer game for iPhone. I wrote a simple plugin which returns an integer.

    The code is here ,

    Project Name : HelloPlugin [In cpp]

    #include "hello.h"
    #import "string.h"

    extern "C"
    {
    int FunMyPlugin(){return 3;}
    }

    Steps - 1. I build this successfully.
    2. Made Plugins folder in assets and put the HelloPlugin.bundle in it.
    3. write the C# file to access it.

    The C# code,

    using UnityEngine;
    using System.Runtime.InteropServices;

    class PluginTest : MonoBehaviour
    {

    [DllImport ("HelloPlugin")]
    private static extern int FunMyPlugin();

    void Start()
    {
    int num = FunMyPlugin();
    print (num);
    }
    }

    4. attached this script to camera and run it.

    When I run it on iPhone Advance i get an error

    " DllNotFoundException: HelloPlugin
    PluginTest.Start () (at Assets/PluginTest.cs:18)"

    But when I run this on Unity 2.6.1, It works fine and give me the output 3.

    Is there any additional things or settings are required for iPhone ?

    Can anyone tell me the detail about how to write plugin for iPhone advance in step by step manner ?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can't use bundles on the iphone, you must have the source in the project.

    Please check out the sample project thats linked in in the iphone plugin manual page at the bottom.