|
|
@@ -50,6 +50,9 @@ public class BowCamera : MonoBehaviour
|
|
|
void Awake() {
|
|
|
_ins = this;
|
|
|
localEulerAngles = transform.localEulerAngles;
|
|
|
+ if (UserSettings.ins.bowCameraFixed) {
|
|
|
+ bowCameraFixed = new BowCameraFixed(this);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void Start() {
|
|
|
@@ -57,8 +60,8 @@ public class BowCamera : MonoBehaviour
|
|
|
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.localEulerAngles.x = Mathf.Clamp(this.localEulerAngles.x - t.deltaPosition.y * Time.deltaTime * 5, -80, 80);
|
|
|
+ this.localEulerAngles.y = Mathf.Clamp(this.localEulerAngles.y + t.deltaPosition.x * Time.deltaTime * 5, -90, 90);
|
|
|
this.transform.localEulerAngles = this.localEulerAngles;
|
|
|
};
|
|
|
touchChecker.onEnded += delegate(Touch t, bool isOnUI) {
|
|
|
@@ -83,8 +86,8 @@ public class BowCamera : MonoBehaviour
|
|
|
|
|
|
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.localEulerAngles.x = Mathf.Clamp(this.localEulerAngles.x - 2f * Input.GetAxis("Mouse Y"), -80, 80);
|
|
|
+ this.localEulerAngles.y = Mathf.Clamp(this.localEulerAngles.y + 2f * Input.GetAxis("Mouse X"), -90, 90);
|
|
|
this.transform.localEulerAngles = this.localEulerAngles;
|
|
|
if (EventSystem.current.IsPointerOverGameObject()) return;
|
|
|
}
|
|
|
@@ -119,15 +122,17 @@ public class BowCamera : MonoBehaviour
|
|
|
Vector3 localEulerAngles = this.transform.localEulerAngles;
|
|
|
float angleY = localEulerAngles.y;
|
|
|
if (angleY < 180) {
|
|
|
- angleY = Mathf.Clamp(angleY * bowRotateConvertRate, 0, 180);
|
|
|
+ angleY = Mathf.Clamp(angleY * bowRotateConvertRate, 0, 90);
|
|
|
} else {
|
|
|
- angleY = Mathf.Clamp((angleY - 360) * bowRotateConvertRate, -180, 0);
|
|
|
+ angleY = Mathf.Clamp((angleY - 360) * bowRotateConvertRate, -90, 0);
|
|
|
}
|
|
|
localEulerAngles.y = angleY;
|
|
|
this.transform.localEulerAngles = localEulerAngles;
|
|
|
}
|
|
|
}
|
|
|
+ onAfterLateUpdate?.Invoke();
|
|
|
}
|
|
|
+ Action onAfterLateUpdate;
|
|
|
|
|
|
//---------------相机视野的相关操作---------------------
|
|
|
|
|
|
@@ -161,4 +166,98 @@ public class BowCamera : MonoBehaviour
|
|
|
cameraFieldOfView = 60;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 2022-04-28
|
|
|
+ // ------ 添加固定镜头选项后,新增的API ------
|
|
|
+ bool isArrowFollowing = false;
|
|
|
+ public void SetArrowFollowing(bool value) {
|
|
|
+ isArrowFollowing = value;
|
|
|
+ cameraComp.enabled = !isArrowFollowing;
|
|
|
+ AutoSwitchCamera();
|
|
|
+ }
|
|
|
+ bool isScaleAimDisplaying = false;
|
|
|
+ public void SetScaleAimDisplaying(bool value) {
|
|
|
+ isScaleAimDisplaying = value;
|
|
|
+ AutoSwitchCamera();
|
|
|
+ }
|
|
|
+
|
|
|
+ void AutoSwitchCamera() {
|
|
|
+ if (bowCameraFixed == null) {
|
|
|
+ cameraComp.enabled = !isArrowFollowing;
|
|
|
+ } else {
|
|
|
+ bowCameraFixed.gameObject.SetActive(!isScaleAimDisplaying && !isArrowFollowing);
|
|
|
+ cameraComp.enabled = isScaleAimDisplaying && !isArrowFollowing;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Camera GetRenderCamera() {
|
|
|
+ if (bowCameraFixed == null) {
|
|
|
+ return cameraComp;
|
|
|
+ } else {
|
|
|
+ if (bowCameraFixed.gameObject.activeSelf) {
|
|
|
+ return bowCameraFixed.camera;
|
|
|
+ } else {
|
|
|
+ return cameraComp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BowCameraFixed bowCameraFixed = null;
|
|
|
+ public class BowCameraFixed {
|
|
|
+ public GameObject gameObject;
|
|
|
+ public Transform transform;
|
|
|
+ public Camera camera;
|
|
|
+ private UnityStandardAssets.ImageEffects.Blur blur;
|
|
|
+ //bowCameraComponent
|
|
|
+ BowCamera bowCamera;
|
|
|
+ private Camera targetCamera;
|
|
|
+ private UnityStandardAssets.ImageEffects.Blur targetBlur;
|
|
|
+
|
|
|
+ public BowCameraFixed(BowCamera bowCamera) {
|
|
|
+ this.bowCamera = bowCamera;
|
|
|
+ gameObject = new GameObject("BowCameraFixed");
|
|
|
+ transform = gameObject.transform;
|
|
|
+ //复制Camera组件
|
|
|
+ targetCamera = bowCamera.cameraComp;
|
|
|
+ camera = gameObject.AddComponent<Camera>();
|
|
|
+ camera.tag = "MainCamera";
|
|
|
+ camera.clearFlags = targetCamera.clearFlags;
|
|
|
+ camera.backgroundColor = targetCamera.backgroundColor;
|
|
|
+ camera.cullingMask = targetCamera.cullingMask;
|
|
|
+ camera.fieldOfView = targetCamera.fieldOfView;
|
|
|
+ camera.nearClipPlane = targetCamera.nearClipPlane;
|
|
|
+ camera.depth = targetCamera.depth + 0.1f;
|
|
|
+ camera.renderingPath = targetCamera.renderingPath;
|
|
|
+ //复制Blur组件
|
|
|
+ targetBlur = bowCamera.GetComponent<UnityStandardAssets.ImageEffects.Blur>();
|
|
|
+ if (targetBlur) {
|
|
|
+ blur = gameObject.AddComponent<UnityStandardAssets.ImageEffects.Blur>();
|
|
|
+ blur.enabled = targetBlur.enabled;
|
|
|
+ blur.blurShader = targetBlur.blurShader;
|
|
|
+ blur.blurSpread = targetBlur.blurSpread;
|
|
|
+ blur.iterations = targetBlur.iterations;
|
|
|
+ }
|
|
|
+ //设置Transform属性
|
|
|
+ transform.parent = bowCamera.transform.parent;
|
|
|
+ transform.localPosition = bowCamera.transform.localPosition;
|
|
|
+ transform.localScale = bowCamera.transform.localScale;
|
|
|
+ transform.localRotation = Quaternion.identity;
|
|
|
+ //监听和驱动LateUpdate
|
|
|
+ bowCamera.onAfterLateUpdate += LateUpdate;
|
|
|
+ //切换镜头
|
|
|
+ bowCamera.AutoSwitchCamera();
|
|
|
+ }
|
|
|
+
|
|
|
+ void LateUpdate() {
|
|
|
+ CrossHair.ins.UpdatePostionWhenFixedCamera();
|
|
|
+ if (blur) {
|
|
|
+ blur.enabled = targetBlur.enabled;
|
|
|
+ if (blur.enabled) {
|
|
|
+ blur.blurShader = targetBlur.blurShader;
|
|
|
+ blur.blurSpread = targetBlur.blurSpread;
|
|
|
+ blur.iterations = targetBlur.iterations;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|