140 lines
5.3 KiB
C#
140 lines
5.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using Vuplex.WebView;
|
|
|
|
public class newfollow : MonoBehaviour
|
|
{
|
|
[SerializeField] string _name;
|
|
public CanvasWebViewPrefab _focusedPrefab;
|
|
public GameObject _canvas;
|
|
private void Start()
|
|
{
|
|
|
|
}
|
|
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);
|
|
CreatView();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
if (_focusedPrefab != null)
|
|
Destroy(_focusedPrefab.gameObject);
|
|
}
|
|
}
|
|
|
|
private void CreatView()
|
|
{
|
|
// Enable the native touch screen keyboard for Android and iOS.
|
|
Web.SetTouchScreenKeyboardEnabled(true);
|
|
|
|
//_canvas = GameObject.Find("Canvas");
|
|
// Create a webview for the main content.
|
|
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;
|
|
}
|
|
|
|
WebViewLogger.Log("Loading Pinterest as an example because it uses popups for third party login. Click 'Login', then select Facebook or Google to open a popup for authentication.");
|
|
mainWebViewPrefab.WebView.LoadUrl("http://111.229.30.246:10015/");
|
|
|
|
webViewWithPopups.SetPopupMode(PopupMode.LoadInNewWebView);
|
|
webViewWithPopups.PopupRequested += (webView, eventArgs) =>
|
|
{
|
|
WebViewLogger.Log("Popup opened with URL: " + eventArgs.Url);
|
|
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) =>
|
|
{
|
|
WebViewLogger.Log("Closing the popup");
|
|
_focusedPrefab = mainWebViewPrefab;
|
|
popupPrefab.Destroy();
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|
|
|
|
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>
|
|
";
|
|
}
|