PointsVisualizer.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. namespace NRKernal.NRExamples
  12. {
  13. /// <summary> The points visualizer. </summary>
  14. public class PointsVisualizer
  15. {
  16. /// <summary> The point entity. </summary>
  17. public List<GameObject> pointEntity = new List<GameObject>();
  18. /// <summary> Shows the given points. </summary>
  19. /// <param name="points"> The points.</param>
  20. public void Show(List<Vector3> points)
  21. {
  22. int objs_len = pointEntity.Count;
  23. int points_len = points.Count;
  24. if (objs_len < points_len)
  25. {
  26. for (int i = 0; i < points_len - objs_len; i++)
  27. {
  28. GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
  29. GameObject.Destroy(go.GetComponent<BoxCollider>());
  30. go.transform.localScale = Vector3.one * 0.1f;
  31. pointEntity.Add(go);
  32. }
  33. }
  34. else
  35. {
  36. for (int i = points_len; i < objs_len; i++)
  37. {
  38. pointEntity[i].SetActive(false);
  39. }
  40. }
  41. for (int i = 0; i < points.Count; i++)
  42. {
  43. pointEntity[i].transform.position = points[i];
  44. pointEntity[i].SetActive(true);
  45. }
  46. }
  47. }
  48. }