using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.XR.ARFoundation; /// /// This example demonstrates how to toggle plane detection, /// and also hide or show the existing planes. /// [RequireComponent(typeof(ARPlaneManager))] public class PlaneDetectionController : MonoBehaviour { [SerializeField] Text m_TogglePlaneDetectionText; /// /// Toggles plane detection and the visualization of the planes. /// public void TogglePlaneDetection() { m_ARPlaneManager.enabled = !m_ARPlaneManager.enabled; if (m_ARPlaneManager.enabled) { m_TogglePlaneDetectionText.text = "Disable Plane Detection and Hide Existing"; SetAllPlanesActive(true); } else { m_TogglePlaneDetectionText.text = "Enable Plane Detection and Show Existing"; SetAllPlanesActive(false); } } /// /// Iterates over all the existing planes and activates /// or deactivates their GameObjects'. /// /// Each planes' GameObject is SetActive with this value. void SetAllPlanesActive(bool value) { m_ARPlaneManager.GetAllPlanes(s_Planes); foreach (var plane in s_Planes) plane.gameObject.SetActive(value); } void Awake() { m_ARPlaneManager = GetComponent(); } ARPlaneManager m_ARPlaneManager; static List s_Planes = new List(); }