fix::修复一些联机中的问题

This commit is contained in:
bzx
2025-09-04 16:29:12 +08:00
parent aa4ba610ef
commit df67ddb9da
40 changed files with 411 additions and 4943 deletions

View File

@@ -7,8 +7,6 @@ using UnityEngine;
public class Explosion : NetworkBehaviour
{
[SoundGroup] public string explosionSound;
public GameObject[] explosions;
public float radius = 3f; // 检测半径
@@ -16,10 +14,6 @@ public class Explosion : NetworkBehaviour
public int damage = 10;
public void Init(int id)
{
if (isClient)
{
MasterAudio.PlaySound3DAtVector3(explosionSound, transform.position);
}
foreach (var obj in explosions)
{
obj.SetActive(false);

View File

@@ -319,6 +319,13 @@ public class GameManager : NetworkBehaviour
EnemyList.Add(enemyIndex, enemyScript);
yield return new WaitForSeconds(info.BornTime);
}
CloseWu();
}
[ClientRpc]
public void CloseWu()
{
GameLocal.Ins.CloseWu();
}
@@ -424,7 +431,7 @@ public class GameManager : NetworkBehaviour
int totalWeight = 0;
int targetWeight = Random.Range(24, 27); // 24-26
int targetCount = Random.Range(4, 8); // 4-7
int targetCount = Random.Range(6, 10); // 4-7
// 随机添加怪物直到接近目标
while (monsterTypes.Count < targetCount && totalWeight < targetWeight)
@@ -455,8 +462,6 @@ public class GameManager : NetworkBehaviour
monsterTypes.Add(minIndex);
totalWeight += weights[minIndex];
}
Debug.LogError("生成的敌人数量:"+targetCount);
return monsterTypes.ToArray();
}
@@ -514,9 +519,15 @@ public class GameManager : NetworkBehaviour
{
CreateGunProp();
CreateNextRound();
GameLocal.Ins.OpenWu();
OpenWu();
}
}
[ClientRpc]
public void OpenWu()
{
GameLocal.Ins.OpenWu();
}
/// <summary>
/// 痛击场上所有敌方单位
/// </summary>

View File

@@ -63,10 +63,6 @@ public class Launcher : NetworkBehaviour
public GameObject muzzle_prefab;
[Header("开火销毁时间")]
public float muzzle_despawn_time = 1;
[Header("开枪音效")]
[SoundGroup]
public string shotSound;
[Header("弹壳创建位置")]
public Transform shellPoint;
@@ -139,7 +135,6 @@ public class Launcher : NetworkBehaviour
if (bullet_amount > 0&& GameManager.Ins.gameState==GameState.Playing)
{
bullet_amount--;
DragonLi.Core.EventDispatcher.TriggerEvent("UserGun", bullet_amount);
}
if (bullet_amount <= 0 && bullet_amount != -999)
{
@@ -150,8 +145,6 @@ public class Launcher : NetworkBehaviour
{
SpawnBullet(ownerIndex, target - bulletPoint.position);
}
//GameManager.Ins.PlaySound3DRPC(shotSound,transform,false);
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
SpawnShell();
SpawnMuzzle();
nextShootTime = Time.time + _shootInterval;

View File

@@ -20,7 +20,7 @@ public class BeamGun : Launcher
}
else if (hand == HandType.Right)
{
MRInput.Ins.RegisterHoldPressRightTrigger(ClickLeftTrigger);
MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger);
}
}
// 主机其他
@@ -40,7 +40,7 @@ public class BeamGun : Launcher
}
else if (hand == HandType.Right)
{
MRInput.Ins.RegisterHoldPressRightTrigger(ClickLeftTrigger);
MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger);
}
}
}
@@ -77,7 +77,7 @@ public class BeamGun : Launcher
[Client]
public void ClickRrightTrigger()
{
Debug.Log("点击右trigger");
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
CmdShoot();
}

View File

@@ -21,7 +21,7 @@ public class GrenadeGun : Launcher
}
else if (hand == HandType.Right)
{
MRInput.Ins.RegisterHoldPressRightTrigger(ClickLeftTrigger);
MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger);
}
}
// 主机其他
@@ -41,11 +41,9 @@ public class GrenadeGun : Launcher
}
else if (hand == HandType.Right)
{
MRInput.Ins.RegisterHoldPressRightTrigger(ClickLeftTrigger);
MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger);
}
}
Debug.LogError("射速:"+shootRate);
}
public void Update()
@@ -81,7 +79,7 @@ public class GrenadeGun : Launcher
[Client]
public void ClickRrightTrigger()
{
Debug.Log("点击右trigger");
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
CmdShoot();
}

View File

