实现简单的效果:点击Button,调用IOS AlertView,并显示硬件型号
具体实现:在脚本中定义2个外部方法,一个为弹出AlertView的,另一个则为返回字符串的
GUI中创建一个Button,并在点击时弹出调用外部函数,达到弹框效果
在C-Sharp定义了一个外部方法
DllImport("__Internal") 和extern是关键点
以下是C-Sharp脚本代码
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class Test : MonoBehaviour {
private static string _buttonTitle = "press!!!!";
[DllImport ("__Internal")]
private static extern string _getDeviceName();
[DllImport ("__Internal")]
private static extern void _showAlertView(string str);
// Use this for initialization
void Start () {
if(Application.platform==RuntimePlatform.IPhonePlayer)
{
print("Unity:"+_getDeviceName());
}
}
void OnGUI ()
{
if (GUI.Button(new Rect (15, 10, 450, 100),_buttonTitle))
{
_showAlertView(_getDeviceName());