日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html5 调用unity,Unity调用UniWebView打开H5界面脚本

發布時間:2023/12/9 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5 调用unity,Unity调用UniWebView打开H5界面脚本 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

//********************************************************************

// 文件名: ShowH5Controller

// 描述: 顯示H5界面

// 作者:

// 創建時間: #CREATIONDATE#

//********************************************************************

public class ShowH5Controller : MonoBehaviour

{

/// /// H5的數據

///

public class H5Data

{

public string h5_url;

public UniWebView.ReceivedMessageDelegate OnReceivedMessage;

public UniWebView.WebViewShouldCloseDelegate OnWebViewShouldClose;

}

public UniWebView uniWebView

{

get

{

if (_uniWebView == null)

{

GameObject go = new GameObject("UniWebView");

_uniWebView = go.AddComponent();

}

return _uniWebView;

}

set

{

_uniWebView = value;

}

}

private UniWebView _uniWebView;

/// /// loading物體

///

public GameObject loadingGo;

/// /// h5的返回按鍵是否使用

///

[HideInInspector]

public bool backButtonEnable = false;

public static ShowH5Controller Instance;

/// /// 異常的退出回調

///

public Action errorCallBack;

/// /// 是否顯示H5界面

///

private bool isShowH5;

/// /// 數據

///

private H5Data data;

private void Awake()

{

Instance = this;

}

/// /// 顯示H5界面

///

///

/// url后面跟的參數

public void ShowH5(string h5_url, Dictionaryurl_param, UniWebView.ReceivedMessageDelegate OnReceivedMessage, UniWebView.WebViewShouldCloseDelegate OnWebViewShouldClose)

{

if (string.IsNullOrEmpty(h5_url))

{

//Debug.Log("顯示h5的界面url為空");

LogTool.AddLogString("顯示h5的界面url為空");

if (errorCallBack != null) errorCallBack();

return;

}

string param = "?";

foreach (var item in url_param)

{

if (string.IsNullOrEmpty(item.Key) || string.IsNullOrEmpty(item.Value)) continue;

param += item.Key + "=" + item.Value + "&";

}

h5_url += param.TrimEnd('&');

h5_url = h5_url.Replace(" ", "");

ShowH5(h5_url, OnReceivedMessage, OnWebViewShouldClose);

}

/// /// 顯示H5界面

///

///

public void ShowH5(string h5_url, UniWebView.ReceivedMessageDelegate OnReceivedMessage, UniWebView.WebViewShouldCloseDelegate OnWebViewShouldClose)

{

if (string.IsNullOrEmpty(h5_url))

{

//Debug.Log("顯示h5的界面url為空");

LogTool.AddLogString("顯示h5的界面url為空");

if (errorCallBack != null) errorCallBack();

return;

}

isShowH5 = true;

data = new H5Data() { h5_url = h5_url, OnReceivedMessage = OnReceivedMessage, OnWebViewShouldClose = OnWebViewShouldClose };

uniWebView.OnLoadComplete += OnLoadComplete;

loadingGo.SetActive(true);

uniWebView.Load(h5_url);

uniWebView.backButtonEnable = backButtonEnable;

uniWebView.SetShowSpinnerWhenLoading(false);

if (OnReceivedMessage != null)

uniWebView.OnReceivedMessage += OnReceivedMessage;

if (OnWebViewShouldClose != null)

uniWebView.OnWebViewShouldClose += OnWebViewShouldClose;

LogTool.AddLogString("h5的界面url:" + h5_url);

}

/// /// 加載頁面

///

///

///

///

private void OnLoadComplete(UniWebView webView, bool success, string errorMessage)

{

if(!success)

{

if (errorCallBack != null) errorCallBack();

Debug.Log("加載頁面失敗!!!!!!!" + errorMessage);

}

else

{

loadingGo.SetActive(false);

uniWebView.Show();

}

}

/// /// 關閉H5界面

///

public void CloseH5()

{

ClearUniWebView();

data = null;

isShowH5 = false;

//Debug.Log("關閉h5的界面url!!");

}

/// /// 清空UniWebView

///

private void ClearUniWebView()

{

backButtonEnable = false;

//uniWebView.CleanCache();

uniWebView.Hide();

Destroy(uniWebView);

Destroy(uniWebView.gameObject);

uniWebView = null;

}

private void OnApplicationPause(bool pause)

{

if(pause)

{

if (isShowH5 && data != null)

{

ClearUniWebView();

}

}

else

{

if(isShowH5 && data != null)

{

ShowH5(data.h5_url, data.OnReceivedMessage, data.OnWebViewShouldClose);

}

}

}

}

1.講解網站鏈接:https://blog.csdn.net/u010019717/article/details/52890644

2.官網鏈接:http://uniwebview.onevcat.com/

總結

以上是生活随笔為你收集整理的html5 调用unity,Unity调用UniWebView打开H5界面脚本的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。