CameraToLookNew.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using AppUI.Bluetooth;
  2. using System;
  3. using UnityEngine;
  4. /* 弓的摄像机总会LookAt该节点的Point子节点
  5. 九轴数据是直接应用到该节点的(特意分离而不直接应用到弓的摄像机) 是为了避免z轴旋转
  6. */
  7. public class CameraToLookNew : MonoBehaviour
  8. {
  9. public Transform point1P;
  10. public Transform point2P;
  11. [SerializeField] bool onlyParseRotation = false;
  12. public Action<Quaternion> onParseRotation;
  13. public static CameraToLookNew ins;
  14. void Awake()
  15. {
  16. ins = this;
  17. }
  18. void OnDestroy()
  19. {
  20. if (ins == this) ins = null;
  21. }
  22. public Quaternion localRotation1P
  23. {
  24. get
  25. {
  26. return transform.localRotation;
  27. }
  28. set
  29. {
  30. transform.localRotation = value;
  31. if (onlyParseRotation)
  32. {
  33. //去掉z轴影响
  34. Vector3 normalVector = value * Vector3.forward;
  35. Quaternion normalQuat = Quaternion.LookRotation(normalVector);
  36. try
  37. {
  38. if (SmartBowDeviceHub.ins.GetSdkStatus(BluetoothPlayer.FIRST_PLAYER) == SmartBowSDK.BluetoothStatusEnum.Connected)
  39. onParseRotation?.Invoke(normalQuat);
  40. }
  41. catch (System.Exception e)
  42. {
  43. Debug.LogError(e);
  44. }
  45. }
  46. }
  47. }
  48. public Quaternion localRotation2P
  49. {
  50. get
  51. {
  52. return transform.localRotation;
  53. }
  54. set
  55. {
  56. transform.localRotation = value;
  57. if (onlyParseRotation)
  58. {
  59. //去掉z轴影响
  60. Vector3 normalVector = value * Vector3.forward;
  61. Quaternion normalQuat = Quaternion.LookRotation(normalVector);
  62. try
  63. {
  64. if (SmartBowDeviceHub.ins.GetSdkStatus(BluetoothPlayer.SECOND_PLAYER) == SmartBowSDK.BluetoothStatusEnum.Connected)
  65. onParseRotation?.Invoke(normalQuat);
  66. }
  67. catch (System.Exception e)
  68. {
  69. Debug.LogError(e);
  70. }
  71. }
  72. }
  73. }
  74. }