lvjincheng пре 3 година
родитељ
комит
403846c11e

+ 11 - 11
Assets/BowArrow/Scenes/Game.unity

@@ -7460,7 +7460,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
-  m_AnchoredPosition: {x: 29.264214, y: 0}
+  m_AnchoredPosition: {x: 29.118067, y: 0}
   m_SizeDelta: {x: 0, y: 33}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &589339043
@@ -9777,7 +9777,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
-  m_AnchoredPosition: {x: 29.264214, y: 0}
+  m_AnchoredPosition: {x: 29.118067, y: 0}
   m_SizeDelta: {x: 0, y: 33}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &694545845
@@ -9879,13 +9879,13 @@ Transform:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 708444217}
-  m_LocalRotation: {x: -0.3090171, y: 0, z: 0, w: 0.95105654}
+  m_LocalRotation: {x: -0.7071068, y: 0, z: 0, w: 0.7071068}
   m_LocalPosition: {x: 5, y: 3.2, z: 13.9}
-  m_LocalScale: {x: 10, y: 1, z: 1}
+  m_LocalScale: {x: 10, y: 1, z: 8}
   m_Children: []
   m_Father: {fileID: 1372893983}
   m_RootOrder: 1
-  m_LocalEulerAnglesHint: {x: -36, y: 0, z: 0}
+  m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
 --- !u!114 &708444219
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -15760,7 +15760,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
-  m_AnchoredPosition: {x: 29.264214, y: 0}
+  m_AnchoredPosition: {x: 29.118067, y: 0}
   m_SizeDelta: {x: 0, y: 33}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &1218454288
@@ -17635,7 +17635,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
-  m_AnchoredPosition: {x: 48.528427, y: 0}
+  m_AnchoredPosition: {x: 48.236134, y: 0}
   m_SizeDelta: {x: 0, y: 33}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &1338115114
@@ -21982,13 +21982,13 @@ Transform:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1615688111}
-  m_LocalRotation: {x: 0.309017, y: 0, z: 0, w: 0.95105654}
+  m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
   m_LocalPosition: {x: 5, y: 3.2, z: -13.87}
-  m_LocalScale: {x: 10, y: 1, z: 1}
+  m_LocalScale: {x: 10, y: 1, z: 8}
   m_Children: []
   m_Father: {fileID: 1372893983}
   m_RootOrder: 0
-  m_LocalEulerAnglesHint: {x: 36, y: 0, z: 0}
+  m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
 --- !u!114 &1615688113
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -25504,7 +25504,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
-  m_AnchoredPosition: {x: 78.52843, y: 0}
+  m_AnchoredPosition: {x: 78.23613, y: 0}
   m_SizeDelta: {x: 0, y: 40}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &1845023679

+ 1 - 1
Assets/BowArrow/Scripts/CommonConfig.cs

@@ -8,7 +8,7 @@ public class CommonConfig
     //需要App商店审核?-标记用于特别处理某些功能
     public static bool needToExamine = false;
     //是否属于发布版本?-标记用于特别处理某些功能,比如屏蔽内部测试才有功能
-    public static bool isReleaseVersion = true;
+    public static bool isReleaseVersion = false;
 
     /**环数精度小数位 */
     public static readonly int ringsPrecision = 1;

+ 7 - 3
Assets/BowArrow/Scripts/Game/ArmBow.cs

@@ -17,6 +17,9 @@ public class ArmBow : MonoBehaviour
     }
     //有效射击目标集合,可以理解为射中集合中的目标才能得分
     public HashSet<TargetBody> validTargets = new HashSet<TargetBody>();
+
+    //本地坐标z
+    public const float localPosZ = -0.3f;
     
     //射箭姿态记录索引倒退数,根据射击难度制造误差
     [NonSerialized] public int shootBackTime = 0;
@@ -107,6 +110,7 @@ public class ArmBow : MonoBehaviour
     {
         _ins = this;
         //initdata
+        Vector3 localPos = transform.localPosition; localPos.z = localPosZ; transform.localPosition = localPos;
         int currentShootLevel = UserSettings.ins.shootLevel;
         shootBackTime = new int[]{0, 2, 5}[currentShootLevel];
         shootOffsetAngleScale = new float[]{0, 10f, 10f}[currentShootLevel];
@@ -167,10 +171,10 @@ public class ArmBow : MonoBehaviour
             }
         #endregion
 
-        Quaternion oldCameraRotation = Camera.main.transform.rotation;
-        Camera.main.transform.rotation = absolute_rotation;
+        Quaternion oldCameraRotation = BowCamera.ins.transform.rotation;
+        BowCamera.ins.transform.rotation = absolute_rotation;
         RaycastHit absoluteRay = CrossHair.ins.GetRaycastHit();
-        Camera.main.transform.rotation = oldCameraRotation;
+        BowCamera.ins.transform.rotation = oldCameraRotation;
         
         Vector3 shootOutPosition = this.bowCamera.transform.position;
         Vector3 arrowEuler = absolute_rotation.eulerAngles;

+ 2 - 2
Assets/BowArrow/Scripts/Game/ArrowCamera.cs

@@ -18,7 +18,7 @@ public class ArrowCamera : MonoBehaviour
 
     void Awake()
     {
-        BowCamera.ins.GetComponent<Camera>().enabled = false;
+        BowCamera.ins.SetArrowFollowing(true);
     }
 
     void Start()
