Skip to content

Instantly share code, notes, and snippets.

@baobao baobao/SamplePlugin.cpp

Last active Dec 7, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.