|
@@ -6,10 +6,12 @@ using UnityEngine.UI;
|
|
|
//多准心渲染姿态角-测试用
|
|
//多准心渲染姿态角-测试用
|
|
|
public class MultipleCrossHair : MonoBehaviour
|
|
public class MultipleCrossHair : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
|
|
+ public static MultipleCrossHair ins;
|
|
|
List<RectTransform> crossHairList = new List<RectTransform>();
|
|
List<RectTransform> crossHairList = new List<RectTransform>();
|
|
|
|
|
|
|
|
void Start()
|
|
void Start()
|
|
|
{
|
|
{
|
|
|
|
|
+ ins = this;
|
|
|
BowCamera.ins.onAfterLateUpdate += MyUpdate;
|
|
BowCamera.ins.onAfterLateUpdate += MyUpdate;
|
|
|
|
|
|
|
|
crossHairList.Add(CreateNewCrossHair(Color.green));
|
|
crossHairList.Add(CreateNewCrossHair(Color.green));
|
|
@@ -20,12 +22,21 @@ public class MultipleCrossHair : MonoBehaviour
|
|
|
|
|
|
|
|
void MyUpdate()
|
|
void MyUpdate()
|
|
|
{
|
|
{
|
|
|
- UpdateCrossHairByRotation(crossHairList[0], Quaternion.identity);
|
|
|
|
|
- UpdateCrossHairByRotation(crossHairList[0], Quaternion.identity);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void UpdateCrossHairByRotation2(int crossHairIndex, Quaternion rotation)
|
|
|
|
|
+ {
|
|
|
|
|
+ RectTransform rectTF = crossHairList[crossHairIndex];
|
|
|
|
|
+ UpdateCrossHairByRotation(rectTF, rotation);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void UpdateCrossHairByRotation(RectTransform rectTF, Quaternion rotation)
|
|
|
|
|
|
|
+ void UpdateCrossHairByRotation(RectTransform rectTF, Quaternion rotation)
|
|
|
{
|
|
{
|
|
|
|
|
+ //把z轴旋转弄成0
|
|
|
|
|
+ rotation = Quaternion.LookRotation(rotation * Vector3.forward);
|
|
|
|
|
+
|
|
|
|
|
+ //比率转化,边界限制
|
|
|
Vector3 theAngles = rotation.eulerAngles;
|
|
Vector3 theAngles = rotation.eulerAngles;
|
|
|
float bowRotateConvertRate = UserSettings.ins.bowRotateConvert.GetRate();
|
|
float bowRotateConvertRate = UserSettings.ins.bowRotateConvert.GetRate();
|
|
|
theAngles.x = Mathf.Clamp((theAngles.x > 180 ? theAngles.x - 360 : theAngles.x) * bowRotateConvertRate,
|
|
theAngles.x = Mathf.Clamp((theAngles.x > 180 ? theAngles.x - 360 : theAngles.x) * bowRotateConvertRate,
|
|
@@ -33,8 +44,10 @@ public class MultipleCrossHair : MonoBehaviour
|
|
|
theAngles.y = Mathf.Clamp((theAngles.y > 180 ? theAngles.y - 360 : theAngles.y) * bowRotateConvertRate,
|
|
theAngles.y = Mathf.Clamp((theAngles.y > 180 ? theAngles.y - 360 : theAngles.y) * bowRotateConvertRate,
|
|
|
-80, 80);
|
|
-80, 80);
|
|
|
|
|
|
|
|
|
|
+ //rotation参数看作本地四元组,还得根据游戏场景转成世界四元组
|
|
|
Transform TF = BowCamera.ins.transform;
|
|
Transform TF = BowCamera.ins.transform;
|
|
|
Vector3 forward = GameMgr.ins.transform.rotation * (Quaternion.Euler(theAngles) * Vector3.forward);
|
|
Vector3 forward = GameMgr.ins.transform.rotation * (Quaternion.Euler(theAngles) * Vector3.forward);
|
|
|
|
|
+
|
|
|
Ray ray = new Ray(TF.position, forward);
|
|
Ray ray = new Ray(TF.position, forward);
|
|
|
RaycastHit hitInfo;
|
|
RaycastHit hitInfo;
|
|
|
Vector3 targetPosition;
|
|
Vector3 targetPosition;
|