AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
TapToPlaceScene.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity
8 {
12  public class TapToPlaceScene : MonoBehaviour, IInputClickHandler
13  {
14  public float DistanceFromHead = 1.0f;
15 
16  public bool Placing = true;
17 
18  Quaternion initialRotation;
19 
20  public void SetPlacing(bool placing)
21  {
22  this.Placing = placing;
23  }
24 
25  private void OnEnable()
26  {
27  this.initialRotation = this.transform.rotation;
28  }
29 
30  void Update()
31  {
32  if (Placing)
33  {
34  var cameraTransform = CameraCache.Main.transform;
35  var headPosition = cameraTransform.position;
36  var forward = cameraTransform.forward;
37  var scenePosition = headPosition + DistanceFromHead * forward;
38 
39  var facingRotation = cameraTransform.localRotation * this.initialRotation;
40  //only yaw
41  facingRotation.x = 0;
42  facingRotation.z = 0;
43 
44  this.transform.position = scenePosition;
45  this.transform.rotation = facingRotation;
46  }
47 
48  if (Input.GetMouseButtonDown(0))
49  {
50  Placing = false;
51  }
52  }
53 
54  public void OnInputClicked(InputClickedEventData eventData)
55  {
56  Placing = false;
57  }
58  }
59 }
void OnInputClicked(InputClickedEventData eventData)
Lightweight game object placement
Interface to implement to react to simple click input.
The purpose of this class is to provide a cached reference to the main camera. Calling Camera...
Definition: CameraCache.cs:12
static Camera Main
Returns a cached reference to the main camera and uses Camera.main if it hasn't been cached yet...
Definition: CameraCache.cs:20
Describes an input event that involves a tap.