Unity與iOS原生代碼之間的相互調用,unityios
效果:
代碼:【GitHub】Unity_iOS_Plugin_Demo
關鍵:1、Unity調用iOS:1.1、在Unity C#中:
[ DllImport( "__Internal" )]private static extern int _showSelectTitleDialog ( string title, string msg);
1.2、在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、在iOS中調用Unity:2.1、在Xcode Objective-C中:
UnitySendMessage("DialogManager", "OnCancel", tag.UTF8String);2.2、在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); }}
參考資料:http://docs.unity3d.com/Manual/PluginsForIOS.htmlhttps://github.com/asus4/UnityNativeDialogPluginhttp://blog.csdn.net/wwmusic/article/details/21008289
文檔資訊
- 原文網址:http://blog.csdn.net/cdztop/article/details/39805803
Unity在Android與iOS中怎調用Native API
首先unity支援在C#中調用C++ dll,這樣可以在Android和iOS中提供C++介面在unity中調用。利用這一特性,可以擴充unity的功能。例如整合和調用第三方庫。同時為了滿足對unity介面的一致性,可以考慮在android和iOS上提供相同的介面供C#調用。這裡列舉以下兩個例子。本例對應的介面聲明如下: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.......餘下全文>>
用Unity3D開發ios程式時,怎調用iphone或者ipad的外部網路攝影機(包括自拍與後置網路攝影機)?
Unity3D產生的是整個ios工程, 當然可以修改了..怎麼修改? 用xcode開啟即可, 接下來就是iphone開發了.