using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class Placer : MonoBehaviour
{
[Header(“AR”)]
[SerializeField] ARRaycastManager raycastManager;
[SerializeField] GameObject blindsPrefab;
[SerializeField] Camera raycastCamera;
private GameObject visual;
private List<ARRaycastHit> hits = new List<ARRaycastHit>();
// Start is called before the first frame update
void Start()
{
raycastManager = FindObjectOfType<ARRaycastManager>();
visual = transform.GetChild(0).gameObject;
visual.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0) && !IsClickOverUI())
{
Ray ray = raycastCamera.ScreenPointToRay(Input.mousePosition);
if (raycastManager.Raycast(ray, hits, TrackableType.Planes))
{
Pose pose = hits[0].pose;
foreach (GameObject gameObject in blindsPrefab)
{
if (FindObjectOfType<ToggleAR>().isOn)
{
gameObject.transform.SetPositionAndRotation(pose.position, pose.rotation);
if (!visual.activeInHierarchy)
visual.SetActive(true);
}
}
}
}
}
bool IsClickOverUI()
{
PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
pointerEventData.position = Input.mousePosition;
List<RaycastResult> raycastResults = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerEventData, raycastResults);
for (int i = 0; i < raycastResults.Count; i++)
{
if (raycastResults*.gameObject.GetComponent<MouseOverClickThrough>() != null)*
-
{*
-
raycastResults.RemoveAt(i);*
-
i--;*
-
}*
-
}*
-
return raycastResults.Count > 0;*
- }*
}