SynPlayerTransform.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using LitJson;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using XRTool.Util;
  6. public class SynPlayerTransform : MonoSingleton<SynPlayerTransform>
  7. {
  8. public Transform player;
  9. public bool isPushPos;
  10. void Start()
  11. {
  12. isPushPos = false;
  13. player = OpenXRCamera.Instance.head;
  14. StartCoroutine(PushPos(0.5f));
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. transform.eulerAngles = new Vector3(0, player.eulerAngles.y, 0);
  20. transform.position = new Vector3(player.position.x, 0, player.position.z);
  21. // UILogManager.Instance.text3.text = transform.localEulerAngles.y.ToString();
  22. if (Input.GetKeyDown(KeyCode.Y))
  23. {
  24. isPushPos = !isPushPos;
  25. }
  26. }
  27. private IEnumerator PushPos (float times)
  28. {
  29. while (true)
  30. {
  31. yield return new WaitForSeconds(times);
  32. if (isPushPos)
  33. {
  34. JsonData obj = new JsonData();
  35. obj["x"] = (float)(Mathf.Round(player.position.x * 100)) / 100;
  36. obj["y"] = (float)(Mathf.Round(player.position.y * 100)) / 100;
  37. obj["z"] = (float)(Mathf.Round(player.position.z * 100)) / 100;
  38. obj["time"] = CommonMethod.GetCurrentTimeUnixMilliseconds();
  39. MQTTManager.Instance.PushMsg(MQTTManager.Instance.front + "younuo", obj.ToJson());
  40. }
  41. }
  42. }
  43. /// <summary>
  44. /// 返回当前朝向的机柜 , False 单排机柜 1 3 5...
  45. /// </summary>
  46. /// <returns></returns>
  47. public bool GetOrientation()
  48. {
  49. if (Mathf.Abs(transform.localEulerAngles.y) > 90&& Mathf.Abs(transform.localEulerAngles.y)<270)
  50. {
  51. return true;
  52. }
  53. return false;
  54. }
  55. /// <summary>
  56. /// 判断当前在第几排机柜之间
  57. /// </summary>
  58. public int GetRowCabinets()
  59. {
  60. int row = 0;
  61. float rowDis = 0;
  62. int index = 0;
  63. for (int i = 0; i < MachineRoomManager.Instance.listObjes.Count; i+=MachineRoomManager.Instance.data.line*2)
  64. {
  65. float disZ = Mathf.Abs(transform.position.z - MachineRoomManager.Instance.listObjes[i].transform.position.z);
  66. if(rowDis>disZ)
  67. {
  68. row = index;
  69. rowDis = disZ;
  70. }
  71. index++;
  72. }
  73. return row;
  74. }
  75. }