- Home /
Is possible to call game logic without SendMessage in WebGL Build
I had seen this page
http://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
It says i can call game logic from js code by using SendMessage.But i wanna to know,is this enough fast?is there a way to call direct (like call c# delegates from c/cpp on win/osx/android etc... )?
I try write a WebGL plugin using c/cpp like
#include <stdio.h>
typedef void (*TestCallback)(int arg);
void Hello ()
{
printf("Hello, world!\n");
}
int AddNumbers (int x, int y)
{
return x + y;
}
void CallCallback(TestCallback cb){
cb(99);
}
and in C#
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class TestPlugin {
public delegate void TestCallback(int arg);
[DllImport("__Internal")]
public static extern void Hello();
[DllImport("__Internal")]
public static extern int AddNumbers(int x, int y);
[DllImport("__Internal")]
public static extern void CallCallback(TestCallback cb);
}
and run c# code:
void Start ()
{
TestPlugin.Hello ();
Debug.Log ("after Hello");
Debug.Log ("AddNumbers:" + TestPlugin.AddNumbers (1, 2));
TestPlugin.CallCallback (myCb);
}
void myCb (int arg)
{
Debug.Log ("myCb:" + arg);
}
if I comment this line
TestPlugin.CallCallback (myCb);
It just work fine,But with uncomment this, WebGL Page load fail with errors,The error message seems not helpful...
can i pass a delegate to WebGL Plugin? or there is anthor way do this?
thanks for watch.
sorry for my english.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to send multiple values from browser to unity webgl game? 1 Answer
Browser interaction to Unity 0 Answers
Webgl and System.IO.Director emscripten's linking support 0 Answers