Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/dd14391050c675d76c3c3bb7a087e535 to your computer and use it in GitHub Desktop.
Save baobao/dd14391050c675d76c3c3bb7a087e535 to your computer and use it in GitHub Desktop.
Unityネイティブプラグインショートコード
extern "C"
{
float _fooPluginFunction ()
{
// Unityのメソッドを実行する
// ネイティブ => C#
UnitySendMessage("Go", "FromNativeCall", "Native to C#");
return 5.0F;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
public class UseTestPlugin : MonoBehaviour
{
#if UNITY_IOS
// static libraryの場合は"__Internal"を指定
[DllImport("__Internal")]
#endif
static extern float _fooPluginFunction();
public static float FooPluginFunction()
{
#if UNITY_EDITOR
return 0;
#elif UNITY_IOS
return _fooPluginFunction();
#else
return 0;
#endif
}
void Update ()
{
// C# => Native実行
Debug.Log("Update : " + FooPluginFunction());
}
// Native => C#
public void FromNativeCall (string param)
{
Debug.Log("FromNativeCall: " + param);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment