lvjincheng 4 년 전
부모
커밋
90916cca8e

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 800 - 125
Assets/BowArrow/Scenes/Game.unity


+ 17 - 5
Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

@@ -72,16 +72,28 @@ public class ShootCheck : MonoBehaviour
             return false;
         } 
         else if (acc < cmd.getAcc() && maxAcc != 0) {
+            //积分求初速度
             shootSpeed = 0;
+            float lasKeytAcc = 0;
+            int keyAccIndex = 0;
             foreach (var keyAcc in keyAccList)
             {
-                shootSpeed += keyAcc;
+                if (keyAccIndex > 0)
+                {
+                    shootSpeed += keyAcc * 0.002f;
+                    shootSpeed -= (keyAcc - lasKeytAcc) * 0.002f / 2;
+                }
+                lasKeytAcc = keyAcc;
+                keyAccIndex++;
             }
-            shootSpeed /= keyAccList.Count;
-            shootSpeed *= 6;
-            Debug.LogWarning("初速度: " + shootSpeed);
-            maxAcc = 0;
+            //加速度acc的单位是g,最后需要乘上
+            shootSpeed *= 9.80665f;
+            //积分出来的值还是太小,需要一个倍率
+            shootSpeed *= 10;
+            Debug.LogWarning("初速度: " + shootSpeed + " 帧数: " + keyAccList.Count);
+            //本轮计算结束
             keyAccList.Clear();
+            maxAcc = 0;
             Dolock();
             Invoke("Unlock", 1.8f);
             return true;

+ 21 - 21
Assets/BowArrow/Scripts/Game/ArmBow.cs

@@ -120,27 +120,27 @@ public class ArmBow : MonoBehaviour
 
         // 筛选出一个稳定的发射角度---start
         Quaternion best_rotation = this.bowCamera.transform.rotation;
-        if (recordCount >= recordRotations.Length) {
-            int single_check_count = 6;
-            float min_wave = float.MaxValue;
-            for (int i = 0; i < recordRotationVars.Length; i++)
-            {
-                recordRotationVars[i] = Quaternion.Angle(recordRotations[i], recordRotations[i + 1]);
-                if (i >= single_check_count - 1) 
-                {
-                    float wave = 0;
-                    for (int j = i; j > i - single_check_count; j--)
-                    {
-                        wave += recordRotationVars[j];
-                    }
-                    if (wave < min_wave)
-                    {
-                        min_wave = wave;
-                        best_rotation = recordRotations[i - single_check_count + 1];
-                    }
-                }
-            }
-        }
+        // if (recordCount >= recordRotations.Length) {
+        //     int single_check_count = 6;
+        //     float min_wave = float.MaxValue;
+        //     for (int i = 0; i < recordRotationVars.Length; i++)
+        //     {
+        //         recordRotationVars[i] = Quaternion.Angle(recordRotations[i], recordRotations[i + 1]);
+        //         if (i >= single_check_count - 1) 
+        //         {
+        //             float wave = 0;
+        //             for (int j = i; j > i - single_check_count; j--)
+        //             {
+        //                 wave += recordRotationVars[j];
+        //             }
+        //             if (wave < min_wave)
+        //             {
+        //                 min_wave = wave;
+        //                 best_rotation = recordRotations[i - single_check_count + 1];
+        //             }
+        //         }
+        //     }
+        // }
         // 筛选出一个稳定的发射角度---end
         Vector3 shootOutPosition = this.bowCamera.transform.position;
         //如果弓指向太过朝下,在弓口发射可能会射穿地面,因此需要角度适当时,才从弓口射出。

+ 8 - 16
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -23,6 +23,12 @@ public class Arrow : MonoBehaviour
         if (GameAssistUI.ins) {
             speedCopy *= (1 + GameAssistUI.ins.shootScaleValue);
         } 
+
+        //箭刚射出去时,角度往上抬一点
+        float distance = TargetBody.ins.GetDistance();
+        this.transform.Rotate(Vector3.left, Mathf.Clamp(distance / 50 * 20, 0, 20));
+
+
         newRigidbody.velocity = this.transform.forward * speedCopy;
         newRigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
         
@@ -30,7 +36,6 @@ public class Arrow : MonoBehaviour
         cameraTF.gameObject.SetActive(true);
         cameraTF.gameObject.AddComponent<ArrowCamera>().arrow = this;
 
-        this.activeEffectCyclone(true);
         this.activeEffectTrail(true);
     }
 
