| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System;
- using UnityEngine;
- /* 弓的摄像机总会LookAt该节点的Point子节点
- 九轴数据是直接应用到该节点的(特意分离而不直接应用到弓的摄像机) 是为了避免z轴旋转
- */
- public class CameraToLook : MonoBehaviour
- {
- [NonSerialized] public Transform point;
- [SerializeField] bool onlyParseRotation = false;
- public Action<Quaternion> onParseRotation;
- public static CameraToLook ins;
- void Awake()
- {
- ins = this;
- point = transform.Find("Point");
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- public Quaternion localRotation {
- 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);
- #if UNITY_EDITOR
- else if (InfraredDemo.DebugInEditor) onParseRotation?.Invoke(normalQuat);
- #endif
- }
- catch (System.Exception e)
- {
- Debug.LogError(e);
- }
- }
- }
- }
- }
|