|
|
|
|
|
|
[RequireComponent(typeof(ARSessionOrigin))] |
|
|
|
public class PlaceMultipleObjectsOnPlane : MonoBehaviour |
|
|
|
{ |
|
|
|
[SerializeField] |
|
|
|
[Tooltip("Instantiates this prefab on a plane at the touch location.")] |
|
|
|
GameObject m_PlacedPrefab; |
|
|
|
[SerializeField] |
|
|
|
[Tooltip("Instantiates this prefab on a plane at the touch location.")] |
|
|
|
GameObject m_PlacedPrefab; |
|
|
|
/// <summary>
|
|
|
|
/// The prefab to instantiate on touch.
|
|
|
|
/// </summary>
|
|
|
|
public GameObject placedPrefab |
|
|
|
{ |
|
|
|
get { return m_PlacedPrefab; } |
|
|
|
set { m_PlacedPrefab = value; } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The object instantiated as a result of a successful raycast intersection with a plane.
|
|
|
|
/// </summary>
|
|
|
|
public GameObject spawnedObject { get; private set; } |
|
|
|
/// <summary>
|
|
|
|
/// The prefab to instantiate on touch.
|
|
|
|
/// </summary>
|
|
|
|
public GameObject placedPrefab |
|
|
|
{ |
|
|
|
get { return m_PlacedPrefab; } |
|
|
|
set { m_PlacedPrefab = value; } |
|
|
|
} |
|
|
|
ARSessionOrigin m_SessionOrigin; |
|
|
|
|
|
|
|
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>(); |
|
|
|
|
|
|
|
public delegate void PlacedObject(); |
|
|
|
|
|
|
|
private static Action s_PlacedObject; |
|
|
|
/// <summary>
|
|
|
|
/// The object instantiated as a result of a successful raycast intersection with a plane.
|
|
|
|
/// </summary>
|
|
|
|
public GameObject spawnedObject { get; private set; } |
|
|
|
public static event Action onPlacedObject; |
|
|
|
|
|
|
|
void Awake() |
|
|
|
{ |
|
|
|
m_SessionOrigin = GetComponent<ARSessionOrigin>(); |
|
|
|
} |
|
|
|
ARSessionOrigin m_SessionOrigin; |
|
|
|
void Update() |
|
|
|
{ |
|
|
|
if (Input.touchCount > 0) |
|
|
|
{ |
|
|
|
Touch touch = Input.GetTouch(0); |
|
|
|
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>(); |
|
|
|
if (touch.phase == TouchPhase.Began) |
|
|
|
{ |
|
|
|
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon)) |
|
|
|
{ |
|
|
|
Pose hitPose = s_Hits[0].pose; |
|
|
|
public delegate void PlacedObject(); |
|
|
|
spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation); |
|
|
|
private static Action s_PlacedObject; |
|
|
|
if (onPlacedObject != null) |
|
|
|
{ |
|
|
|
onPlacedObject(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public static event Action onPlacedObject; |
|
|
|
|
|
|
|
void Awake() |
|
|
|
{ |
|
|
|
m_SessionOrigin = GetComponent<ARSessionOrigin>(); |
|
|
|
} |
|
|
|
|
|
|
|
void Update() |
|
|
|
{ |
|
|
|
if (Input.touchCount > 0) |
|
|
|
{ |
|
|
|
Touch touch = Input.GetTouch(0); |
|
|
|
|
|
|
|
if (touch.phase == TouchPhase.Began) |
|
|
|
{ |
|
|
|
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon)) |
|
|
|
{ |
|
|
|
Pose hitPose = s_Hits[0].pose; |
|
|
|
|
|
|
|
spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation); |
|
|
|
|
|
|
|
if (onPlacedObject != null) |
|
|
|
{ |
|
|
|
onPlacedObject(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |