public static DialogHandler Create(Browser parent, DialogCallback dialogCallback, MenuCallback contextCallback) { if (dialogPage == null) { dialogPage = Resources.Load <TextAsset>("Browser/Dialogs").text; } GameObject gameObject = new GameObject("Browser Dialog for " + parent.name); DialogHandler handler = gameObject.AddComponent <DialogHandler>(); handler.parentBrowser = parent; handler.dialogCallback = dialogCallback; Browser browser = (handler.dialogBrowser = handler.GetComponent <Browser>()); browser.UIHandler = parent.UIHandler; browser.EnableRendering = false; browser.EnableInput = false; browser.allowContextMenuOn = BrowserNative.ContextMenuOrigin.Editable; browser.Resize(parent.Texture); browser.LoadHTML(dialogPage, "about:dialog"); browser.UIHandler = parent.UIHandler; browser.RegisterFunction("reportDialogResult", delegate(JSONNode args) { dialogCallback(args[0], args[1], args[3]); handler.Hide(); }); browser.RegisterFunction("reportContextMenuResult", delegate(JSONNode args) { contextCallback(args[0]); handler.Hide(); }); return(handler); }
protected void CreateDialogHandler() { if (dialogHandler != null) { return; } DialogHandler.DialogCallback dialogCallback = (affirm, text1, text2) => { CheckSanity(); BrowserNative.zfb_sendDialogResults(browserId, affirm, text1, text2); }; DialogHandler.MenuCallback contextCallback = commandId => { CheckSanity(); BrowserNative.zfb_sendContextMenuResults(browserId, commandId); }; dialogHandler = DialogHandler.Create(this, dialogCallback, contextCallback); }
protected void OnDestroy() { if (browserId == 0) { return; } if (dialogHandler) { DestroyImmediate(dialogHandler.gameObject); } dialogHandler = null; BrowserNative.zfb_destoryBrowser(browserId); if (textureIsOurs) { Destroy(texture); } browserId = 0; texture = null; }