浏览代码

refactored PlaceOnPlane, conformed to naming conventions

/1.5-preview
Dan Miller 7 年前
当前提交
45c24e1e
共有 2 个文件被更改,包括 15 次插入21 次删除
  1. 2
      Assets/Scenes/SampleScene.unity
  2. 34
      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,
placedPrefab: {fileID: 1934569588295450, guid: b34b6c8f1206a6844b983e23b9da0441,
type: 2}

34
Assets/Scripts/PlaceOnPlane.cs


public class PlaceOnPlane : MonoBehaviour
{
[SerializeField] [Tooltip("Instantiates this prefab on a plane at the touch location.")]
public GameObject PlacedPrefab;
public GameObject placedPrefab;
private List<ARRaycastHit> hits;
private bool spawnedPrefab = false;
private GameObject spawnedObject;
private ARSessionOrigin sessionOrigin;
List<ARRaycastHit> m_Hits;
GameObject m_SpawnedObject;
ARSessionOrigin m_SessionOrigin;
sessionOrigin = GetComponent<ARSessionOrigin>();
hits = new List<ARRaycastHit>();
m_SessionOrigin = GetComponent<ARSessionOrigin>();
m_Hits = new List<ARRaycastHit>();
}
void Update()

Touch touch = Input.GetTouch(0);
if (!spawnedPrefab)
if (m_SessionOrigin.Raycast(touch.position, m_Hits, TrackableType.PlaneWithinPolygon))
if (touch.phase == TouchPhase.Began)
Pose hitPose = m_Hits[0].pose;
if (m_SpawnedObject == null)
if (sessionOrigin.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
if (touch.phase == TouchPhase.Began)
Pose hitPose = hits[0].pose;
spawnedObject = Instantiate(PlacedPrefab, hitPose.position, hitPose.rotation);
spawnedPrefab = true;
m_SpawnedObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
}
else
{
if (sessionOrigin.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
else
Pose hitPose = hits[0].pose;
spawnedObject.transform.position = hitPose.position;
m_SpawnedObject.transform.position = hitPose.position;
}
}
}
正在加载...
取消
保存