|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Experimental.XR; |
|
|
|
using UnityEngine.XR.ARFoundation; |
|
|
|
|
|
|
|
[RequireComponent(typeof(ARSessionOrigin))] |
|
|
|
public class MakeAppearOnPlane : MonoBehaviour |
|
|
|
{ |
|
|
|
[SerializeField] |
|
|
|
Transform m_Content; |
|
|
|
|
|
|
|
public Transform content |
|
|
|
{ |
|
|
|
get { return m_Content; } |
|
|
|
set { m_Content = value; } |
|
|
|
} |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
Quaternion m_Rotation; |
|
|
|
|
|
|
|
public Quaternion rotation |
|
|
|
{ |
|
|
|
get { return m_Rotation; } |
|
|
|
set |
|
|
|
{ |
|
|
|
m_Rotation = value; |
|
|
|
if (m_SessionOrigin != null) |
|
|
|
m_SessionOrigin.MakeContentAppearAt(content, content.transform.position, m_Rotation); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Awake() |
|
|
|
{ |
|
|
|
m_SessionOrigin = GetComponent<ARSessionOrigin>(); |
|
|
|
} |
|
|
|
|
|
|
|
void Update() |
|
|
|
{ |
|
|
|
if (Input.touchCount == 0 || m_Content == null) |
|
|
|
return; |
|
|
|
|
|
|
|
var touch = Input.GetTouch(0); |
|
|
|
|
|
|
|
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon)) |
|
|
|
{ |
|
|
|
// Raycast hits are sorted by distance, so the first one
|
|
|
|
// will be the closest hit.
|
|
|
|
var hitPose = s_Hits[0].pose; |
|
|
|
|
|
|
|
m_SessionOrigin.MakeContentAppearAt(content, hitPose.position, m_Rotation); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>(); |
|
|
|
|
|
|
|
ARSessionOrigin m_SessionOrigin; |
|
|
|
} |