浏览代码

refactored PlaceOnPlane, made hits static

/1.5-preview
Dan Miller 7 年前
当前提交
fe6b48cb
共有 2 个文件被更改,包括 18 次插入8 次删除
  1. 2
      Assets/Scenes/SampleScene.unity
  2. 24
      Assets/Scripts/PlaceOnPlane.cs

2
Assets/Scenes/SampleScene.unity


m_Script: {fileID: 11500000, guid: 7d5359d5f13250e4485741ed685a32be, type: 3}
m_Name:
m_EditorClassIdentifier:
placedPrefab: {fileID: 1934569588295450, guid: b34b6c8f1206a6844b983e23b9da0441,
m_PlacedPrefab: {fileID: 1934569588295450, guid: b34b6c8f1206a6844b983e23b9da0441,
type: 2}

24
Assets/Scripts/PlaceOnPlane.cs


[RequireComponent(typeof(ARSessionOrigin))]
public class PlaceOnPlane : MonoBehaviour
{
[SerializeField] [Tooltip("Instantiates this prefab on a plane at the touch location.")]
public GameObject placedPrefab;
[SerializeField]
[Tooltip("Instantiates this prefab on a plane at the touch location.")]
GameObject m_PlacedPrefab;
List<ARRaycastHit> m_Hits;
/// <summary>
/// The prefab to instantiate on touch.
/// </summary>
public GameObject placedPrefab
{
get { return m_PlacedPrefab; }
set { m_PlacedPrefab = value; }
}
static List<ARRaycastHit> s_Hits;
GameObject m_SpawnedObject;
ARSessionOrigin m_SessionOrigin;

m_Hits = new List<ARRaycastHit>();
s_Hits = new List<ARRaycastHit>();
}
void Update()

Touch touch = Input.GetTouch(0);
if (m_SessionOrigin.Raycast(touch.position, m_Hits, TrackableType.PlaneWithinPolygon))
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
Pose hitPose = m_Hits[0].pose;
Pose hitPose = s_Hits[0].pose;
m_SpawnedObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
m_SpawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
}
}
else

正在加载...
取消
保存