RaycastHit
This feature is particularly useful for full-screen single-page applications; you don’t need to create multiple WebViews to implement pop-ups and other functionalities. Other Unity WebViews, although transparent, can obstruct Unity’s UGUI events, preventing the realization of single-page programs. However, UWebView2 solves this problem.
tip
It utilizes Unity's native UGUI event system(EventSystem.current.IsPointerOverGameObject), requiring no modifications to the project settings.
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<img src="./leaf.png" width="1024"/>
</body>
</html>
The effect after the HTML is loaded is as shown in the figure below.
Next Step
tip
The event will only be triggered when the mouse enters the red area.
It is based on the detection of the alpha channel in the render cache, rather than the rectangular size of the HTML elements.
Mouse event checking
if(EventSystem.current.IsPointerOverGameObject() == true)
{
Debug.Log("The mouse position is within the red area.")
}