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.

69 lines
1.9 KiB

4 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.XR.ARFoundation;
  7. public class Object_Control : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private PlacementObject[] placedObjects;
  11. [SerializeField]
  12. private Camera arCamera;
  13. [SerializeField]
  14. private GameObject gameObject;
  15. private Vector2 touchPosition = default;
  16. private ARRaycastManager aRRaycastManager;
  17. private bool is_Hold = false;
  18. [SerializeField]
  19. private float maxDistanceOnSelection = 25.0f;
  20. static List<ARRaycastHit> hits = new List<ARRaycastHit>();
  21. void Update()
  22. {
  23. // do not capture events unless the welcome panel is hidden
  24. if (Input.touchCount > 0)
  25. {
  26. Touch touch = Input.GetTouch(0);
  27. if (touch.phase == TouchPhase.Began)
  28. {
  29. Ray ray = Camera.main.ScreenPointToRay(touch.position);
  30. RaycastHit hitObj; ;
  31. if(Physics.Raycast(ray,out hitObj, maxDistanceOnSelection))
  32. {
  33. if (hitObj.transform.name.Contains("PlaceObject"))
  34. {
  35. is_Hold = true;
  36. }
  37. }
  38. }
  39. if(touch.phase == TouchPhase.Moved)
  40. {
  41. touchPosition = touch.position;
  42. }
  43. if(touch.phase == TouchPhase.Ended)
  44. {
  45. is_Hold = false;
  46. }
  47. }
  48. if (is_Hold)
  49. {
  50. if (aRRaycastManager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.All))
  51. {
  52. Pose hitPose = hits[0].pose;
  53. gameObject.transform.position = hitPose.position;
  54. gameObject.transform.rotation = hitPose.rotation;
  55. }
  56. }
  57. }
  58. }