using UnityEngine; using UnityEngine.SceneManagement; public class WebViewController : MonoBehaviour { private UniWebView webView; private void Start() { SceneManager.LoadScene(1, LoadSceneMode.Additive); var webViewGameObject = new GameObject("UniWebView"); webView = webViewGameObject.AddComponent(); webView.SetUserAgent(webView.GetUserAgent() + "app"); webView.Frame = new Rect(0, 0, Screen.width, Screen.height); webView.OnOrientationChanged += (view, orientation) => { webView.Frame = new Rect(0, 0, Screen.width, Screen.height); }; webView.OnMessageReceived += (view, message) => { if (message.Path == "facelogin") { this.FaceLogin(); } }; webView.OnShouldClose += (view) => { webView = null; return true; }; // webView.CleanCache(); webView.Load(UniWebViewHelper.StreamingAssetURLForPath("wwwroot/index.html")); webView.Show(); } private void OnRectTransformDimensionsChange() { webView.UpdateFrame(); } //private void OnEnable() //{ // webView.Show(); //} private void OnDestroy() { CloseWebView(); } // private void FaceLogin() { webView.Hide(); SceneManager.LoadScene(1); } private void CloseWebView() { Destroy(webView); webView = null; } }