From 2f72e3b08d3ce38c02a8fa94e27662f702d63be9 Mon Sep 17 00:00:00 2001 From: bzx <496597135@qq.com> Date: Wed, 21 Jan 2026 13:43:20 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BD=BF=E7=94=A8=E5=AE=8C?= =?UTF-8?q?=E6=9E=AA=E6=A2=B0=20=E5=88=A0=E9=99=A4=E6=9E=AA=E6=A2=B0?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=90=8E=E6=9C=9F=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/_Zombie/Scripts/Guns/Launcher.cs | 9 ++++---- Assets/_Zombie/Scripts/Guns/NewGun/BeamGun.cs | 17 +++++++-------- .../_Zombie/Scripts/Guns/NewGun/GrenadeGun.cs | 17 +++++++-------- Assets/_Zombie/Scripts/Guns/NewGun/Gun2.cs | 20 ------------------ Assets/_Zombie/Scripts/Guns/NewGun/Gun4.cs | 18 +++++++--------- Assets/_Zombie/Scripts/Guns/NewGun/Pistol.cs | 14 +++++++++---- Assets/_Zombie/Scripts/MRInput.cs | 21 +++++++++++++++---- Assets/_Zombie/Scripts/Player.cs | 3 ++- 8 files changed, 56 insertions(+), 63 deletions(-) diff --git a/Assets/_Zombie/Scripts/Guns/Launcher.cs b/Assets/_Zombie/Scripts/Guns/Launcher.cs index 00864467..3206a701 100644 --- a/Assets/_Zombie/Scripts/Guns/Launcher.cs +++ b/Assets/_Zombie/Scripts/Guns/Launcher.cs @@ -121,10 +121,10 @@ public class Launcher : NetworkBehaviour public virtual bool Shoot(Vector3 target, int ownerIndex) { // 弹量不够 - if (bullet_amount <= 0 && bullet_amount != -999) - { - return false; - } + // if (bullet_amount <= 0 && bullet_amount != -999) + // { + // return false; + // } // 未冷却 if (nextShootTime > Time.time) @@ -139,6 +139,7 @@ public class Launcher : NetworkBehaviour if (bullet_amount <= 0 && bullet_amount != -999) { LauncherEmpty(); + return false; } for (int i = 0; i < bullet_per_shoot; i++) diff --git a/Assets/_Zombie/Scripts/Guns/NewGun/BeamGun.cs b/Assets/_Zombie/Scripts/Guns/NewGun/BeamGun.cs index 9a54d782..812381ff 100644 --- a/Assets/_Zombie/Scripts/Guns/NewGun/BeamGun.cs +++ b/Assets/_Zombie/Scripts/Guns/NewGun/BeamGun.cs @@ -14,11 +14,7 @@ public class BeamGun : Launcher GunInfo gunInfo = GameManager.Ins.GunInfos[type]; shootRate = gunInfo.ShootRate; recoil = gunInfo.Recoil; - if (hand == HandType.Left) - { - MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - } - else if (hand == HandType.Right) + if (hand == HandType.Right) { MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger); } @@ -34,16 +30,17 @@ public class BeamGun : Launcher // 从机自身 else if (isClient && isOwned) { - if (hand == HandType.Left) - { - MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - } - else if (hand == HandType.Right) + if (hand == HandType.Right) { MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger); } } } + + private void OnDestroy() + { + MRInput.Ins.UnregisterHoldPressRightTrigger(ClickRrightTrigger); + } public void Update() { diff --git a/Assets/_Zombie/Scripts/Guns/NewGun/GrenadeGun.cs b/Assets/_Zombie/Scripts/Guns/NewGun/GrenadeGun.cs index 4ce0444a..3057dea3 100644 --- a/Assets/_Zombie/Scripts/Guns/NewGun/GrenadeGun.cs +++ b/Assets/_Zombie/Scripts/Guns/NewGun/GrenadeGun.cs @@ -15,11 +15,7 @@ public class GrenadeGun : Launcher GunInfo gunInfo = GameManager.Ins.GunInfos[type]; shootRate = gunInfo.ShootRate; recoil = gunInfo.Recoil; - if (hand == HandType.Left) - { - MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - } - else if (hand == HandType.Right) + if (hand == HandType.Right) { MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger); } @@ -35,16 +31,17 @@ public class GrenadeGun : Launcher // 从机自身 else if (isClient && isOwned) { - if (hand == HandType.Left) - { - MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - } - else if (hand == HandType.Right) + if (hand == HandType.Right) { MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger); } } } + + private void OnDestroy() + { + MRInput.Ins.UnregisterHoldPressRightTrigger(ClickRrightTrigger); + } public void Update() { diff --git a/Assets/_Zombie/Scripts/Guns/NewGun/Gun2.cs b/Assets/_Zombie/Scripts/Guns/NewGun/Gun2.cs index 746ced3e..bb54612f 100644 --- a/Assets/_Zombie/Scripts/Guns/NewGun/Gun2.cs +++ b/Assets/_Zombie/Scripts/Guns/NewGun/Gun2.cs @@ -29,14 +29,6 @@ public class Gun2 : Launcher GunInfo gunInfo = GameManager.Ins.GunInfos[type]; shootRate = gunInfo.ShootRate; recoil = gunInfo.Recoil; - // if (hand == HandType.Left) - // { - // MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - // } - // else if (hand == HandType.Right) - // { - // MRInput.Ins.RegisterHoldPressRightTrigger(ClickLeftTrigger); - // } } // 主机其他 else if (isServer && isClient) @@ -46,18 +38,6 @@ public class Gun2 : Launcher shootRate = gunInfo.ShootRate; recoil = gunInfo.Recoil; } - // 从机自身 - else if (isClient && isOwned) - { - // if (hand == HandType.Left) - // { - // MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - // } - // else if (hand == HandType.Right) - // { - // MRInput.Ins.RegisterHoldPressRightTrigger(ClickLeftTrigger); - // } - } shot.SetActive(false); bullet_attack = GameManager.Ins.BulletInfos[(BulletType)type].Damage; shotSource.enabled = false; diff --git a/Assets/_Zombie/Scripts/Guns/NewGun/Gun4.cs b/Assets/_Zombie/Scripts/Guns/NewGun/Gun4.cs index 295681b1..796edd51 100644 --- a/Assets/_Zombie/Scripts/Guns/NewGun/Gun4.cs +++ b/Assets/_Zombie/Scripts/Guns/NewGun/Gun4.cs @@ -18,11 +18,7 @@ public class Gun4 : Launcher GunInfo gunInfo = GameManager.Ins.GunInfos[type]; shootRate = gunInfo.ShootRate; recoil = gunInfo.Recoil; - if (hand == HandType.Left) - { - MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - } - else if (hand == HandType.Right) + if (hand == HandType.Right) { MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger); } @@ -38,16 +34,18 @@ public class Gun4 : Launcher // 从机自身 else if (isClient && isOwned) { - if (hand == HandType.Left) - { - MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger); - } - else if (hand == HandType.Right) + + if (hand == HandType.Right) { MRInput.Ins.RegisterHoldPressRightTrigger(ClickLeftTrigger); } } } + + private void OnDestroy() + { + MRInput.Ins.UnregisterHoldPressRightTrigger(ClickRrightTrigger); + } public void Update() { diff --git a/Assets/_Zombie/Scripts/Guns/NewGun/Pistol.cs b/Assets/_Zombie/Scripts/Guns/NewGun/Pistol.cs index 0977e0a4..d35bfc3f 100644 --- a/Assets/_Zombie/Scripts/Guns/NewGun/Pistol.cs +++ b/Assets/_Zombie/Scripts/Guns/NewGun/Pistol.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using Mirror; @@ -45,13 +46,18 @@ public class Pistol : Launcher } } + private void OnDestroy() + { + MRInput.Ins.UnregisterHoldPressRightTrigger(ClickRrightTrigger); + } + public void Update() { if (!isOwned) { return; } - + // 左手 if (hand == HandType.Left) { @@ -64,13 +70,13 @@ public class Pistol : Launcher transform.position = GameLocal.Ins.self.RightHand.position; transform.rotation = GameLocal.Ins.self.RightHand.rotation; } - + } [Client] public void ClickLeftTrigger() { - if(gameObject.activeSelf) + if (gameObject.activeSelf) CmdShoot(); } @@ -86,4 +92,4 @@ public class Pistol : Launcher { Shoot(); } -} +} \ No newline at end of file diff --git a/Assets/_Zombie/Scripts/MRInput.cs b/Assets/_Zombie/Scripts/MRInput.cs index 25380ecf..7f68924e 100644 --- a/Assets/_Zombie/Scripts/MRInput.cs +++ b/Assets/_Zombie/Scripts/MRInput.cs @@ -16,6 +16,7 @@ public class MRInput : MonoBehaviour [UnityEngine.DisplayOnly] #endif public bool pressLeftTrigger = false; + private bool _lastPressLeftTrigger = false; private List _clickLeftTriggerhandlers = new List(); @@ -23,6 +24,7 @@ public class MRInput : MonoBehaviour [UnityEngine.DisplayOnly] #endif public bool holdPressLeftTrigger = false; + private List _holdPressLeftTriggerhandlers = new List(); @@ -30,6 +32,7 @@ public class MRInput : MonoBehaviour [UnityEngine.DisplayOnly] #endif public bool pressRightTrigger = false; + private bool _lastPressRightTrigger = false; private List _clickRightTriggerhandlers = new List(); @@ -37,6 +40,7 @@ public class MRInput : MonoBehaviour [UnityEngine.DisplayOnly] #endif public bool holdPressRightTrigger = false; + private List _holdPressRightTriggerhandlers = new List(); void Start() @@ -80,6 +84,15 @@ public class MRInput : MonoBehaviour _holdPressRightTriggerhandlers.Add(handler); } + /// + /// 注销持续点击右trigger事件 + /// + public void UnregisterHoldPressRightTrigger(System.Action handler) + { + if (_holdPressRightTriggerhandlers.Contains(handler)) + _holdPressRightTriggerhandlers.Remove(handler); + } + /// /// 震动左手控制器 /// @@ -95,7 +108,7 @@ public class MRInput : MonoBehaviour /// public void VibrateRightController(float amplitude, int duration, int frequency = 150) { - + #if !UNITY_EDITOR && UNITY_ANDROID && PICO PXR_Input.SendHapticImpulse(VibrateType.RightController, amplitude, duration, frequency); #endif @@ -103,9 +116,9 @@ public class MRInput : MonoBehaviour void Update() { - if(GameLocal.Ins.self==null||GameLocal.Ins.self.isDie) + if (GameLocal.Ins.self == null || GameLocal.Ins.self.isDie) return; - if(GameManager.Ins==null|| !GameManager.Ins.isStart) + if (GameManager.Ins == null || !GameManager.Ins.isStart) return; #if !UNITY_EDITOR && UNITY_ANDROID && PICO if (_leftHandDevice != null) @@ -190,4 +203,4 @@ public class MRInput : MonoBehaviour } #endif } -} +} \ No newline at end of file diff --git a/Assets/_Zombie/Scripts/Player.cs b/Assets/_Zombie/Scripts/Player.cs index 6c9ff91a..937541f2 100644 --- a/Assets/_Zombie/Scripts/Player.cs +++ b/Assets/_Zombie/Scripts/Player.cs @@ -366,6 +366,7 @@ public class Player : NetworkRoomPlayer,IDamagable if (Guns.Count <= 0) { Debug.Log("无武器"); + PickUpGun(GunType.Pistol,-999); return; } @@ -456,7 +457,7 @@ public class Player : NetworkRoomPlayer,IDamagable if (rightGun != null) { rightGun.gameObject.SetActive(false); - NetworkServer.UnSpawn(rightGun.gameObject); + NetworkServer.Destroy(rightGun.gameObject); rightGun = null; }