SynPlayerTransform.cs 1.4 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. }
  17. /// <summary>
  18. /// 返回当前朝向的机柜 , False 单排机柜 1 3 5...
  19. /// </summary>
  20. /// <returns></returns>
  21. public bool GetOrientation()
  22. {
  23. if (Mathf.Abs(transform.localEulerAngles.y) > 90)
  24. {
  25. return false;
  26. }
  27. return true;
  28. }
  29. /// <summary>
  30. /// 判断当前在第几排机柜之间
  31. /// </summary>
  32. public int GetRowCabinets()
  33. {
  34. int row = 0;
  35. float rowDis = 0;
  36. int index = 0;
  37. for (int i = 0; i < MachineRoomManager.Instance.listObjes.Count; i+=MachineRoomManager.Instance.data.line*2)
  38. {
  39. float disZ = Mathf.Abs(transform.position.z - MachineRoomManager.Instance.listObjes[i].transform.position.z);
  40. if(rowDis>disZ)
  41. {
  42. row = index;
  43. rowDis = disZ;
  44. }
  45. index++;
  46. }
  47. return row;
  48. }
  49. }