207 lines
7.1 KiB
C#
207 lines
7.1 KiB
C#
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();
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// 使用工具打开链接
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
//public void OpenToolWeb(string url)
|
|
//{
|
|
// if (_focusedPrefab == null)
|
|
// CreatView(url);
|
|
// else
|
|
// _focusedPrefab.gameObject.SetActive(true);
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 打开外部链接
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
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 = @"
|
|
// <body>
|
|
// <style>
|
|
// body {
|
|
// font-family: sans-serif;
|
|
// display: flex;
|
|
// justify-content: center;
|
|
// align-items: center;
|
|
// line-height: 1.25;
|
|
// }
|
|
// div {
|
|
// max-width: 80%;
|
|
// }
|
|
// li {
|
|
// margin: 10px 0;
|
|
// }
|
|
// </style>
|
|
// <div>
|
|
// <p>
|
|
// Sorry, but this 3D WebView package doesn't support yet the <a href='https://developer.vuplex.com/webview/IWithPopups'>IWithPopups</a> interface. Current packages that support popups:
|
|
// </p>
|
|
// <ul>
|
|
// <li>
|
|
// <a href='https://developer.vuplex.com/webview/StandaloneWebView'>3D WebView for Windows and macOS</a>
|
|
// </li>
|
|
// <li>
|
|
// <a href='https://developer.vuplex.com/webview/AndroidWebView'>3D WebView for Android</a>
|
|
// </li>
|
|
// <li>
|
|
// <a href='https://developer.vuplex.com/webview/AndroidGeckoWebView'>3D WebView for Android with Gecko Engine</a>
|
|
// </li>
|
|
// </ul>
|
|
// </div>
|
|
// </body>
|
|
// ";
|
|
}
|