UniWebView插件适用于安卓和iOS端,在PC无法使用。
解决按到返回键导致无法打开Web页面的方法: 每次打开web页面都使用一个新的uniwebview组件。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class web : MonoBehaviour
{
public Transform WebParent; //存放web组件预制体的父节点
public RectTransform Panel; //web 页面打开的位置
private GameObject go;
private UniWebView web1;
void Start()
{
go = Resources.Load<GameObject>("UniWebView");
}
public void Open()
{
for (int i = WebParent.childCount-1; i >=0; i--)
{
Destroy(WebParent.GetChild(i).gameObject);
}
GameObject a = Instantiate(go, WebParent);
web1 = a.GetComponent<UniWebView>();
web1.ReferenceRectTransform = Panel;
web1.Show();
web1.Load("https://www.baidu.com");
}
public void close()
{
web1.Hide();
}
}