@@ -38,7 +38,7 @@ public class ArrowCamera : MonoBehaviour
     {
         try
         {
-            BowCamera.ins.GetComponent<Camera>().enabled = true;
+            BowCamera.ins.SetArrowFollowing(false);
         }
         catch (System.Exception) {}
     }

+ 105 - 6
Assets/BowArrow/Scripts/Game/BowCamera.cs

@@ -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;
+                }
+            }
+        }
+    }
 }

+ 40 - 6
Assets/BowArrow/Scripts/Game/CrossHair.cs

@@ -48,11 +48,45 @@ public class CrossHair : MonoBehaviour
 
     public RaycastHit GetRaycastHit() {
         float maxDistance = 100;
-        int layerMask = 1 << 8;
-        RaycastHit hit;
-        Ray ray = Camera.main.ScreenPointToRay(this.transform.position, Camera.MonoOrStereoscopicEye.Mono);
-        bool raycastResult = Physics.Raycast(ray.origin, ray.direction, out hit, maxDistance, layerMask);
-        // if (raycastResult) return hit.point;
-        return hit;
+        int layerMask = 1 << 8; //TargetLayerMask
+        RaycastHit raycastHit;
+        Ray ray;
+        if (Camera.main.name.EndsWith("Fixed")) {
+            ray = new Ray(BowCamera.ins.transform.position, BowCamera.ins.transform.forward);
+        } else {
+            ray = Camera.main.ScreenPointToRay(this.transform.position, Camera.MonoOrStereoscopicEye.Mono);
+        }
+        Physics.Raycast(ray.origin, ray.direction, out raycastHit, maxDistance, layerMask);
+        return raycastHit;
     }    
+
+    #region 固定相机更新
+        RectTransform _parentRTF;
+        RectTransform parentRTF {
+            get {
+                if (!_parentRTF) {
+                    _parentRTF = transform.parent.GetComponent<RectTransform>();
+                }
+                return _parentRTF;
+            }
+        }
+        Vector3 centerPoint = new Vector3(0.5f, 0.5f, 0);
+        Vector3 targetPosition;
+        public void UpdatePostionWhenFixedCamera() {
+            if (!visiable) return;
+            Transform transform = BowCamera.ins.transform;
+            Ray ray = new Ray(transform.position, transform.forward);
+            RaycastHit hitInfo;
+            if (Physics.Raycast(ray, out hitInfo, 100)) {
+                targetPosition = hitInfo.point;
+            } else {
+                targetPosition = transform.position + transform.forward * 100f;
+            }
+            Vector3 v3 = Camera.main.WorldToViewportPoint(targetPosition) - centerPoint;
+            v3.x *= parentRTF.rect.width;
+            v3.y *= parentRTF.rect.height;
+            v3.z = 0;
+            this.transform.localPosition = v3;
+        }
+    #endregion
 }

+ 3 - 2
Assets/BowArrow/Scripts/Game/GameAssistUI.cs

@@ -228,19 +228,20 @@ public class GameAssistUI : MonoBehaviour
         isScaleAimDisplaying = open;
         aimScaleDisplayValue = scaleValue;
 
-        BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
+        BowCamera bowCamera = BowCamera.ins;
         Transform scope = bowCamera.transform.Find("Scope");
 
         CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta =  
             open ? new Vector2(500, 500) : new Vector2(260, 260);
 
         bowCamera.banCameraFieldOfView = open;
+        bowCamera.SetScaleAimDisplaying(isScaleAimDisplaying);
         if (open) {
             bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
         }
 
         Vector3 localPosition = ArmBow.ins.transform.localPosition;
-        localPosition.z = open ? -2 : -0.1f;
+        localPosition.z = open ? -2 : ArmBow.localPosZ;
         ArmBow.ins.transform.localPosition = localPosition;
         
         if (open) {

+ 5 - 1
Assets/BowArrow/Scripts/Game/TargetDistanceLabel.cs

@@ -6,18 +6,22 @@ using UnityEngine.UI;
 public class TargetDistanceLabel : MonoBehaviour
 {
     public RectTransform canvasRTF;
-    public Camera mainCamera;
     public Transform followTarget;
     TargetBody targetBody;
     Vector3 centerPoint = new Vector3(0.5f, 0.5f, 0);
     Text textComp;
+    Canvas parentCanvas; 
+
     void Start()
     {
         targetBody = GameObject.Find("GameArea/TargetObject").GetComponentInChildren<TargetBody>();
         textComp = this.GetComponent<Text>();
+        parentCanvas = transform.parent.GetComponent<Canvas>();
     }
     void LateUpdate()
     {
+        Camera mainCamera = BowCamera.ins.GetRenderCamera();
+        parentCanvas.worldCamera = mainCamera;
         float angle = Vector3.Angle(mainCamera.transform.forward, followTarget.position - mainCamera.transform.position);
         if (angle > 90) {
             textComp.enabled = false;

+ 2 - 0
Assets/BowArrow/Scripts/Manager/LoginMgr.cs

@@ -91,6 +91,8 @@ public class UserSettings {
     public float actualArrowWeight = 20; 
     //弓箭旋转转化
     public BowRotateConvert bowRotateConvert = new BowRotateConvert();
+    //游戏中是否固定镜头
+    public bool bowCameraFixed = true;
 
     //设备校准引导-是否已经完成
     public bool deviceCalibrateGuideFinish = false;