Skip to content

Instantly share code, notes, and snippets.

@baobao
Created August 31, 2017 05:17
Show Gist options
  • Save baobao/fa835acbd48c33fe8a64f1af302a3431 to your computer and use it in GitHub Desktop.
Save baobao/fa835acbd48c33fe8a64f1af302a3431 to your computer and use it in GitHub Desktop.
Unityネイティブプラグイン文字列やり取りの失敗例
using UnityEngine;
using System.Runtime.InteropServices;
public class BridgeCSharpToObjC : MonoBehaviour
{
#if !UNITY_EDITOR
[DllImport("__Internal")]
static extern string Test_ ();
#endif
public static string Test ()
{
#if !UNITY_EDITOR
return Test_ ();
#endif
return "";
}
void Update ()
{
Debug.Log (BridgeCSharpToObjC.Test ());
}
}
#import <Foundation/Foundation.h>
extern "C"
{
const char* Test_()
{
NSString *sample = @"Fugafuga";
const char *str = [sample UTF8String];
return str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment