| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- using UnityEngine;
- using UnityEngine.EventSystems;
- /* 弓的相机 */
- public class BowCamera : MonoBehaviour
- {
- //相机组件
- Camera _cameraComp;
- Camera cameraComp {
- get {
- if (!_cameraComp) _cameraComp = GetComponent<Camera>();
- return _cameraComp;
- }
- }
- //控制的手臂弓
- ArmBow _armBow;
- ArmBow armBow {
- get {
- if (!_armBow) _armBow = GetComponentInChildren<ArmBow>();
- return _armBow;
- }
- }
- //本地欧拉角记录值
- Vector3 localEulerAngles;
- //触摸检测器
- JC.Unity.TouchChecker touchChecker = new JC.Unity.TouchChecker();
- //触摸模式开关
- private static bool _isTouchMode = true;
- public static bool isTouchMode {
- get {
- if (CommonConfig.isReleaseVersion) return false;
- return _isTouchMode;
- }
- set {
- _isTouchMode = value;
- }
- }
- //禁止逻辑,只用于同步状态和渲染,目前用于联机
- [NonSerialized] public bool banLogic = false;
- private static BowCamera _ins;
- public static BowCamera ins {
- get {
- if (!_ins) {
- _ins = GameObject.FindObjectOfType<BowCamera>();
- }
- return _ins;
- }
- }
- void Awake() {
- _ins = this;
- localEulerAngles = transform.localEulerAngles;
- }
- void Start() {
- touchChecker.onMoved += delegate(Touch t, bool isOnUI) {
- if (banLogic) return;
- 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 (banLogic) return;
- if (!isOnUI) armBow.ADS_fire();
- };
- }
- void Update()
- {
- //更新相机视野
- if (cameraComp && !banCameraFieldOfView) {
- cameraComp.fieldOfView = cameraFieldOfView;
- }
- if (banLogic) return;
- //满足以下条件则阻止控制输入
- if (GameMgr.ins.gameOver) {
- return;
- }
- if (GameMgr.debugInEditor) {
- //鼠标控制镜头和拉弓射箭
- 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;
- }
- else if (isTouchMode) {
- touchChecker.Update();
- } else {
- if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked) return;
- //需要-镜头看向九轴姿态虚拟节点
- needLookAtPoint = true;
- }
- }
- bool needLookAtPoint = false; //需要-镜头看向九轴姿态虚拟节点?
- void LateUpdate() {
- if (needLookAtPoint) {
- needLookAtPoint = false;
- //镜头看向九轴姿态虚拟节点
- this.transform.LookAt(CameraToLook.ins.point);
- }
- }
- //---------------相机视野的相关操作---------------------
- //视野值记录
- float cameraFieldOfView = 60;
- //禁止相机视野改变
- [NonSerialized] public bool banCameraFieldOfView = false;
-
- public void SetCameraFieldOfView(float value) {
- cameraComp.fieldOfView = value;
- }
- public void SetCameraFieldOfViewRecord(float value) {
- cameraFieldOfView = value;
- }
- //拉弓时的相机视野值变化
- public void updateFollowPullBow() {
- if (cameraFieldOfView > 40) {
- cameraFieldOfView -= 20 * Time.deltaTime;
- } else {
- cameraFieldOfView = 40;
- }
- }
- //松开拉弓时的相机视野值变化
- public void updateGiveUpPullBow() {
- if (cameraFieldOfView < 60) {
- cameraFieldOfView += 20 * Time.deltaTime;
- } else {
- cameraFieldOfView = 60;
- }
- }
- }
|