AR + GPS Location  3.0.0
All Classes Namespaces Functions Variables Properties Events Pages
DevCameraController.cs
1 using UnityEngine;
2 using UnityEngine.Serialization;
3 
4 namespace ARLocation.Utils
5 {
6 
7  public class DevCameraController : MonoBehaviour
8  {
12  public float MouseSensitivity = 1.0f;
13 
17  [FormerlySerializedAs("speed")] public float Speed = 1.0f;
18 
19  // Current orientation parameters
20  float rotationY;
21  float rotationX;
22 
23  // The initial location
24  Location firstLocation;
25 
26  // The accumulated lat/lng displacement
27  private Vector3 accumDelta;
28 
29  // Use this for initialization
30  void Awake()
31  {
32  // If we are not running on a device, make this the main
33  // camera, else, self-destruct.
34  if (!Misc.IsARDevice())
35  {
36  var arCamera = GameObject.Find("AR Camera");
37 
38  if (arCamera != null)
39  {
40  arCamera.tag = "Untagged";
41  arCamera.SetActive(false);
42  }
43 
44  GetComponent<Camera>().gameObject.SetActive(true);
45 
46  GameObject o;
47  (o = gameObject).AddComponent<AudioListener>();
48  o.tag = "MainCamera";
49 
50  ARLocationManager.Instance.WaitForARTrackingToStart = false;
51  }
52  else
53  {
54  Destroy(gameObject);
55  }
56 
57  var rotation = transform.rotation;
58  rotationX = rotation.eulerAngles.x;
59  rotationY = rotation.eulerAngles.y;
60  }
61 
62  // Update is called once per frame
63  void Update()
64  {
65  var forward = Vector3.ProjectOnPlane(transform.forward, new Vector3(0, 1, 0));
66 
67  var initialPosition = transform.position;
68 
69  if (Input.GetKey("w"))
70  {
71  transform.Translate(
72  forward * Speed, Space.World
73  );
74  }
75 
76  if (Input.GetKey("s"))
77  {
78  transform.Translate(
79  -forward * Speed, Space.World
80  );
81  }
82 
83  if (Input.GetKey("d"))
84  {
85  transform.Translate(
86  transform.right * Speed, Space.World
87  );
88  }
89 
90  if (Input.GetKey("a"))
91  {
92  transform.Translate(
93  -transform.right * Speed, Space.World
94  );
95  }
96 
97  if (Input.GetKey("up"))
98  {
99  transform.Translate(
100  transform.up * Speed, Space.World
101  );
102  }
103 
104  var finalPosition = transform.position;
105  var delta = finalPosition - initialPosition;
106 
107  var locMngr = ARLocationProvider.Instance;
108 
109  if (firstLocation == null)
110  {
111  firstLocation = locMngr.CurrentLocation.ToLocation();
112  }
113 
114  accumDelta += delta * 0.00001f;
115 
116  //locMngr.UpdateMockLocation(new Location(
117  // firstLocation.latitude + accumDelta.z,
118  // firstLocation.longitude + accumDelta.x,
119  // 0
120  //));
121 
122  rotationY += Input.GetAxis("Mouse X") * MouseSensitivity;
123  rotationX -= Input.GetAxis("Mouse Y") * MouseSensitivity;
124 
125  transform.localRotation = Quaternion.Euler(rotationX, rotationY, 0);
126  }
127  }
128 }
ARLocation.ARLocationManager
This Component manages all positioned GameObjects, synchronizing their world position in the scene wi...
Definition: ARLocationManager.cs:30
ARLocation.Utils.DevCameraController.MouseSensitivity
float MouseSensitivity
The mouse look/rotation sensitivity.
Definition: DevCameraController.cs:12
ARLocation.Utils.Misc
Definition: Misc.cs:7
ARLocation.Location
Represents a geographical location.
Definition: Location.cs:19
ARLocation.Utils.Singleton.Instance
static T Instance
Access singleton instance through this propriety.
Definition: Singleton.cs:18
ARLocation.Utils
Definition: CreatePointOfInterestTextMeshes.cs:9
ARLocation.Utils.DevCameraController.Speed
float Speed
The walking speed
Definition: DevCameraController.cs:17
ARLocation.Utils.DevCameraController
Definition: DevCameraController.cs:8