SynPlayerTransform.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SynPlayerTransform : MonoSingleton<SynPlayerTransform>
  5. {
  6. public Transform player;
  7. void Start()
  8. {
  9. player = OpenXRCamera.Instance.head;
  10. }
  11. // Update is called once per frame
  12. void Update()
  13. {
  14. transform.eulerAngles = new Vector3(0, player.eulerAngles.y, 0);
  15. transform.position = new Vector3(player.position.x, 0, player.position.z);
  16. UILogManager.Instance.text3.text = transform.localEulerAngles.y.ToString();
  17. }
  18. /// <summary>
  19. /// 返回当前朝向的机柜 , False 单排机柜 1 3 5...
  20. /// </summary>
  21. /// <returns></returns>
  22. public bool GetOrientation()
  23. {
  24. if (Mathf.Abs(transform.localEulerAngles.y) > 90&& Mathf.Abs(transform.localEulerAngles.y)<270)
  25. {
  26. return true;
  27. }
  28. return false;
  29. }
  30. /// <summary>
  31. /// 判断当前在第几排机柜之间
  32. /// </summary>
  33. public int GetRowCabinets()
  34. {
  35. int row = 0;
  36. float rowDis = 0;
  37. int index = 0;
  38. for (int i = 0; i < MachineRoomManager.Instance.listObjes.Count; i+=MachineRoomManager.Instance.data.line*2)
  39. {
  40. float disZ = Mathf.Abs(transform.position.z - MachineRoomManager.Instance.listObjes[i].transform.position.z);
  41. if(rowDis>disZ)
  42. {
  43. row = index;
  44. rowDis = disZ;
  45. }
  46. index++;
  47. }
  48. return row;
  49. }
  50. }