| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using UnityEngine;
- /* 弓的摄像机总会LookAt该节点的Point子节点
- 九轴数据是直接应用到该节点的(特意分离而不直接应用到弓的摄像机) 是为了避免z轴旋转
- */
- public class CameraToLookNew : MonoBehaviour
- {
- public Transform point1P;
- public Transform point2P;
- [SerializeField] bool onlyParseRotation = false;
- public Action<Quaternion> onParseRotation;
- public static CameraToLookNew ins;
- void Awake()
- {
- ins = this;
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- public Quaternion localRotation1P
- {
- get
- {
- return transform.localRotation;
- }
- set
- {
- transform.localRotation = value;
- if (onlyParseRotation)
- {
- //去掉z轴影响
- Vector3 normalVector = value * Vector3.forward;
- Quaternion normalQuat = Quaternion.LookRotation(normalVector);
- try
- {
- if (BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
- onParseRotation?.Invoke(normalQuat);
- }
- catch (System.Exception e)
- {
- Debug.LogError(e);
- }
- }
- }
- }
- public Quaternion localRotation2P
- {
- get
- {
- return transform.localRotation;
- }
- set
- {
- transform.localRotation = value;
- if (onlyParseRotation)
- {
- //去掉z轴影响
- Vector3 normalVector = value * Vector3.forward;
- Quaternion normalQuat = Quaternion.LookRotation(normalVector);
- try
- {
- if (BluetoothAim.ins.getSmartBowHelper2P().GetBluetoothStatus() == SmartBowSDK.BluetoothStatusEnum.Connected)
- onParseRotation?.Invoke(normalQuat);
- }
- catch (System.Exception e)
- {
- Debug.LogError(e);
- }
- }
- }
- }
- }
|