CloudPoints.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CloudPoints : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private Transform pointPrefab;
  8. private GameObject cloudFather;
  9. private List<GameObject> cloudPointList = new List<GameObject>();
  10. bool isStop = false;
  11. int dataNum = 0;
  12. ulong timeStamp = 0;
  13. float[] pointArray = new float[5000 * 3];
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. cloudFather = new GameObject("CloudPoint");
  18. cloudFather.transform.position = Vector3.zero;
  19. GameObject obj;
  20. foreach (var item in pointArray) {
  21. obj = Instantiate<GameObject>(pointPrefab.gameObject);
  22. obj.transform.SetParent(cloudFather.transform,false);
  23. cloudPointList.Add(obj);
  24. obj.SetActive(false);
  25. }
  26. StartCoroutine(UpdateCloudPoint());
  27. }
  28. IEnumerator UpdateCloudPoint() {
  29. // yield return new WaitUntil(()=>(API_GSXR_Slam.SlamManager!=null && API_GSXR_Slam.SlamManager.IsRunning));
  30. if (API_GSXR_Slam.GSXR_Is_EnablePointCloudData() == false) {
  31. API_GSXR_Slam.GSXR_Set_PointCloudData(true);
  32. }
  33. while ( !isStop) {
  34. yield return new WaitForSeconds(1);
  35. API_GSXR_Slam.GSXR_Get_PointCloudData(ref dataNum,ref timeStamp,pointArray);
  36. Debug.Log("CloudPoints Enable:"+ API_GSXR_Slam.GSXR_Is_EnablePointCloudData() + dataNum + " "+ timeStamp +" "+pointArray.Length);
  37. if (dataNum > 0) {
  38. foreach (var item in cloudPointList) {
  39. item.SetActive(false);
  40. }
  41. for (int i = 0; i <= dataNum; i ++) {
  42. cloudPointList[i].transform.position = new Vector3(pointArray[i * 3], pointArray[i * 3 + 1], -pointArray[i * 3 + 2]);
  43. cloudPointList[i].SetActive(true);
  44. }
  45. }
  46. }
  47. }
  48. }