lvjincheng il y a 4 ans
Parent
commit
4628dd0fda

+ 4 - 0
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -288,6 +288,7 @@ public class Arrow : MonoBehaviour
         }
     }
 
+    [NonSerialized] public int hitType = 0;
     //飞行逻辑中检测到碰撞
     void OnHitAnyInFlyLogic(RaycastHit raycastHit) {
         this.Head().position = raycastHit.point;
@@ -302,6 +303,7 @@ public class Arrow : MonoBehaviour
             this.arrowCameraComp.arrowCameraTemplate?.beforeHit();
             raycastHit.transform.GetComponent<TargetBody>().Hit(this, hitPoint);
         } else if (targetName.StartsWith("TargetAnimalPart")) {
+            hitType = 5;
             Vector3 hitPoint = raycastHit.point;
             string partName = targetName.Split(new char[]{'_'})[1];
             this.arrowCameraComp.arrowCameraTemplate?.beforeHit();
@@ -316,8 +318,10 @@ public class Arrow : MonoBehaviour
             GameMgr.ins.gameMode.HitTarget(0);
             //击中其它东西时的音效
             if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "GameChallenge") {
+                hitType = 4;
                 AudioMgr.ins.PlayArrowEnter();
             } else {
+                hitType = 3;
                 AudioMgr.ins.PlayCheer(false);
             }
         }

+ 1 - 0
Assets/BowArrow/Scripts/Game/TargetBody.cs

@@ -39,6 +39,7 @@ public class TargetBody : MonoBehaviour
             GameMgr.ins.gameMode.HitTarget(0);
             AudioMgr.ins.PlayCheer(false);
         }
+        arrow.hitType = hitTarget ? 1 : 2; 
     }
 
     float measureRadius(Vector3 position) {

+ 15 - 0
Assets/BowArrow/Scripts/Manager/GameMode/OnlineObject/ArrowSync.cs

@@ -22,6 +22,7 @@ public class ArrowSync : MonoBehaviour
 
     Quaternion rotation;
     Vector3 position;
+    bool hasPlayHitAudio = false;
     [System.NonSerialized] public bool isHit;
     [System.NonSerialized] public bool canUseSideCamera;
     [System.NonSerialized] public bool hasSetSyncData = false; //外部运算用的
@@ -46,6 +47,18 @@ public class ArrowSync : MonoBehaviour
             //射出的声音
             AudioMgr.ins.PlayShoot(AudioMgr.GetAudioSource(this.gameObject));
         }
+        if (isHit && !hasPlayHitAudio) {
+            hasPlayHitAudio = true;
+            int hitType = syncData.ht;
+            if (hitType == 1 || hitType == 2) {
+                AudioMgr.ins.PlayHit(AudioMgr.GetAudioSource(TargetBody.ins.gameObject));
+                AudioMgr.ins.PlayCheer(hitType == 1 ? true : false);
+            } else if (hitType == 4 || hitType == 5) {
+                AudioMgr.ins.PlayArrowEnter();
+            } else if (hitType == 3) {
+                AudioMgr.ins.PlayCheer(false);
+            }
+        }
     }
 
     public class SyncData {
@@ -61,6 +74,7 @@ public class ArrowSync : MonoBehaviour
         public float pz;
         public bool cs;
         public bool ih;
+        public int ht;
         public void SetData(Arrow arrow) {
             Quaternion r = arrow.transform.rotation;
             Vector3 p = arrow.Head().transform.position;
@@ -73,6 +87,7 @@ public class ArrowSync : MonoBehaviour
             pz = p.z;
             cs = arrow.canUseSideCamera;
             ih = arrow.isHit;
+            ht = arrow.hitType;
             if (!inited) {
                 id = autoID++;
                 if (autoID > 1000) autoID = 0;

+ 0 - 1
Assets/BowArrow/Scripts/Manager/GameMode/PKGameMode_OnlinePK.cs

@@ -109,7 +109,6 @@ public class PKGameMode_OnlinePK : GameMode {
         }
         if (key == "score") {
             HitTargetNumber.Create(float.Parse(data));
-            AudioMgr.ins.PlayHit(AudioMgr.GetAudioSource(TargetBody.ins.gameObject));
         }
     }