CameraToLookNew.cs 2.0 KB

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