TrackableManager.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace SC.XR.Unity
  7. {
  8. class TrackableManager : Singleton<TrackableManager>
  9. {
  10. private List<Trackable> allTrackables = new List<Trackable>();
  11. private Dictionary<int, Trackable> oldTrackableDic = new Dictionary<int, Trackable>();
  12. public void GetTrackables<T>(List<T> trackables, TrackableQueryFilter filter) where T : Trackable
  13. {
  14. trackables.Clear();
  15. switch (filter)
  16. {
  17. case TrackableQueryFilter.All:
  18. GetAllTrackable<T>(trackables);
  19. break;
  20. case TrackableQueryFilter.New:
  21. GetNewTrackable<T>(trackables);
  22. break;
  23. }
  24. }
  25. private void GetAllTrackable<T>(List<T> trackables) where T : Trackable
  26. {
  27. //TODO
  28. trackables.Clear();
  29. TrackableApi.GetPlaneInfo(trackables);
  30. RefreshOldTrackable(trackables);
  31. }
  32. private void GetNewTrackable<T>(List<T> trackables) where T : Trackable
  33. {
  34. //TODO
  35. allTrackables.Clear();
  36. trackables.Clear();
  37. TrackableApi.GetPlaneInfo(allTrackables);
  38. for (int i = 0; i < allTrackables.Count; i++)
  39. {
  40. Trackable trackable = allTrackables[i];
  41. if (!oldTrackableDic.ContainsKey(trackable.trackableId))
  42. {
  43. trackables.SafeAdd(trackable);
  44. }
  45. }
  46. RefreshOldTrackable(allTrackables);
  47. }
  48. private void RefreshOldTrackable<T>(List<T> trackables) where T : Trackable
  49. {
  50. oldTrackableDic.Clear();
  51. for (int i = 0; i < trackables.Count; i++)
  52. {
  53. Trackable trackable = trackables[i];
  54. oldTrackableDic[trackable.trackableId] = trackable;
  55. }
  56. }
  57. }
  58. }