I'm new to Unity 3D, and never touched c# before. Now I have a project to develop a program with Unity 3D, which is able to use internal browser in the program to visit external links. And able to use buttons to control CLOSE and OPEN of this internal browser.
I used the Embedded Browser plugin, but occurs several issues.
When set the plugin to work, the internal browser will popup automatically along the program start. in which I assume the browser is called out by a button. I assume there need a line
gameObject.SetActive(false);
to stop the browser auto start in the Browser script, but I could find where to put, or use other function to stop it.I wrote a common script to close and open this internal browser by buttons.
public class OpenCloseOption : MonoBehaviour
{
// Close the browser window with cross button
public void Close()
{
this.gameObject.SetActive(false);
}
// Open the browser window with bookmark button
public void Open()
{
gameObject.SetActive(true);
}
}
The close and open functions are work fine, but when I close the browser window, and open again, it will display the previous page when it was closed (about.google), but not the default page google index page. Is there a way to initialize the browser when it be closed or restarted?
I tried Destroy function, it doesn't work, once destroy the gameObject, it will never be call out again.
- I'm going to put some bookmark buttons in the program, and leave the Url null in the Browser component. so that, when I click the bookmark button, the browser window will popup and lead me to desired page.
I found some codes in the Browser script, looks like for doing this requirement, but I dont know how to change it.
/**
* Navigates to the given URL. If force is true, it will go there right away.
* If force is false, pages that wish to can prompt the user and possibly cancel the
* navigation.
*/
public void LoadURL(string url, bool force) {
if (DeferUnready(() => LoadURL(url, force))) return;
const string magicPrefix = "localGame://";
if (url.StartsWith(magicPrefix)) {
url = LocalUrlPrefix + url.Substring(magicPrefix.Length);
}
if (string.IsNullOrEmpty(url)) {
//If we ask CEF to load "" it will crash. Try Url = "about:blank" or LoadHTML() instead.
throw new ArgumentException("URL must be non-empty", "value");
}
loadPending = true;
BrowserNative.zfb_goToURL(browserId, url, force);
}
/**
* Loads the given HTML string as if it were the given URL.
* For the URL use http://-like porotocols or else things may not work right. (In particular, the backend
* might sanitize it to "about:blank" and things won't work right because it appears a page isn't loaded.)
*
* Note that, instead of using this, you can also load "data:" URIs into this.Url.
* This allows pretty much any type of content to be loaded as the whole page.
*/
public void LoadHTML(string html, string url = null) {
if (DeferUnready(() => LoadHTML(html, url))) return;
//Debug.Log("Load HTML " + html);
loadPending = true;
if (string.IsNullOrEmpty(url)) {
url = LocalUrlPrefix + "custom";
}
if (string.IsNullOrEmpty(this.Url)) {
//Nothing will happen if we don't have an initial page, so cause one.
this.Url = "about:blank";
skipNextLoad = true;
}
BrowserNative.zfb_goToHTML(browserId, html, url);
}
Can someone help me to point out which part is for control to load button's Url into here?