Interaction between Unity and iOS native code, unityios

Source: Internet
Author: User

Interaction between Unity and iOS native code, unityios
Effect:

Code: [GitHub] Unity_iOS_Plugin_Demo
Key: 1. Unity calls iOS: 1.1. in Unity C:

[ DllImport( "__Internal" )]private static extern int _showSelectTitleDialog ( string title, string msg);

1.2 In Xcode Objective-C:

extern "C" {    int _showSelectTitleDialog(const char *title, const char *msg) {        return [[UNDialogManager sharedManager]                showSelectDialog:[NSString stringWithUTF8String:title]                message:[NSString stringWithUTF8String:msg]];    }}

2. Call Unity: 2.1 in iOS. In Xcode Objective-C:
UnitySendMessage("DialogManager", "OnCancel", tag.UTF8String);
2.2 In Unity C:
public void OnCancel ( string idStr){        int id = int.Parse (idStr);        if (_delegates.ContainsKey (id)) {              _delegates [id] (-1);              _delegates.Remove (id);              Debug.LogWarning ( "===OnCancel idStr1:" + idStr);       } else {              Debug.LogWarning ( "===OnCancel idStr2:" + idStr);       }}

References: http://docs.unity3d.com/Manual/PluginsForIOS.htmlhttps://github.com/asus4/UnityNativeDialogPluginhttp://blog.csdn.net/wwmusic/article/details/21008289


Document Information

  • Http://blog.csdn.net/cdztop/article/details/39805803
  • Last modification time:, January 1, October 05, 2014

How does Unity call Native APIs in Android and iOS?

First, unity supports Calling C ++ dll in C #, so that C ++ interfaces can be provided in Android and iOS to be called in unity. With this feature, you can extend the functions of unity. For example, integrate and call third-party libraries. To ensure consistency of the unity interface, you can provide the same interface on android and iOS for C # to call. The following two examples are provided. The interface declaration for this example is as follows: public class CallNativeAPI {# if UNITY_EDITOR public static void OpenWebView (string url) {return;} public static void SumNum (int v1, int v2) {TestUnityEditor. sumNum (v1, v2); return ;}# elif UNITY_IPHONE [DllImport ("_ Internal")] public static extern void OpenWebView (string url ); [DllImport ("_ Internal")] public static extern void SumNum (int v1, int v2); # elif UNITY_ANDROID [DllImport ("libtestunity", CallingConvention = CallingConvention. cdecl)] public static extern void OpenWebView (string url); [DllImport ("libtestunity", CallingConvention = CallingConvention. cdecl)] public static extern void SumNum (int v1, int v2); # endif public static void SumNumForResult (int v1, int v2, CallbackManager. resultCallback callback) {TestCallbackManager. sumNumCallback. setResultCallBack (new CallbackManager. resultCallback (callback); SumNum (v1, v2); return ;}} namespace CallbackManager {public delegate void ResultCallback (int result); public class SumNumManager {public SumNumManager () {} private ResultCallback resultCallback; public void SetResultCallBack (ResultCallback callback) {resultCallback = callback;} public void SendResult (int result) {resultCallback (result );}}} public class TestCallbackManager {public static CallbackManager. sumNumManager sumNumCallback = new CallbackManager ....... remaining full text>

How do I call the external camera (including the front camera and the rear camera) of the iphone or ipad when developing ios programs using Unity3D )?

Unity3D generates the entire ios project. Of course you can modify it. How can I modify it? Open it with xcode, and then develop the iphone.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.