SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.4 KiB

4 years ago
  1. using UnityEngine;
  2. using UnityEngine.Serialization;
  3. namespace ARLocation.Utils
  4. {
  5. public class DevCameraController : MonoBehaviour
  6. {
  7. /// <summary>
  8. /// The mouse look/rotation sensitivity.
  9. /// </summary>
  10. public float MouseSensitivity = 1.0f;
  11. /// <summary>
  12. /// The walking speed
  13. /// </summary>
  14. [FormerlySerializedAs("speed")] public float Speed = 1.0f;
  15. // Current orientation parameters
  16. float rotationY;
  17. float rotationX;
  18. // The initial location
  19. Location firstLocation;
  20. // The accumulated lat/lng displacement
  21. private Vector3 accumDelta;
  22. // Use this for initialization
  23. void Awake()
  24. {
  25. // If we are not running on a device, make this the main
  26. // camera, else, self-destruct.
  27. if (!Misc.IsARDevice())
  28. {
  29. var arCamera = GameObject.Find("AR Camera");
  30. if (arCamera != null)
  31. {
  32. arCamera.tag = "Untagged";
  33. arCamera.SetActive(false);
  34. }
  35. GetComponent<Camera>().gameObject.SetActive(true);
  36. GameObject o;
  37. (o = gameObject).AddComponent<AudioListener>();
  38. o.tag = "MainCamera";
  39. }
  40. else
  41. {
  42. Destroy(gameObject);
  43. }
  44. var rotation = transform.rotation;
  45. rotationX = rotation.eulerAngles.x;
  46. rotationY = rotation.eulerAngles.y;
  47. }
  48. // Update is called once per frame
  49. void Update()
  50. {
  51. var forward = Vector3.ProjectOnPlane(transform.forward, new Vector3(0, 1, 0));
  52. var initialPosition = transform.position;
  53. if (Input.GetKey("w"))
  54. {
  55. transform.Translate(
  56. forward * Speed, Space.World
  57. );
  58. }
  59. if (Input.GetKey("s"))
  60. {
  61. transform.Translate(
  62. -forward * Speed, Space.World
  63. );
  64. }
  65. if (Input.GetKey("d"))
  66. {
  67. transform.Translate(
  68. transform.right * Speed, Space.World
  69. );
  70. }
  71. if (Input.GetKey("a"))
  72. {
  73. transform.Translate(
  74. -transform.right * Speed, Space.World
  75. );
  76. }
  77. if (Input.GetKey("up"))
  78. {
  79. transform.Translate(
  80. transform.up * Speed, Space.World
  81. );
  82. }
  83. var finalPosition = transform.position;
  84. var delta = finalPosition - initialPosition;
  85. var locMngr = ARLocationProvider.Instance;
  86. if (firstLocation == null)
  87. {
  88. firstLocation = locMngr.CurrentLocation.ToLocation();
  89. }
  90. accumDelta += delta * 0.00001f;
  91. //locMngr.UpdateMockLocation(new Location(
  92. // firstLocation.latitude + accumDelta.z,
  93. // firstLocation.longitude + accumDelta.x,
  94. // 0
  95. //));
  96. rotationY += Input.GetAxis("Mouse X") * MouseSensitivity;
  97. rotationX -= Input.GetAxis("Mouse Y") * MouseSensitivity;
  98. transform.localRotation = Quaternion.Euler(rotationX, rotationY, 0);
  99. }
  100. }
  101. }