Unity->Objective-Cサンプル
#import <Foundation/Foundation.h>
extern "C"
{
void _callObjcMethod(const char *msg)
{
// コンソールにログを出力
NSString *str = [NSString stringWithCString:msg encoding:NSUTF8StringEncoding];
NSLog(str);
}
}
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
public class SamplePlugin : MonoBehaviour
{
#if UNITY_IOS && !UNITY_EDITOR
[DllImport ("__Internal")]
static extern void _callObjcMethod (string msg);
#endif
public static void CallObjcMethod (string msg)
{
#if UNITY_IOS && !UNITY_EDITOR
_callObjcMethod (msg);
#endif
}
}
using UnityEngine;
public class Test : MonoBehaviour
{
public int cnt;
void Update ()
{
SamplePlugin.CallObjcMethod (cnt.ToString ());
cnt++;
}
}