EditorHitTest.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEngine.XR.iOS
  5. {
  6. public class EditorHitTest : MonoBehaviour {
  7. public Transform m_HitTransform;
  8. public float maxRayDistance = 30.0f;
  9. public LayerMask collisionLayerMask;
  10. #if UNITY_EDITOR //we will only use this script on the editor side, though there is nothing that would prevent it from working on device
  11. void Update () {
  12. if (Input.GetMouseButtonDown (0)) {
  13. Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  14. RaycastHit hit;
  15. //we'll try to hit one of the plane collider gameobjects that were generated by the plugin
  16. //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent
  17. if (Physics.Raycast (ray, out hit, maxRayDistance, collisionLayerMask)) {
  18. //we're going to get the position from the contact point
  19. m_HitTransform.position = hit.point;
  20. Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));
  21. //and the rotation from the transform of the plane collider
  22. m_HitTransform.rotation = hit.transform.rotation;
  23. }
  24. }
  25. }
  26. #endif
  27. }
  28. }