|
|
|
|
|
|
get { return m_PlacedPrefab; } |
|
|
|
set { m_PlacedPrefab = value; } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public GameObject placedObject { get; private set; } |
|
|
|
public GameObject spawnedObject { get; private set; } |
|
|
|
ARSessionOrigin m_SessionOrigin; |
|
|
|
|
|
|
|
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>(); |
|
|
|
|
|
|
|
void Awake() |
|
|
|
{ |
|
|
|
m_SessionOrigin = GetComponent<ARSessionOrigin>(); |
|
|
|
|
|
|
{ |
|
|
|
if (Input.touchCount == 0) |
|
|
|
return; |
|
|
|
|
|
|
|
var touch = Input.GetTouch(0); |
|
|
|
|
|
|
|
var hits = s_RaycastHits; |
|
|
|
|
|
|
|
if (!m_SessionOrigin.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon)) |
|
|
|
return; |
|
|
|
|
|
|
|
placementHit = hits[0]; |
|
|
|
} |
|
|
|
|
|
|
|
ARSessionOrigin m_SessionOrigin; |
|
|
|
|
|
|
|
ARRaycastHit m_PlacementHit; |
|
|
|
|
|
|
|
ARRaycastHit placementHit |
|
|
|
{ |
|
|
|
get { return m_PlacementHit; } |
|
|
|
set |
|
|
|
if (Input.touchCount > 0) |
|
|
|
m_PlacementHit = value; |
|
|
|
Touch touch = Input.GetTouch(0); |
|
|
|
if (placedObject == null && m_PlacedPrefab != null) |
|
|
|
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon)) |
|
|
|
placedObject = Instantiate(m_PlacedPrefab); |
|
|
|
} |
|
|
|
Pose hitPose = s_Hits[0].pose; |
|
|
|
if (placedObject != null) |
|
|
|
{ |
|
|
|
var pose = m_PlacementHit.pose; |
|
|
|
placedObject.transform.position = pose.position; |
|
|
|
placedObject.transform.rotation = pose.rotation; |
|
|
|
if (spawnedObject == null) |
|
|
|
{ |
|
|
|
spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
spawnedObject.transform.position = hitPose.position; |
|
|
|
} |
|
|
|
|
|
|
|
List<ARRaycastHit> s_RaycastHits = new List<ARRaycastHit>(); |
|
|
|
} |