You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.5 KiB
87 lines
2.5 KiB
using System.IO.Ports;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class WebViewController : MonoBehaviour
|
|
|
|
{
|
|
private UniWebView webView;
|
|
private SerialDevice _sp;
|
|
|
|
public static string Token { get; set; }
|
|
public static string FaceLoginUrl { get; set; }
|
|
|
|
private void Start()
|
|
{
|
|
UniWebView.SetWebContentsDebuggingEnabled(true);
|
|
UniWebView.SetAllowAutoPlay(true);
|
|
UniWebView.SetAllowInlinePlay(true);
|
|
var webViewGameObject = new GameObject("UniWebView");
|
|
webView = webViewGameObject.AddComponent<UniWebView>();
|
|
webView.SetCalloutEnabled(false);
|
|
webView.SetUserAgent(webView.GetUserAgent() + " isapp" + "|is" + Application.platform.ToString().ToLower());
|
|
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.OnShouldClose += (view) =>
|
|
{
|
|
webView = null;
|
|
return true;
|
|
};
|
|
webView.OnPageFinished += WebView_OnPageFinished;
|
|
webView.OnPageErrorReceived += WebView_OnPageErrorReceived;
|
|
webView.OnMessageReceived += WebView_OnMessageReceived;
|
|
//
|
|
webView.CleanCache();
|
|
//webView.Load("http://192.168.31.155");
|
|
webView.Load(UniWebViewHelper.StreamingAssetURLForPath("wwwroot/index.html"));
|
|
webView.Show();
|
|
}
|
|
|
|
private void WebView_OnMessageReceived(UniWebView webView, UniWebViewMessage message)
|
|
{
|
|
if (message.Path == "config")
|
|
{
|
|
webView.Load(UniWebViewHelper.StreamingAssetURLForPath("wwwroot/config.html"));
|
|
}
|
|
}
|
|
|
|
private void WebView_OnPageErrorReceived(UniWebView webView, int errorCode, string errorMessage)
|
|
{
|
|
webView.Load(UniWebViewHelper.StreamingAssetURLForPath($"wwwroot/config.html#{errorCode}-{errorMessage}-{webView.Url}"));
|
|
}
|
|
|
|
private void WebView_OnPageFinished(UniWebView webView, int statusCode, string url)
|
|
{
|
|
Debug.Log(url);
|
|
Debug.Log(statusCode);
|
|
}
|
|
|
|
private void OnRectTransformDimensionsChange()
|
|
{
|
|
webView.UpdateFrame();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
CloseWebView();
|
|
}
|
|
|
|
private void FaceLogin()
|
|
{
|
|
SceneManager.LoadScene(1);
|
|
}
|
|
|
|
private void CloseWebView()
|
|
{
|
|
Destroy(webView);
|
|
webView = null;
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
} |