Ver Fonte

新的射箭逻辑加入主程序

lvjincheng há 4 anos atrás
pai
commit
355ad8229d

Diff do ficheiro suprimidas por serem muito extensas
+ 91 - 780
Assets/BowArrow/Scenes/Game.unity


+ 0 - 3
Assets/BowArrow/Scripts/Debug/GameDebug.cs

@@ -10,7 +10,6 @@ public class GameDebug : MonoBehaviour
     [SerializeField] Text absoluteAngleText;
     [SerializeField] InputField offsetAngleInput;
     [SerializeField] Text logText;
-    [SerializeField] GameObject outTip;
     bool loaded = false;
 
     public static GameDebug ins;
@@ -88,8 +87,6 @@ public class GameDebug : MonoBehaviour
             float parabolaAngle = Mathf.Min(Mathf.Atan(res1), Mathf.Atan(res2)) / Mathf.PI * 180;
 
             absoluteAngleText.text = "绝对角度: " + parabolaAngle + "°";
-
-            outTip.SetActive(Mathf.Abs(parabolaAngle) > 5);
         } else {
             absoluteAngleText.text = "绝对角度: " + "无解";
         }

+ 56 - 0
Assets/BowArrow/Scripts/Game/AimLoadChecker.cs

@@ -0,0 +1,56 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+/**瞄准器负载检测 */
+public class AimLoadChecker : MonoBehaviour
+{
+    [SerializeField] GameObject outTip;
+
+    void Start()
+    {
+        
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        bool needActiveOutTip = false;
+        if (ArmBow.ins && ArmBow.ins.IsCanShoot() && TargetBody.ins) {
+            RaycastHit ray = CrossHair.ins.GetRaycastHit();
+            if (ray.transform && ray.transform.gameObject.name == "TargetBody") {
+                float mySpeed = Arrow.speed;
+                if (GameAssistUI.ins) {
+                    mySpeed *= (1 + GameAssistUI.ins.shootScaleValue);
+                } 
+                Vector3 destination = ray.point;
+                Vector3 startPoint = BowCamera.ins.transform.position;
+                float deltaX = Mathf.Sqrt(
+                    Mathf.Pow(destination.x - startPoint.x, 2) +
+                    Mathf.Pow(destination.z - startPoint.z,2)
+                );
+                float deltaY = destination.y - startPoint.y;
+                float a = 0.5f * Physics.gravity.y * Mathf.Pow(deltaX, 2) / Mathf.Pow(mySpeed, 2);
+                float b = deltaX;
+                float c = a - deltaY;
+                bool hasParabolaAngle = Mathf.Pow(b, 2) - 4 * a * c >= 0;
+                if (hasParabolaAngle) {
+                    float res1 = (-b + Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a);
+                    float res2 = (-b - Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a);
+                    float parabolaAngle = Mathf.Min(Mathf.Atan(res1), Mathf.Atan(res2)) / Mathf.PI * 180;
+
+                    needActiveOutTip = parabolaAngle > 5;               
+                }
+            }
+        }
+        ActiveOutTip(needActiveOutTip);
+    }
+
+    public void ActiveOutTip(bool value) 
+    {
+        if (outTip.activeSelf != value) {
+            outTip.SetActive(value);
+        }
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Game/AimLoadChecker.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: da55f36190c6b3944b91362f41910598
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 2
Assets/BowArrow/Scripts/Game/ArmBow.cs

@@ -169,7 +169,9 @@ public class ArmBow : MonoBehaviour
         arrowComp.armBow = this;
         arrowComp.shootOutPosition = shootOutPosition;
         arrowComp.absoluteRay = absoluteRay;
-        arrowComp.offsetAngle = GameDebug.ins.GetOffsetAngle();
+        arrowComp.offsetAngle = GameDebug.ins ? 
+            GameDebug.ins.GetOffsetAngle() : 
+            Vector3.Angle(absolute_rotation.eulerAngles, final_rotation.eulerAngles);
 
         if (ShootCheck.ins && !GameMgr.debugInEditor) 
         {
@@ -198,7 +200,7 @@ public class ArmBow : MonoBehaviour
         this.transform.localScale = new Vector3(1, 1, 1);
     }
 
-    public bool NeedCrossHair()
+    public bool IsCanShoot()
     {
         return canShoot;
     }

+ 1 - 1
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -189,7 +189,7 @@ public class Arrow : MonoBehaviour
     }
 
     public void Hit() {
-        GameDebug.ins.ShowRes(absoluteRay.point, this.getHeadPosition());
+        if (GameDebug.ins) GameDebug.ins.ShowRes(absoluteRay.point, this.getHeadPosition());
         gameObject.GetComponent<BoxCollider>().enabled = false;
         if (newRigidbody) {
             newRigidbody.useGravity = false;

+ 1 - 1
Assets/BowArrow/Scripts/Game/CrossHair.cs

@@ -25,7 +25,7 @@ public class CrossHair : MonoBehaviour
 
     void Update()
     {
-        if (open) SetVisiable(ArmBow.ins && ArmBow.ins.NeedCrossHair());
+        if (open) SetVisiable(ArmBow.ins && ArmBow.ins.IsCanShoot());
     }
 
     void SetVisiable(bool value)

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

@@ -70,7 +70,6 @@ public class GameAssistUI : MonoBehaviour
 
     Transform scope = null;
     float[] scaleAimFieldOfViews = {30, 20, 12, 6, 3};
-    float[] scaleAimArmBowZs = {-0.813f, -0.799f, -0.77f, -0.695f, -0.55f};
     float[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
     Sequence seq1 = null;
     bool openScaleAim()
@@ -138,7 +137,7 @@ public class GameAssistUI : MonoBehaviour
             if (prop.config.type == 2) {
                 PropScaleShoot config = prop.config as PropScaleShoot;
                 shootScaleValue = config.scaleValue;
-                GameDebug.ins.caluculateAbsoluteAngle();
+                if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
                 return true;
             }
         }
@@ -154,6 +153,6 @@ public class GameAssistUI : MonoBehaviour
     void closeScaleShoot()
     {
         shootScaleValue = 0;
-        GameDebug.ins.caluculateAbsoluteAngle();
+        if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
     }
 }

+ 3 - 3
ProjectSettings/EditorBuildSettings.asset

@@ -5,13 +5,13 @@ EditorBuildSettings:
   m_ObjectHideFlags: 0
   serializedVersion: 2
   m_Scenes:
-  - enabled: 0
+  - enabled: 1
     path: Assets/BowArrow/Scenes/Entry.unity
     guid: 14a16d0455f1bf44a8cf4e02c0550a99
-  - enabled: 0
+  - enabled: 1
     path: Assets/BowArrow/Scenes/Login.unity
     guid: 200a793b1fc5aac438c87e1b342a939a
-  - enabled: 0
+  - enabled: 1
     path: Assets/BowArrow/Scenes/Home.unity
     guid: 8aa5affa1b256294a8c908dbab6122d0
   - enabled: 1

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff