Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PointerDown and PointerUp Handling #204

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 143832582}
m_RootOrder: 1
Expand Down Expand Up @@ -284,6 +285,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1895741750}
- {fileID: 97853871}
Expand Down Expand Up @@ -337,6 +339,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2092252165}
m_RootOrder: 0
Expand Down Expand Up @@ -471,6 +474,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 963194228}
m_Father: {fileID: 0}
Expand Down Expand Up @@ -565,6 +569,7 @@ Transform:
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
Expand Down Expand Up @@ -609,6 +614,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
Expand Down Expand Up @@ -695,6 +701,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 340263451}
m_RootOrder: 0
Expand Down Expand Up @@ -734,6 +741,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7a21b486d0bb44444b1418aaa38b44de, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SendPointerHoverToParent: 1
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
Expand Down Expand Up @@ -790,6 +798,7 @@ RectTransform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 1.5}
m_LocalScale: {x: 0.001, y: 0.001, z: 0.001}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1187233980}
- {fileID: 2092252165}
Expand Down Expand Up @@ -1180,6 +1189,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 143832582}
m_Father: {fileID: 1054508623}
Expand Down Expand Up @@ -1219,6 +1229,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1959170144}
m_Father: {fileID: 1054508623}
Expand Down Expand Up @@ -1352,6 +1363,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1054508623}
m_Father: {fileID: 0}
Expand Down Expand Up @@ -1503,6 +1515,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 143832582}
m_RootOrder: 0
Expand Down Expand Up @@ -1540,6 +1553,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1306366453}
m_RootOrder: 0
Expand Down Expand Up @@ -1673,6 +1687,21 @@ MonoBehaviour:
BackButton: {fileID: 2092252166}
GoButton: {fileID: 1306366454}
URLField: {fileID: 1187233977}
Collider: {fileID: 2082689498}
--- !u!64 &2082689498
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2082689487}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &2092252164
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1702,6 +1731,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 165517765}
m_Father: {fileID: 1054508623}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
using TMPro;
using System;

public class WebViewBrowser : MonoBehaviour
using Microsoft.MixedReality.Toolkit.Input;

public class WebViewBrowser : MonoBehaviour, IMixedRealityPointerHandler
{
// Declare UI elements: back button, go button, and URL input field
public Button BackButton;
public Button GoButton;
public TMP_InputField URLField;
public MeshCollider Collider;
private IWebView _webView;

private void Start()
{
// Get the WebView component attached to the game object
var webViewComponent = gameObject.GetComponent<WebView>();
webViewComponent.GetWebViewWhenReady((IWebView webView) =>
{
_webView = webView;

// If the WebView supports browser history, enable the back button
if (webView is IWithBrowserHistory history)
{
Expand Down Expand Up @@ -52,4 +58,55 @@ private void CanGoBack(bool value)
{
BackButton.enabled = value;
}

public void OnPointerDown(MixedRealityPointerEventData eventData)
{
TranslateToWebViewMouseEvent(eventData, WebViewMouseEventData.EventType.MouseDown);
}

public void OnPointerUp(MixedRealityPointerEventData eventData)
{
TranslateToWebViewMouseEvent(eventData, WebViewMouseEventData.EventType.MouseUp);
}

private void TranslateToWebViewMouseEvent(MixedRealityPointerEventData eventData, WebViewMouseEventData.EventType evenType)
{
var hitCoord = NormalizeWorldPoint(eventData.Pointer.Result.Details.Point);

hitCoord.x *= _webView.Width;
hitCoord.y *= _webView.Height;

var mouseEventsWebView = _webView as IWithMouseEvents;
WebViewMouseEventData mouseEvent = new WebViewMouseEventData
{
X = (int)hitCoord.x,
Y = (int)hitCoord.y,
Device = WebViewMouseEventData.DeviceType.Pointer,
Type = evenType,
Button = WebViewMouseEventData.MouseButton.ButtonLeft,
TertiaryAxisDeviceType = WebViewMouseEventData.TertiaryAxisDevice.PointingDevice
};

mouseEventsWebView.MouseEvent(mouseEvent);
}

private Vector2 NormalizeWorldPoint(Vector3 worldPoint)
{
// Convert the world point to our control's local space.
Vector3 localPoint = transform.InverseTransformPoint(worldPoint);

var boundsSize = Collider.sharedMesh.bounds.size;
var boundsExtents = Collider.sharedMesh.bounds.max;

// Adjust the point to be based on a 0,0 origin.
var uvTouchPoint = new Vector2((localPoint.x + boundsExtents.x), -1.0f * (localPoint.y - boundsExtents.y));

// Normalize the point so it can be mapped to the WebView's texture.
var normalizedPoint = new Vector2(uvTouchPoint.x / boundsSize.x, uvTouchPoint.y / boundsSize.y);

return normalizedPoint;
}

public void OnPointerClicked(MixedRealityPointerEventData eventData) { }
public void OnPointerDragged(MixedRealityPointerEventData eventData) { }
}
Loading