Unity與iOS原生代碼之間的相互調用


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.html

https://github.com/asus4/UnityNativeDialogPlugin

http://blog.csdn.net/wwmusic/article/details/21008289


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM