RaycastSamples.cs
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
[TestFixture]
class RaycastSamples
{
#pragma warning disable CS0649
#region raycasthit_trackable
ARPlaneManager m_PlaneManager;
void HandleRaycast(ARRaycastHit hit)
{
// Determine if it is a plane
if ((hit.hitType & TrackableType.Planes) != 0)
{
// Look up the plane by id
var plane = m_PlaneManager.GetPlane(hit.trackableId);
// Do something with 'plane':
Debug.Log($"Hit a plane with alignment {plane.alignment}");
}
else
{
// What type of thing did we hit?
Debug.Log($"Raycast hit a {hit.hitType}");
}
}
#endregion
class UsingTouch : MonoBehaviour
{
#region raycast_using_touch
[SerializeField]
ARRaycastManager m_RaycastManager;
List<ARRaycastHit> m_Hits = new List<ARRaycastHit>();
void Update()
{
if (Input.touchCount == 0)
return;
if (m_RaycastManager.Raycast(Input.GetTouch(0).position, m_Hits))
{
// Only returns true if there is at least one hit
}
}
#endregion
}
#pragma warning restore CS0649
}
}