1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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<PlaneTrackable> newPlanes = new List<PlaneTrackable>();
- private List<PlaneTrackable> allPlanes = new List<PlaneTrackable>();
- public Text text;
- private List<TrackablePlaneMono> trackableCache = new List<TrackablePlaneMono>();
- #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<PlaneTrackable>(newPlanes, TrackableQueryFilter.New);
- for (int i = 0; i < newPlanes.Count; i++)
- {
- GameObject trackablePlaneGameObject = Instantiate(trackablePlanePrefab);
- trackablePlaneGameObject.GetComponent<TrackablePlaneMono>().Init(newPlanes[i]);
- trackableCache.Add(trackablePlaneGameObject.GetComponent<TrackablePlaneMono>());
- }
- TrackableManager.Instance.GetTrackables<PlaneTrackable>(allPlanes, TrackableQueryFilter.All);
- List<TrackablePlaneMono> 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);
- }
- }
- }
|