|
|
@@ -22,6 +22,8 @@ public class BowCamera : MonoBehaviour
|
|
|
}
|
|
|
//本地欧拉角记录值
|
|
|
Vector3 localEulerAngles;
|
|
|
+ //触摸检测器
|
|
|
+ JC.Unity.TouchChecker touchChecker = new JC.Unity.TouchChecker();
|
|
|
//触摸模式开关
|
|
|
public static bool isTouchMode = true;
|
|
|
public static BowCamera ins;
|
|
|
@@ -31,6 +33,19 @@ public class BowCamera : MonoBehaviour
|
|
|
localEulerAngles = transform.localEulerAngles;
|
|
|
}
|
|
|
|
|
|
+ void Start() {
|
|
|
+ touchChecker.onMoved += delegate(Touch t, bool isOnUI) {
|
|
|
+ if (isOnUI) return;
|
|
|
+ //触摸控制镜头和拉弓射箭
|
|
|
+ this.localEulerAngles.x = Mathf.Clamp(this.localEulerAngles.x - t.deltaPosition.y * Time.deltaTime * 5, -36, 36);
|
|
|
+ this.localEulerAngles.y = Mathf.Clamp(this.localEulerAngles.y + t.deltaPosition.x * Time.deltaTime * 5, -180, 180);
|
|
|
+ this.transform.localEulerAngles = this.localEulerAngles;
|
|
|
+ };
|
|
|
+ touchChecker.onEnded += delegate(Touch t, bool isOnUI) {
|
|
|
+ if (!isOnUI) armBow.ADS_fire();
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
void Update()
|
|
|
{
|
|
|
//更新相机视野
|
|
|
@@ -54,55 +69,13 @@ public class BowCamera : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
else if (isTouchMode) {
|
|
|
- if (Input.touchCount > 0) {
|
|
|
- if (!hasTouch) {
|
|
|
- Touch touch = Input.GetTouch(0);
|
|
|
- if (touch.phase == TouchPhase.Began) {
|
|
|
- hasTouch = true;
|
|
|
- touchID = touch.fingerId;
|
|
|
- }
|
|
|
- }
|
|
|
- if (hasTouch) {
|
|
|
- Touch touch = default;
|
|
|
- foreach (var t in Input.touches)
|
|
|
- {
|
|
|
- if (t.fingerId == touchID) touch = t;
|
|
|
- }
|
|
|
- bool isOverUI = EventSystem.current.IsPointerOverGameObject(touchID);
|
|
|
- if (touch.phase == TouchPhase.Began) {
|
|
|
- touchOnUI = isOverUI;
|
|
|
- }
|
|
|
- else if (touch.phase == TouchPhase.Moved) {
|
|
|
- touchOnUI = isOverUI;
|
|
|
- if (!isOverUI) {
|
|
|
- //触摸控制镜头和拉弓射箭
|
|
|
- this.localEulerAngles.x = Mathf.Clamp(this.localEulerAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
|
|
|
- this.localEulerAngles.y = Mathf.Clamp(this.localEulerAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -180, 180);
|
|
|
- this.transform.localEulerAngles = this.localEulerAngles;
|
|
|
- }
|
|
|
- }
|
|
|
- else if (touch.phase == TouchPhase.Ended) {
|
|
|
- hasTouch = false;
|
|
|
- //UnityBug,Ended阶段isOverUI总是返回false,因此通过新增变量touchOnUI来辅助识别触点是否在UI上
|
|
|
- if (touchOnUI) touchOnUI = false;
|
|
|
- else armBow.ADS_fire();
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- hasTouch = false;
|
|
|
- }
|
|
|
+ touchChecker.Update();
|
|
|
} else {
|
|
|
- hasTouch = false;
|
|
|
//镜头看向九轴姿态虚拟节点
|
|
|
this.transform.LookAt(CameraToLook.ins.point);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //触摸模式下的有效触点信息记录
|
|
|
- int touchID;
|
|
|
- bool hasTouch;
|
|
|
- bool touchOnUI;
|
|
|
-
|
|
|
//---------------相机视野的相关操作---------------------
|
|
|
|
|
|
//视野值记录
|