ResetTransform.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Blue;
  2. using UnityEngine;
  3. /// <summary>
  4. /// 重置位置---Action
  5. /// </summary>
  6. public class ResetTransform : MonoBehaviour
  7. {
  8. [SerializeField] private Transform Xunjian => SceneIOCContainer.Instance.Pull("Dof") as Transform;
  9. public bool FixedHeight;
  10. private float height;
  11. private bool heightIsNull;
  12. private void Awake()
  13. {
  14. if(OpenXRCamera.Instance!=null)
  15. height = OpenXRCamera.Instance.head.position.y;
  16. else
  17. heightIsNull = true;
  18. }
  19. private void Start()
  20. {
  21. if(heightIsNull)
  22. height = OpenXRCamera.Instance.head.position.y;
  23. }
  24. public void Execute()
  25. {
  26. transform.position = Xunjian.position;
  27. transform.eulerAngles = Xunjian.eulerAngles;
  28. /*
  29. transform.LookAt(OpenXRCamera.Instance.head);
  30. transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y + 180f, 0);
  31. Transform Player = OpenXRCamera.Instance.head;
  32. Player.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
  33. transform.position = OpenXRCamera.Instance.head.position + Player.forward * 1.6f;
  34. transform.position = new Vector3(transform.position.x, transform.position.y + 0f, transform.position.z);
  35. */
  36. }
  37. public void FixedHeightExecute()
  38. {
  39. Vector3 v3 = Xunjian.position;
  40. v3.y = height;
  41. transform.position = v3;
  42. Vector3 v3Rot = Xunjian.eulerAngles;
  43. v3Rot = new Vector3(0, v3Rot.y, 0);
  44. transform.eulerAngles = v3Rot;
  45. }
  46. }