|
|
@@ -1,38 +1,38 @@
|
|
|
using System;
|
|
|
-using System.Collections;
|
|
|
-using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.EventSystems;
|
|
|
/* 弓的相机 */
|
|
|
public class BowCamera : MonoBehaviour
|
|
|
{
|
|
|
- private Vector3 eualrAngles = new Vector3();
|
|
|
- private float mouseSensitivity = 2f;
|
|
|
- public Camera cameraComp;
|
|
|
- // 用于禁止相机旋转外部接口
|
|
|
- public bool banRotate = false;
|
|
|
- public bool banCameraFieldOfView = false;
|
|
|
+ //相机组件
|
|
|
+ Camera cameraComp;
|
|
|
+ //本地欧拉角记录值
|
|
|
+ Vector3 localEulerAngles;
|
|
|
public static BowCamera ins;
|
|
|
|
|
|
void Awake() {
|
|
|
ins = this;
|
|
|
+ cameraComp = GetComponent<Camera>();
|
|
|
+ localEulerAngles = transform.localEulerAngles;
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
|
- {
|
|
|
+ {
|
|
|
+ //更新相机视野
|
|
|
if (cameraComp && !banCameraFieldOfView) {
|
|
|
cameraComp.fieldOfView = cameraFieldOfView;
|
|
|
}
|
|
|
|
|
|
- if (GameMgr.ins.gameOver || banRotate) {
|
|
|
+ //满足以下条件则阻止控制输入
|
|
|
+ if (GameMgr.ins.gameOver) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
if (GameMgr.debugInEditor) {
|
|
|
- this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - this.mouseSensitivity * Input.GetAxis("Mouse Y"), -36, 36);
|
|
|
- this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + this.mouseSensitivity * Input.GetAxis("Mouse X"), -20, 20);
|
|
|
- // this.eualrAngles.x = this.eualrAngles.x - this.mouseSensitivity * Input.GetAxis("Mouse Y");
|
|
|
- // this.eualrAngles.y = this.eualrAngles.y + this.mouseSensitivity * Input.GetAxis("Mouse X");
|
|
|
- this.transform.eulerAngles = this.eualrAngles;
|
|
|
+ //鼠标控制镜头和拉弓射箭
|
|
|
+ this.localEulerAngles.x = Mathf.Clamp(this.localEulerAngles.x - 2f * Input.GetAxis("Mouse Y"), -36, 36);
|
|
|
+ this.localEulerAngles.y = Mathf.Clamp(this.localEulerAngles.y + 2f * Input.GetAxis("Mouse X"), -180, 180);
|
|
|
+ this.transform.localEulerAngles = this.localEulerAngles;
|
|
|
if (EventSystem.current.IsPointerOverGameObject())
|
|
|
{
|
|
|
return;
|
|
|
@@ -44,42 +44,49 @@ public class BowCamera : MonoBehaviour
|
|
|
ArmBow.ins.mouseUp();
|
|
|
}
|
|
|
} else {
|
|
|
+ //镜头看向九轴姿态虚拟节点
|
|
|
this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
|
|
|
- // if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
|
|
|
- // {
|
|
|
- // if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
|
|
|
- // {
|
|
|
- // this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
|
|
|
- // this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -25, 25);
|
|
|
- // this.transform.eulerAngles = this.eualrAngles;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // if (Input.touches.Length > 0)
|
|
|
- // {
|
|
|
- // foreach (Touch touch in Input.touches)
|
|
|
- // {
|
|
|
- // if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
|
|
|
- // }
|
|
|
- // ArmBow.ins.mouseDown();
|
|
|
- // }
|
|
|
- // if (Input.touches.Length == 0)
|
|
|
- // {
|
|
|
- // ArmBow.ins.mouseUp();
|
|
|
- // }
|
|
|
+
|
|
|
+ //触摸控制镜头和拉弓射箭
|
|
|
+ #region
|
|
|
+ if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
|
|
|
+ {
|
|
|
+ if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Input.touches.Length > 0)
|
|
|
+ {
|
|
|
+ foreach (Touch touch in Input.touches)
|
|
|
+ {
|
|
|
+ if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
|
|
|
+ }
|
|
|
+ ArmBow.ins.mouseDown();
|
|
|
+ }
|
|
|
+ if (Input.touches.Length == 0)
|
|
|
+ {
|
|
|
+ ArmBow.ins.mouseUp();
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- float cameraFieldOfView = 60;
|
|
|
-
|
|
|
- public void SetCameraFieldOfView(float value)
|
|
|
- {
|
|
|
- cameraComp.fieldOfView = value;
|
|
|
- }
|
|
|
+ //---------------相机视野的相关操作---------------------
|
|
|
|
|
|
- public void setFieldOfView(float value, bool isPlus) {
|
|
|
- cameraFieldOfView = isPlus ? cameraFieldOfView + value : value;
|
|
|
+ //视野值记录
|
|
|
+ float cameraFieldOfView = 60;
|
|
|
+ //禁止相机视野改变
|
|
|
+ [NonSerialized] public bool banCameraFieldOfView = false;
|
|
|
+
|
|
|
+ //立马改变相机视野值
|
|
|
+ public void SetCameraFieldOfView(float value) {
|
|
|
+ cameraComp.fieldOfView = cameraFieldOfView = value;
|
|
|
}
|
|
|
|
|
|
+ //拉弓时的相机视野值变化
|
|
|
public void updateFollowPullBow() {
|
|
|
if (cameraFieldOfView > 40) {
|
|
|
cameraFieldOfView -= 20 * Time.deltaTime;
|
|
|
@@ -88,6 +95,7 @@ public class BowCamera : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //松开拉弓时的相机视野值变化
|
|
|
public void updateGiveUpPullBow() {
|
|
|
if (cameraFieldOfView < 60) {
|
|
|
cameraFieldOfView += 20 * Time.deltaTime;
|