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
69 lines
1.9 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.XR.ARFoundation;
|
|
|
|
public class Object_Control : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private PlacementObject[] placedObjects;
|
|
|
|
[SerializeField]
|
|
private Camera arCamera;
|
|
|
|
[SerializeField]
|
|
private GameObject gameObject;
|
|
private Vector2 touchPosition = default;
|
|
|
|
private ARRaycastManager aRRaycastManager;
|
|
|
|
private bool is_Hold = false;
|
|
[SerializeField]
|
|
private float maxDistanceOnSelection = 25.0f;
|
|
|
|
static List<ARRaycastHit> hits = new List<ARRaycastHit>();
|
|
void Update()
|
|
{
|
|
// do not capture events unless the welcome panel is hidden
|
|
|
|
if (Input.touchCount > 0)
|
|
{
|
|
Touch touch = Input.GetTouch(0);
|
|
|
|
if (touch.phase == TouchPhase.Began)
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(touch.position);
|
|
RaycastHit hitObj; ;
|
|
|
|
if(Physics.Raycast(ray,out hitObj, maxDistanceOnSelection))
|
|
{
|
|
if (hitObj.transform.name.Contains("PlaceObject"))
|
|
{
|
|
is_Hold = true;
|
|
}
|
|
}
|
|
}
|
|
if(touch.phase == TouchPhase.Moved)
|
|
{
|
|
touchPosition = touch.position;
|
|
}
|
|
if(touch.phase == TouchPhase.Ended)
|
|
{
|
|
is_Hold = false;
|
|
}
|
|
}
|
|
if (is_Hold)
|
|
{
|
|
if (aRRaycastManager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.All))
|
|
{
|
|
Pose hitPose = hits[0].pose;
|
|
gameObject.transform.position = hitPose.position;
|
|
gameObject.transform.rotation = hitPose.rotation;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|