@@ -97,6 +97,7 @@ public class Gun2 : Launcher
if ((isTrigger||isGrip)&&!GameLocal.Ins.self.isDie&& GameManager.Ins.isStart)
{
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
CmdShot();
}
else
@@ -108,13 +109,12 @@ public class Gun2 : Launcher
[Command]
public void CmdShot()
{
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
if (GameManager.Ins.gameState == GameState.Playing)
{
if (bullet_amount>0)
{
bullet_amount-=Time.deltaTime;
EventDispatcher.TriggerEvent("UserGun", bullet_amount);
}
}
// 获取范围内所有碰撞体
@@ -142,16 +142,20 @@ public class Gun2 : Launcher
{
lastDamageTime = Time.time;
}
Debug.LogError("剩余子弹数量:"+bullet_amount);
SetShot(true);
// 武器寿命逻辑
if (bullet_amount<=0)
{
bullet_amount = 0;
GameLocal.Ins.self.DelWeapon();
DelWeapon();
}
}
[TargetRpc]
public void DelWeapon()
{
bullet_amount = 0;
GameLocal.Ins.self.DelWeapon();
}
[Command]
public void CmdCloseShot()

View File

@@ -80,6 +80,7 @@ public class Gun3 : Launcher
if ((isTrigger||isGrip)&&!GameLocal.Ins.self.isDie&& GameManager.Ins.isStart)
{
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
CmdShot();
}
else
@@ -93,7 +94,6 @@ public class Gun3 : Launcher
{
frame++;
xl.SetActive(true);
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
if (frame >= 70)
{
xl.SetActive(false);
@@ -102,7 +102,6 @@ public class Gun3 : Launcher
if (bullet_amount>0)
{
bullet_amount-=Time.deltaTime;
EventDispatcher.TriggerEvent("UserGun", bullet_amount);
}
}
RaycastHit raycast;
@@ -118,6 +117,7 @@ public class Gun3 : Launcher
// 控制伤害间隔
if (Time.time - lastDamageTime >= damageInterval)
{
ApplyDamage(raycast.transform); // 敌人受伤
}
}
@@ -129,14 +129,20 @@ public class Gun3 : Launcher
lastDamageTime = Time.time;
}
}
Debug.LogError("剩余子弹数量:"+bullet_amount);
// 武器寿命逻辑
if (bullet_amount<=0)
{
bullet_amount = 0;
GameLocal.Ins.self.DelWeapon();
DelWeapon();
}
}
[TargetRpc]
public void DelWeapon()
{
bullet_amount = 0;
GameLocal.Ins.self.DelWeapon();
}
[Command]
public void CmdCloseShot()

View File

@@ -70,7 +70,6 @@ public class Pistol : Launcher
[Client]
public void ClickLeftTrigger()
{
//Debug.Log("点击左trigger");
if(gameObject.activeSelf)
CmdShoot();
}
@@ -78,6 +77,7 @@ public class Pistol : Launcher
[Client]
public void ClickRrightTrigger()
{
MRInput.Ins.VibrateRightController(0.4F, 50, 300);
CmdShoot();
}

View File

@@ -95,6 +95,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

View File

@@ -109,6 +109,8 @@ public class Player : NetworkRoomPlayer,IDamagable
IsAlive = true;
}
public void SetBlood(float num)
{
currentHp += num;
@@ -219,13 +221,9 @@ public class Player : NetworkRoomPlayer,IDamagable
other.gameObject.SetActive(false);
NetworkServer.Destroy(other.gameObject);
GameManager.Ins.GameStart();
}
if (other.tag == "WeaponProp")
{
Debug.Log("触碰武器道具");
WeaponProp prop = other.transform.GetComponent<WeaponProp>();
//prop.Collider();
@@ -239,12 +237,18 @@ public class Player : NetworkRoomPlayer,IDamagable
ItemProp prop = other.transform.GetComponent<ItemProp>();
if (prop.itemPropType == ItemPropType.Hp)
{
SetBlood(prop.addHpIndex);
prop.Collider();
GetProp(prop);
}
}
}
[TargetRpc]
public void GetProp(ItemProp prop)
{
SetBlood(prop.addHpIndex);
prop.Collider();
}
#region
/// <summary>

View File

@@ -43,11 +43,11 @@ public class WeaponProp : NetworkBehaviour
break;
case GunType.LightSphereGun:
weapons[2].SetActive(true);
amount = 200;
amount = 100;
break;
case GunType.BeamGun:
weapons[3].SetActive(true);
amount = 200;
amount = 100;
break;
case GunType.GrenadeGun:
weapons[4].SetActive(true);

View File

@@ -145,12 +145,10 @@ public class HUDPanel : MonoBehaviour
{
gunImage.sprite = gunIcons[GameLocal.Ins.self.NowGunIndex];
gunCountTxt.text = bulletIndex.ToString();
Debug.LogError("枪械:"+bulletIndex);
}
public void UserGun(int bullet)
{
Debug.LogError("子弹数量:"+bullet);
gunCountTxt.text = bullet.ToString();
}