Last active
December 7, 2018 03:19
-
-
Save baobao/dd14391050c675d76c3c3bb7a087e535 to your computer and use it in GitHub Desktop.
Unityネイティブプラグインショートコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" | |
{ | |
float _fooPluginFunction () | |
{ | |
// Unityのメソッドを実行する | |
// ネイティブ => C# | |
UnitySendMessage("Go", "FromNativeCall", "Native to C#"); | |
return 5.0F; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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