using SC.XR.Unity; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using System.Linq; public class TrackablePlaneGenerator : MonoBehaviour { public GameObject trackablePlanePrefab; private List newPlanes = new List(); private List allPlanes = new List(); public Text text; private List trackableCache = new List(); #if UNITY_EDITOR public static bool twoPlane = false; #endif public void Update() { #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.O)) { twoPlane = false; } if (Input.GetKeyDown(KeyCode.T)) { twoPlane = true; } #endif //if (!GSXRManager.Instance.Initialized) //{ // return; //} text.text = API_GSXR_Slam.GSXR_Get_PanelNum().ToString(); TrackableManager.Instance.GetTrackables(newPlanes, TrackableQueryFilter.New); for (int i = 0; i < newPlanes.Count; i++) { GameObject trackablePlaneGameObject = Instantiate(trackablePlanePrefab); trackablePlaneGameObject.GetComponent().Init(newPlanes[i]); trackableCache.Add(trackablePlaneGameObject.GetComponent()); } TrackableManager.Instance.GetTrackables(allPlanes, TrackableQueryFilter.All); List tobeRemovePlane = trackableCache.Where((item) => { PlaneTrackable plane = allPlanes.Where((planeItem) => { return planeItem.trackableId == item.GetPlaneId(); }).FirstOrDefault(); return plane == null; }).ToList(); for (int i = 0; i < tobeRemovePlane.Count; i++) { trackableCache.Remove(tobeRemovePlane[i]); GameObject.Destroy(tobeRemovePlane[i].gameObject); } } }