fix:使用完枪械 删除枪械,解决后期卡顿问题

This commit is contained in:
bzx
2026-01-21 13:43:20 +08:00
parent 7d584c3cd9
commit 2f72e3b08d
8 changed files with 56 additions and 63 deletions

View File

@ -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++)

View File

@ -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()
{

View File

@ -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()
{

View File

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

View File

@ -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()
{

View File

@ -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();
}
}
}

View File

@ -16,6 +16,7 @@ public class MRInput : MonoBehaviour
[UnityEngine.DisplayOnly]
#endif
public bool pressLeftTrigger = false;
private bool _lastPressLeftTrigger = false;
private List<System.Action> _clickLeftTriggerhandlers = new List<System.Action>();
@ -23,6 +24,7 @@ public class MRInput : MonoBehaviour
[UnityEngine.DisplayOnly]
#endif
public bool holdPressLeftTrigger = false;
private List<System.Action> _holdPressLeftTriggerhandlers = new List<System.Action>();
@ -30,6 +32,7 @@ public class MRInput : MonoBehaviour
[UnityEngine.DisplayOnly]
#endif
public bool pressRightTrigger = false;
private bool _lastPressRightTrigger = false;
private List<System.Action> _clickRightTriggerhandlers = new List<System.Action>();
@ -37,6 +40,7 @@ public class MRInput : MonoBehaviour
[UnityEngine.DisplayOnly]
#endif
public bool holdPressRightTrigger = false;
private List<System.Action> _holdPressRightTriggerhandlers = new List<System.Action>();
void Start()
@ -80,6 +84,15 @@ public class MRInput : MonoBehaviour
_holdPressRightTriggerhandlers.Add(handler);
}
/// <summary>
/// 注销持续点击右trigger事件
/// </summary>
public void UnregisterHoldPressRightTrigger(System.Action handler)
{
if (_holdPressRightTriggerhandlers.Contains(handler))
_holdPressRightTriggerhandlers.Remove(handler);
}
/// <summary>
/// 震动左手控制器
/// </summary>
@ -95,7 +108,7 @@ public class MRInput : MonoBehaviour
/// </summary>
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
}
}
}

View File

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