Last active
December 16, 2022 13:23
-
-
Save kamend/cea52cb940e52eb0f33337b66eb43c44 to your computer and use it in GitHub Desktop.
XR Interaction Toolkit: Custom ARPlacementInteractable to place object with the left mouse button when in the Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.XR.Interaction.Toolkit.AR; | |
public class CustomPlacementInteractable : ARPlacementInteractable | |
{ | |
ARObjectPlacementEventArgs m_ObjectPlacementEventArgs = new ARObjectPlacementEventArgs(); | |
void Update() | |
{ | |
if (Input.GetMouseButtonDown(0)) | |
{ | |
MousePressed(Input.mousePosition); | |
} | |
} | |
TapGesture GenerateTapGestureFromPosition(Vector2 p) | |
{ | |
Touch t = new Touch(); | |
t.position = p; | |
TapGesture tp = new TapGesture(new TapGestureRecognizer(), t); | |
return tp; | |
} | |
void MousePressed(Vector2 p) | |
{ | |
var tp = GenerateTapGestureFromPosition(p); | |
if (TryGetPlacementPose(tp, out var pose)) | |
{ | |
var placementObject = PlaceObject(pose); | |
m_ObjectPlacementEventArgs.placementInteractable = this; | |
m_ObjectPlacementEventArgs.placementObject = placementObject; | |
OnObjectPlaced(m_ObjectPlacementEventArgs); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment