RtkPos.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class RtkPos : MonoBehaviour
  6. {
  7. /// <summary>
  8. /// 显示物体
  9. /// </summary>
  10. public List<Transform> list_Obj;
  11. /// <summary>
  12. /// 根据实地GPS数据转化位置信息 ( 与 List_Obj 对应)
  13. /// </summary>
  14. public List<Vector2> list_Pos;
  15. public List<Transform> list_Box;
  16. public Text text;
  17. /// <summary>
  18. /// 根据玩家传输进来的Gps 推算出 物体位置
  19. /// </summary>
  20. /// <param name="playerGps"></param>
  21. public void SettingPos( Vector2 playerGps )
  22. {
  23. if(list_Pos.Count!=list_Obj.Count)
  24. {
  25. Debug.LogError(" RTK版本 提供的物体和提供的坐标数量不符 ");
  26. return;
  27. }
  28. if (API_SVR.GetHead()!=null)
  29. for (int i = 0; i < list_Obj.Count; i++)
  30. {
  31. Vector2 diff = list_Pos[i] - playerGps;
  32. Vector3 playerPos = API_SVR.GetHead().position;
  33. Vector3 pos = new Vector3(playerPos.x + diff.x, list_Obj[i].position.y, playerPos.z + diff.y);
  34. list_Obj[i].position = pos;
  35. list_Box[i].position = pos;
  36. //text.text = pos.ToString();
  37. Debug.Log(pos);
  38. }
  39. }
  40. }