using Adam; using System; using System.Threading.Tasks; using UnityEngine; using UnityEngine.EventSystems; using Vuplex.WebView; public class newfollow : MonoBehaviour { [SerializeField] string _name; public CanvasWebViewPrefab _focusedPrefab; public GameObject _canvas; public bool isOnce = true; public string url; private void Start() { OnClose(); url = WebIPAdress.Instance.dicAdresses["用采界面"]; } private void Update() { // 鼠标左键按下 if (Input.GetMouseButtonDown(0)) { // 从相机位置发射一条射线经过屏幕上的鼠标点击位置 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // 声明一个射线碰撞信息类 RaycastHit hit; // 进行碰撞检测 bool res = Physics.Raycast(ray, out hit) && !EventSystem.current.IsPointerOverGameObject(); if (res) { // 如果产生了碰撞 if (hit.transform.name.Equals(_name)) { Debug.Log(hit.transform.name); OpenWaiBuUrl(url); } } } //if (Input.GetKeyDown(KeyCode.Escape)) //{ // if (_focusedPrefab != null) // { // _focusedPrefab.gameObject.SetActive(false); // isOnce = true; // } //} //if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.C)) //{ // if (_focusedPrefab != null) // _focusedPrefab.WebView.Copy(); //} } /// /// 使用工具打开链接 /// /// //public void OpenToolWeb(string url) //{ // if (_focusedPrefab == null) // CreatView(url); // else // _focusedPrefab.gameObject.SetActive(true); //} /// /// 打开外部链接 /// /// public void OpenWaiBuUrl(string _url) { //Application.OpenURL(url); _focusedPrefab.InitialUrl = _url; _canvas.gameObject.SetActive(true); } public void OnClose() { _canvas.gameObject.SetActive(false); } //private void _setUpHardwareKeyboard() //{ // if (_hardwareKeyboard == null) // { // _hardwareKeyboard = HardwareKeyboardListener.Instantiate(); // _hardwareKeyboard.KeyDownReceived += (sender, eventArgs) => // { // var webViewWithKeyDown = _focusedPrefab.WebView as IWithKeyDownAndUp; // if (webViewWithKeyDown == null) // { // //_focusedPrefab.WebView.HandleKeyboardInput(eventArgs.Value); // } // else // { // webViewWithKeyDown.KeyDown(eventArgs.Value, eventArgs.Modifiers); // } // }; // } //} //private void CreatView(string _url) //{ // var mainWebViewPrefab = CanvasWebViewPrefab.Instantiate(); // mainWebViewPrefab.transform.SetParent(_canvas.transform, false); // var rectTransform = mainWebViewPrefab.transform as RectTransform; // rectTransform.anchoredPosition3D = Vector3.zero; // rectTransform.offsetMin = Vector2.zero; // rectTransform.offsetMax = Vector2.zero; // mainWebViewPrefab.transform.localScale = Vector3.one; // _focusedPrefab = mainWebViewPrefab; // mainWebViewPrefab.Initialized += (s, e) => // { // var webViewWithPopups = mainWebViewPrefab.WebView as IWithPopups; // if (webViewWithPopups == null) // { // mainWebViewPrefab.WebView.LoadHtml(NOT_SUPPORTED_HTML); // return; // } // mainWebViewPrefab.WebView.LoadUrl(_url); // webViewWithPopups.SetPopupMode(PopupMode.LoadInNewWebView); // webViewWithPopups.PopupRequested += (webView, eventArgs) => // { // var popupPrefab = CanvasWebViewPrefab.Instantiate(eventArgs.WebView); // _focusedPrefab = popupPrefab; // popupPrefab.transform.SetParent(_canvas.transform, false); // var popupRectTransform = popupPrefab.transform as RectTransform; // popupRectTransform.anchoredPosition3D = Vector3.zero; // popupRectTransform.offsetMin = Vector2.zero; // popupRectTransform.offsetMax = Vector2.zero; // popupPrefab.transform.localScale = Vector3.one; // // Place the popup in front of the main webview. // var localPosition = popupPrefab.transform.localPosition; // localPosition.z = 0.1f; // popupPrefab.transform.localPosition = localPosition; // popupPrefab.Initialized += (sender, initializedEventArgs) => // { // popupPrefab.WebView.CloseRequested += (popupWebView, closeEventArgs) => // { // _focusedPrefab = mainWebViewPrefab; // showAsync(); // popupPrefab.Destroy(); // }; // }; // }; // }; //} //private async void showAsync() //{ // //await Task.Delay(2000); // await _focusedPrefab.WaitUntilInitialized(); // //await _focusedPrefab.WebView.WaitForNextPageLoadToFinish(); // var headerText = await _focusedPrefab.WebView.ExecuteJavaScript("toggleVisibility()"); // _setUpHardwareKeyboard(); // Debug.Log("H1 text: " + headerText); //} //const string NOT_SUPPORTED_HTML = @" // // //
//

// Sorry, but this 3D WebView package doesn't support yet the IWithPopups interface. Current packages that support popups: //

// //
// // "; }