/** * Request a callback from the browser. * <p> * The returned result will be the result of running eval on the js code * in the parent browser. * <p> * The return is: var value = js; return value; * <p> * A typical js call might be: * <pre> * (function() { return "hello world"; })(); * </pre> */ public void Invoke(string js, AsyncBrowserCallback callback) { InitMessenger(); var id = key; ++key; _messenger.Add(id, callback); var cmd = String.Format("var rvalue = {0}; var u = GetUnity(); u.SendMessage('{1}', 'Message', '{2}!'+rvalue);", js, NAME, id); Application.ExternalEval(cmd); }
/** Add a callback to invoke when it happens */ public void Add(int id, AsyncBrowserCallback callback) { _callbacks[id] = callback; }