浏览代码

Convert tabs to spaces and remove extra whitespace.

/1.5-preview
Tim Mowrer 6 年前
当前提交
05ed8029
共有 1 个文件被更改,包括 48 次插入48 次删除
  1. 96
      Assets/Scripts/PlaceMultipleObjectsOnPlane.cs

96
Assets/Scripts/PlaceMultipleObjectsOnPlane.cs


[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();
}
}
}
}
}
}
正在加载...
取消
保存