fix:1、修复bug

This commit is contained in:
2026-07-14 17:56:40 +08:00
parent bb84cea894
commit 447c7b7bc7
17 changed files with 71 additions and 77 deletions
+35 -35
View File
@@ -23,40 +23,6 @@ public class FreeWebViewManager : MonoBehaviour
}
public void initView()
{
if (_webObj != null) return;
// 创建WebView对象
_webObj = new GameObject("WebViewObject1");
_webView = _webObj.AddComponent<WebViewObject1>();
// 关键:开启WKWebView,规避苹果审核拒绝
_webView.Init(
enableWKWebView: true,
cb: OnWebMessage // JS调用Unity回调
);
float top_offset = 0;//fgui中的顶部信息的高度
float buttom_offset = 155;
if (Screen.safeArea.y != 0)
{//刘海屏
top_offset += Screen.safeArea.y;
}
// 铺满屏幕,适配刘海安全区
_webView.SetMargins(0, (int)top_offset, 0, (int)buttom_offset);
// 禁止下拉回弹(可选)
_webView.SetScrollBounceEnabled(false);
_webView.LoadURL("about:blank");
_webView.SetVisibility(false);
}
/// <summary>
/// 打开网页
/// </summary>
public void OpenWeb(string url)
{
// if (_webObj != null) return;
//
@@ -82,6 +48,40 @@ public class FreeWebViewManager : MonoBehaviour
// // 禁止下拉回弹(可选)
// _webView.SetScrollBounceEnabled(false);
//
// _webView.LoadURL("about:blank");
// _webView.SetVisibility(false);
//
}
/// <summary>
/// 打开网页
/// </summary>
public void OpenWeb(string url)
{
if (_webObj != null) return;
// 创建WebView对象
_webObj = new GameObject("WebViewObject1");
_webView = _webObj.AddComponent<WebViewObject1>();
// 关键:开启WKWebView,规避苹果审核拒绝
_webView.Init(
enableWKWebView: true,
cb: OnWebMessage // JS调用Unity回调
);
float top_offset = 0;//fgui中的顶部信息的高度
float buttom_offset = 155;
if (Screen.safeArea.y != 0)
{//刘海屏
top_offset += Screen.safeArea.y;
}
// 铺满屏幕,适配刘海安全区
_webView.SetMargins(0, (int)top_offset, 0, (int)buttom_offset);
// 禁止下拉回弹(可选)
_webView.SetScrollBounceEnabled(false);
// 加载网页并显示
_webView.LoadURL(url);
_webView.SetVisibility(true);
@@ -107,7 +107,7 @@ public class FreeWebViewManager : MonoBehaviour
{
if (_webObj != null)
{
_webView.SetVisibility(false);
OnDestroy();
}
}