注定命中 2022-11-24 06:53 采纳率: 0%
浏览 11

Unity内置浏览器Embedded Browser插件关闭以及跳转空Url

我是刚接触Unity 3D,以前也没学过C#。我需要开发一个项目,使用Unity 3D开发一个程序,可以在程序内部调用浏览器访问不同的链接。并且可以通过设置的按键关闭和打开内部浏览器。

我使用了Embedded Browser插件。现在遇到了几个问题。

  1. 将插件里的Browser脚本加入空组件,并写入固定的Url地址后,程序启动后,浏览器自动启动,并进入那个地址。我需要浏览器不随程序启动而启动,而是通过点击按键启动。我认为应该在插件的Browser脚本中加入gameObject.SetActive(false);,但我找不到放置这条指令合适的位置,或者应该使用别的指令阻止浏览器随程序开启。

  2. 另外,我为包含浏览器的gameObject编写了一个关闭和开启的脚本。通过关闭按键可以关闭浏览器窗口的gameObject,通过程序内桌面的网页书签可以打开浏览器窗口的gameObject

    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);
     }
    }
    

    这个脚本可以顺利关闭浏览器窗口,但在再次打开窗口时,浏览器会显示上次关闭时的页面(about.google)如图,而不是google首页。

    img


    有办法可以让gameObject在关闭,并重新打开后还原到原始状态吗?——载入google首页。

  3. 我想要在程序内桌面上放置几个书签按钮,包含Url地址,然后保持Browser组件里的Url为空。

    img


    点击任意书签按钮,可以打开内置浏览器,并转至需要的链接。我在Browser脚本里找到这段代码,似乎是用于实现这一功能的。但我不知道应该如何修改。

    /**
      * 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);
     }
    

    谢谢帮助

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-11-24 08:07
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 11月24日

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