Unity application development based on UIWidgets (7)

Unity does not integrate browser components, nor does UIWidgets. When a mobile project requires a built-in browser, you can only write a browser plug-in by yourself, or directly use a third-party browser plug-in.

It should be noted here that the third-party browser plug-ins are basically based on the callable library packaged under the ios or Android platform, and the project needs to be run on the corresponding platform to be able to call it. Generally, it can only be forced out of the PC platform. Unity opens the default browser of the system (that is, the method called Applicaition.LoadURL)

The webview of the browser plug-in called by a third party is generally at the top of the UI, that is, blocked on the UGUI, which will shield the original UI interaction events, but the plug-in generally provides a margin method of the webview, that is, the webview distance is up and down The distance between the left and right borders. When developing, you can use this feature to stack a layer of UI under the WebView to be responsible for operation events such as return, then stack the interface of the webview on top, and set the margin value without blocking the upper layer of UI. For example, the upper layer of the UI has a return button in the upper left corner of the interface, and occupies 100 pixels from top to bottom on the y axis, you can set the upper layer webView to margin (top: 100px), as shown in the figure

 

When the UIWidget is called to open the browser interface, the browser interface can be initialized and displayed in the initState method of the interface. When the return button of the UI is clicked, the browser interface can be destroyed in the pop event. code show as below:

public override void initState() {
            base.initState();
            //初始化时显示浏览器界面
            MainLogic.GetInstance().webViewManager.Load("http://www.baidu.com");
        }

//返回键的事件
Widget _buildNavigationBar() {
            return new CustomAppBar(
                () => {
                    //点击返回时关掉浏览器页面
                    MainLogic.GetInstance().webViewManager.Close();
                    if (Router.navigator.canPop()) {
                        Router.navigator.pop();
                    }
                },
                rightWidget: this.widget.showOpenInBrowser ?
                    (Widget) new CustomButton(
                        onPressed: () => StoreProvider.store.dispatcher.dispatch(new OpenUrlAction {url = this.widget.url}),
                        child: new Icon(
                            icon: Icons.open_in_browser,
                            size: 24,
                            color: CColors.Icon
                        )
                    )
                    : new Container(),
                backgroundColor: this._progress == 1 && this.widget.fullScreen ? CColors.Black : null,
                bottomSeparatorColor: this._progress == 1 && this.widget.fullScreen ? CColors.Black : null
            );
        }

Unity third-party mobile browser plug-ins generally use Uniwebview, but pay attention to the version used. Especially when you need to publish to the appstore, if you use an old version of the browser plug-in, you may still reference the UIWebView component in xcode, which will cause the app to fail the appstore review. Because the Apple developer here has recommended users to replace UIWebView with WKWebView, if it is used, it will not be listed. Here is a third-party browser plug-in ULiteWebView , if you are interested, you can also support the developer AssetStore

 

 

Guess you like

Origin blog.csdn.net/ssssssilver/article/details/110876654