@@ -145,25 +150,12 @@ public class Arrow : MonoBehaviour
         this.transform.SetParent(collision.transform.parent);
     }
 
-    void activeEffectCyclone(bool value)
+    public void activeEffectCyclone(bool value)
     {
         this.transform.Find("Head/EF_kuosanquan").gameObject.SetActive(value);
+        if (!value) return;
         ParticleSystemRenderer ps = this.transform.Find("Head/EF_kuosanquan/kuosan").GetComponent<ParticleSystemRenderer>();
         ParticleSystemRenderer ps1 = this.transform.Find("Head/EF_kuosanquan/kuosan (1)").GetComponent<ParticleSystemRenderer>();
-        // if (!followArrow) {
-        //     ps.minParticleSize = 0.3f;
-        //     ps.maxParticleSize = 0.3f;
-        //     ps1.minParticleSize = 0.6f;
-        //     ps1.maxParticleSize = 0.6f;
-        // }
-        // DOTween.To(() => ps.minParticleSize, value => {
-        //     ps.minParticleSize = value;
-        //     ps.maxParticleSize = value;
-        // }, followArrow ? 0.6f : 0.06f, 0.6f);
-        // DOTween.To(() => ps1.minParticleSize, value => {
-        //     ps1.minParticleSize = value;
-        //     ps1.maxParticleSize = value;
-        // }, followArrow ? 1.2f : 0.12f, 0.6f);
         DOTween.To(() => ps.minParticleSize, value => {
             ps.minParticleSize = value;
             ps.maxParticleSize = value;

+ 15 - 5
Assets/BowArrow/Scripts/Game/ArrowCamera.cs

@@ -10,8 +10,16 @@ public class ArrowCamera : MonoBehaviour
 
     void Start()
     {
-        if (Random.value < 0.5) arrowCameraTemplate = new ArrowCameraTemplate1(this);    
-        else arrowCameraTemplate = new ArrowCameraTemplate2(this);
+        float distance = TargetBody.ins.GetDistance();
+        if (Mathf.RoundToInt(distance) >= 50)
+        {
+            if (Random.value < 0.5) arrowCameraTemplate = new ArrowCameraTemplate1(this);    
+            else arrowCameraTemplate = new ArrowCameraTemplate2(this);
+        }
+        else 
+        {
+            arrowCameraTemplate = new ArrowCameraTemplate1(this);    
+        }
         // arrowCameraTemplate = new ArrowCameraTemplate2(this);
     }
 
@@ -25,8 +33,8 @@ class ArrowCameraTemplate2 : ArrowCameraTemplate
 {
     public ArrowCameraTemplate2(ArrowCamera arrowCamera)  : base(arrowCamera) {
         this.arrowCamera.transform.parent = null;
-        arrowCamera.transform.localPosition = new Vector3(9.94f, 2.24f, 1.74f);
-        arrowCamera.transform.localEulerAngles = new Vector3(0, -52.32f, 0);
+        arrowCamera.transform.localPosition = new Vector3(8.33f, 2.45f, 6.4f);
+        arrowCamera.transform.localEulerAngles = new Vector3(0, -56, 0);
     }
 
     bool isHit = false;
@@ -54,7 +62,9 @@ class ArrowCameraTemplate2 : ArrowCameraTemplate
 }
 class ArrowCameraTemplate1 : ArrowCameraTemplate 
 {
-    public ArrowCameraTemplate1(ArrowCamera arrowCamera)  : base(arrowCamera) {}
+    public ArrowCameraTemplate1(ArrowCamera arrowCamera)  : base(arrowCamera) {
+        this.arrowCamera.arrow.activeEffectCyclone(true);
+    }
     
     /**相机移动 */
     private bool cameraMoveFinish = false;

+ 5 - 3
Assets/BowArrow/Scripts/Game/TargetBody.cs

@@ -3,9 +3,11 @@
 public class TargetBody : MonoBehaviour
 {
     float distance = 70f;
+    public static TargetBody ins;
 
     void Start()
     {
+        ins = this;
         SetDistance(distance);
     }
 
@@ -20,8 +22,8 @@ public class TargetBody : MonoBehaviour
             if (arrow.armBow.validTargets.Contains(this)) {
                 float maxSize = Vector3.Distance(this.transform.Find("CenterPoint").position, this.transform.Find("SidePoint").position);
                 float radius = this.measureRadius(collision.contacts[0].point);
-                int score = 10 - Mathf.FloorToInt(radius / maxSize * 5);
-                if (score > 5) {
+                int score = 10 - Mathf.FloorToInt(radius / maxSize * 10);
+                if (score > 0) {
                     GameMgr.ins.gameMode.HitTarget(score);
                     AudioMgr.ins.PlayCheer(true);
                     hitTarget = true;
@@ -41,7 +43,7 @@ public class TargetBody : MonoBehaviour
     public void SetDistance(float value) {
         distance = value;
         Vector3 v3 = this.transform.parent.localPosition;
-        v3.x = 11.85766f - GameMgr.RealSizeToGameSize(value);
+        v3.x = 9.815f - GameMgr.RealSizeToGameSize(value);
         this.transform.parent.localPosition = v3;
     }
 

+ 31 - 7
Assets/BowArrow/Scripts/Manager/GameMgr.cs

@@ -259,23 +259,27 @@ public class TimeLimitGameMode : GameMode {
 }
 /**双人PK模式 */
 public class PKGameMode : GameMode {
-    public int currentPlayerID = 1;
+    public int currentPlayerIndex = 0;
     public int[] totalScores = {0, 0};
     public int[] currentScores = {0, 0};
     public int round = 1;
     float[] targetDistancesOnRound = {10, 20, 30, 50, 70, 70};
     int maxRound = 5;
     int shootCount = 0;
-    int maxShootCount = 3;
+    int maxShootCount = 1;
     public float singleShootReadyTime = 20;
     public float singleShootReadyMaxTime = 20;
     bool singleShootTimeRunning = false;
     public static int[] playerRoleIDs = {1, 2};
     string[] gameRes = {"平局", "平局"};
+    //本回合玩家先后顺序
+    Queue<int> playerIndexSequence = new Queue<int>();
     //记录可射击的靶子
     TargetBody targetBody;
 
     public PKGameMode(GameMgr gameMgr) : base(gameMgr) {
+        InitPlayerIndexSequence();
+        currentPlayerIndex = playerIndexSequence.Dequeue();
         //记录可射击的靶子
         targetBody = GameObject.Find("GameArea/010/TargetBody").GetComponent<TargetBody>();
         GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(targetBody);
@@ -292,6 +296,26 @@ public class PKGameMode : GameMode {
         AddReadyView();
     }
 
+    int[] playerIndexSequenceRecord = {0, 1};
+    void InitPlayerIndexSequence()
+    {
+        if (round >= 3)
+        {
+            if (totalScores[0] < totalScores[1])
+            {
+                playerIndexSequenceRecord = new int[]{0, 1};
+            }
+            else if (totalScores[1] < totalScores[0])
+            {
+                playerIndexSequenceRecord = new int[]{1, 0};
+            }
+        } else {
+            playerIndexSequenceRecord = new int[]{0, 1};
+        }
+        playerIndexSequence.Enqueue(playerIndexSequenceRecord[0]);
+        playerIndexSequence.Enqueue(playerIndexSequenceRecord[1]);
+    }
+
     void AddReadyView() 
     {
         GameObject view = Resources.Load<GameObject>("Prefabs/Views/PKGameReadyView");
@@ -299,7 +323,7 @@ public class PKGameMode : GameMode {
     }
 
     public override void HitTarget(int score) {
-        currentScores[currentPlayerID - 1] += score;
+        currentScores[currentPlayerIndex] += score;
         shootCount++;
         HitTargetNumber.Create(score);
     }
@@ -312,8 +336,7 @@ public class PKGameMode : GameMode {
         if (shootCount == maxShootCount) {
             shootCount = 0;
             //当局是否结束
-            if (currentPlayerID == 2) {
-                currentPlayerID = 1;
+            if (playerIndexSequence.Count == 0) {
                 nextRound = true;
                 //更新总比分
                 if (currentScores[0] == currentScores[1]) {
@@ -340,8 +363,6 @@ public class PKGameMode : GameMode {
                     gameEnd = true;
                     gameRes = new string[]{"失败", "胜利"};
                 }
-            } else {
-                currentPlayerID = 2;
             }
             nextPlayer = true;
         }
@@ -356,8 +377,11 @@ public class PKGameMode : GameMode {
             if (nextRound) {
                 round++;
                 currentScores[0] = currentScores[1] = 0;
+                InitPlayerIndexSequence();
                 targetBody.SetDistance(targetDistancesOnRound[round - 1]);
             }
+            //本轮玩家登记
+            currentPlayerIndex = playerIndexSequence.Dequeue();
             //准备切换玩家
             BanBowReady();
             AddReadyView();

+ 1 - 1
Assets/BowArrow/Scripts/View/PKGameReadyView.cs

@@ -13,7 +13,7 @@ public class PKGameReadyView : MonoBehaviour
         GameObject.FindObjectOfType<ArmBow>().Hide();
         
         pKGameMode = (PKGameMode) GameMgr.ins.gameMode;
-        (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[pKGameMode.currentPlayerID - 1]);
+        (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[pKGameMode.currentPlayerIndex]);
         this.transform.Find("Panel/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
         this.transform.Find("Panel/Name").GetComponent<Text>().text = nickName;
         Image mask = this.transform.Find("Mask").GetComponent<Image>();

+ 5 - 5
Assets/BowArrow/Scripts/View/PKGameView.cs

@@ -8,7 +8,7 @@ public class PKGameView : MonoBehaviour
 {
     [SerializeField] Text[] scoreTexts;
     PKGameMode pKGameMode;
-    int currentPlayerID;
+    int currentPlayerIndex = -1;
     string[] numCNs = {"", "第一局", "第二局", "第三局", "第四局", "第五局", "第六局"};
     string[] numENs = {"", "1st leg", "2st leg", "3st leg", "4st leg", "5st leg", "6st leg"};
 
@@ -37,14 +37,14 @@ public class PKGameView : MonoBehaviour
         scoreTexts[2].text = pKGameMode.currentScores[1].ToString();
         scoreTexts[3].text = pKGameMode.totalScores[0] + " : " + pKGameMode.totalScores[1];
             
-        if (currentPlayerID != pKGameMode.currentPlayerID)
+        if (currentPlayerIndex != pKGameMode.currentPlayerIndex)
         {
-            currentPlayerID = pKGameMode.currentPlayerID;
-            (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[currentPlayerID - 1]);
+            currentPlayerIndex = pKGameMode.currentPlayerIndex;
+            (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(PKGameMode.playerRoleIDs[currentPlayerIndex]);
             this.transform.Find("CurrentPlayer/Avatar").GetComponent<Image>().sprite = avatar;
             this.transform.Find("CurrentPlayer/Name").GetComponent<Text>().text = nickName;
         }
-        if (currentPlayerID == pKGameMode.currentPlayerID) 
+        if (currentPlayerIndex == pKGameMode.currentPlayerIndex) 
         {
             this.transform.Find("CurrentPlayer/Progress").GetComponent<Image>().fillAmount = pKGameMode.singleShootReadyTime / pKGameMode.singleShootReadyMaxTime;
             this.transform.Find("CurrentPlayer/Time").GetComponent<Text>().text = pKGameMode.GetTimeStr();

BIN
Assets/MeiShu Asset/GameArea/New Folder/Textures/Mapping_003.png


+ 1 - 1
ProjectSettings/DynamicsManager.asset

@@ -4,7 +4,7 @@
 PhysicsManager:
   m_ObjectHideFlags: 0
   serializedVersion: 13
-  m_Gravity: {x: 0, y: -4.061, z: 0}
+  m_Gravity: {x: 0, y: -9.81, z: 0}
   m_DefaultMaterial: {fileID: 0}
   m_BounceThreshold: 2
   m_DefaultMaxDepenetrationVelocity: 10

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.