浏览代码

Update PlaceOnPlane script to emulate touch with mouse clicks.

/2.1
Tim Mowrer 6 年前
当前提交
24a0ec90
共有 1 个文件被更改,包括 25 次插入6 次删除
  1. 31
      Assets/Scripts/PlaceOnPlane.cs

31
Assets/Scripts/PlaceOnPlane.cs


/// <summary>
/// Listens for touch events and performs an AR raycast from the screen touch point.
/// AR raycasts will only hit detected trackables like feature points and planes.
///
///
/// If a raycast hits a trackable, the <see cref="placedPrefab"/> is instantiated
/// and moved to the hit position.
/// </summary>

get { return m_PlacedPrefab; }
set { m_PlacedPrefab = value; }
}
/// <summary>
/// The object instantiated as a result of a successful raycast intersection with a plane.
/// </summary>

m_RaycastManager = GetComponent<ARRaycastManager>();
}
bool TryGetTouchPosition(out Vector2 touchPosition)
{
#if UNITY_EDITOR
if (Input.GetMouseButton(0))
{
var mousePosition = Input.mousePosition;
touchPosition = new Vector2(mousePosition.x, mousePosition.y);
return true;
}
#else
if (Input.touchCount > 0)
{
touchPosition = Input.GetTouch(0).position;
return true;
}
#endif
touchPosition = default;
return false;
}
if (Input.touchCount == 0)
if (!TryGetTouchPosition(out Vector2 touchPosition))
var touch = Input.GetTouch(0);
if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
if (m_RaycastManager.Raycast(touchPosition, s_Hits, TrackableType.PlaneWithinPolygon))
{
// Raycast hits are sorted by distance, so the first one
// will be the closest hit.

正在加载...
取消
保存