5. Assets 내부에 Scripts 폴더를 만들고 해당 폴더에서 iOSPlugin.cs 파일과 UIBindinsg.cs 파일을 만들자.
<iOSPlugin.cs>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
publicclassiOSPlugin : MonoBehaviour
{
#if UNITY_IOS
[DllImport("__Internal")]
privatestaticexternvoid _ShowAlert(string title, string message);
publicstaticvoidShowAlert(string title, string message)
{
Debug.Log("ShowAlert 이 제대로 실행되고 있습니다.");
_ShowAlert(title, message);
}
#elsepublicstaticvoidShowAlert(string title, string message)
{
Debug.LogError("ShowAlert is only supported on iOS platform");
}
#endif
}
<UIBindins.cs>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
publicclassUIBindings : MonoBehaviour
{
[SerializeField]
private Button showAlertButton;
// Start is called before the first frame updatevoidStart()
{
showAlertButton.onClick.AddListener(ShowAlert);
}
voidShowAlert()
{
iOSPlugin.ShowAlert("Hello","World");
}
}
6. Unity로 들어와서 Building Setting를 누르자.
Building Settings 내부에 있는 iOS에서 Player Settings 안에 들어와서 target SDK를 Device에서 simulatior 로 바꿔주도록 하자.
7. Build를 작동시키고 Unity-iPhone 파일을 실행시켜보자.
실행을 하면 오류가 날 것이다. 이 때 파일 내부에 있는 iOSPlugin 내부 내용을 아래와 같이 바꿔주도록 하자.