fix:调整音效,武器添加武器UI,添加武器装弹功能

This commit is contained in:
bzx
2025-11-08 18:32:31 +08:00
parent 5bba6beffc
commit fdeaac6867
117 changed files with 162430 additions and 4242 deletions

View File

@@ -75,12 +75,26 @@ public class Launcher : NetworkBehaviour
[SyncVar]
public float nextShootTime = 0f;
private float _shootInterval = 0f;
/// <summary>
/// 上子弹时间
/// </summary>
[NonSerialized] [SyncVar]
public float waitBulletTime;
/// <summary>
/// 持续时间
/// </summary>
public float userTime;
private float _curWaitBulletTime = 0f;
private bool _isWaiBulletting = false;
//private float _shootInterval = 0f;
public void Awake()
{
_shootInterval = 1f / shootRate;
bullet_amount = -999;
bullet_amount = 0;
}
[Server]
@@ -98,12 +112,7 @@ public class Launcher : NetworkBehaviour
[Server]
public virtual bool Shoot(Vector3 target, int ownerIndex)
{
// 弹量不够
if (bullet_amount <= 0 && bullet_amount != -999)
{
return false;
}
// 未冷却
if (nextShootTime > Time.time)
{
@@ -114,6 +123,24 @@ public class Launcher : NetworkBehaviour
{
bullet_amount--;
}
// 弹量不够
if (bullet_amount <= 0&&!_isWaiBulletting&& waitBulletTime>0)
{
_isWaiBulletting = true;
PlayWaitBullet();
return false;
}
if (_isWaiBulletting)
{
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
{
_isWaiBulletting = false;
StopBullet();
SetBulletAmount(GameManager.Ins.GunInfos[type][1].BulletAmount);
},waitBulletTime);
return false;
}
if (bullet_amount <= 0 && bullet_amount != -999)
{
@@ -127,7 +154,7 @@ public class Launcher : NetworkBehaviour
SpawnShell();
SpawnMuzzle();
nextShootTime = Time.time + _shootInterval;
nextShootTime = Time.time + shootRate;
return true;
}
@@ -157,9 +184,20 @@ public class Launcher : NetworkBehaviour
{
return;
}
bullet_amount += amount;
bullet_amount = amount;
GunInfo info = GameManager.Ins.GunInfos[type][1];
userTime = info.Time;
}
public void SetBulletAmount(int amount)
{
bullet_amount = amount;
}
public virtual void PlayWaitBullet(){}
public virtual void StopBullet(){}
[Server]
protected void SpawnMuzzle()
{

View File

@@ -1,19 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using DarkTonic.MasterAudio;
using Mirror;
using UnityEngine;
public class Pistol : Launcher
{
void Start()
[SoundGroup]
public string coolDownSound;//充能音效
public GameObject coolDownPre;//充能特效
private void Start()
{
// 主机自身
if (isServer && isClient && isOwned)
{
type = GunType.Pistol;
GunInfo gunInfo = GameManager.Ins.GunInfos[type][1];
shootRate = gunInfo.ShootRate;
recoil = gunInfo.Recoil;
userTime = gunInfo.Time;
waitBulletTime = gunInfo.CoolDown;
if (hand == HandType.Left)
{
MRInput.Ins.RegisterHoldPressLeftTrigger(ClickLeftTrigger);
@@ -30,6 +37,9 @@ public class Pistol : Launcher
GunInfo gunInfo = GameManager.Ins.GunInfos[type][1];
shootRate = gunInfo.ShootRate;
recoil = gunInfo.Recoil;
userTime = gunInfo.Time;
//bullet_amount=gunInfo.BulletAmount;
waitBulletTime = gunInfo.CoolDown;
}
// 从机自身
else if (isClient && isOwned)
@@ -43,6 +53,7 @@ public class Pistol : Launcher
MRInput.Ins.RegisterHoldPressRightTrigger(ClickRrightTrigger);
}
}
coolDownPre.SetActive(false);
}
public void Update()
@@ -85,4 +96,17 @@ public class Pistol : Launcher
{
Shoot();
}
public override void PlayWaitBullet()
{
base.PlayWaitBullet();
MasterAudio.PlaySound(coolDownSound);
coolDownPre.SetActive(true);
}
public override void StopBullet()
{
base.StopBullet();
coolDownPre.SetActive(false);
}
}

View File

@@ -15,9 +15,17 @@ public class StartGameItem : NetworkBehaviour,IDamagable
[NonSerialized]
public int HpIndex;
public float Health { get; set; }
private void Start()
{
HpIndex = 10;
originalPos=transform.position;
}
public void ApplyDamage(float value, object info, Transform _sender)
{
HpIndex--;
Debug.Log(HpIndex);
DamageNumber prefab = MRDamage.Ins.GetCurrent();
DamageNumber newDamageNumber = prefab.Spawn(transform.position+new Vector3(0,2,0), value);
if (HpIndex <= 0)
@@ -62,5 +70,4 @@ public class StartGameItem : NetworkBehaviour,IDamagable
isShaking = false;
});
}
}

View File

@@ -50,6 +50,9 @@ public class Player : NetworkRoomPlayer,IDamagable
[SyncVar]
public TeamType teamType;
[NonSerialized]
[SyncVar] public bool IsUserAirdropItem;
#if UNITY_EDITOR
[DisplayOnly]
#endif
@@ -65,7 +68,7 @@ public class Player : NetworkRoomPlayer,IDamagable
/// <summary>
/// 手上的枪械
/// </summary>
private List<Launcher[]> Guns = new List<Launcher[]>();
private List<Launcher> Guns = new List<Launcher>();
/// <summary>
/// 现在手上的武器
@@ -75,7 +78,7 @@ public class Player : NetworkRoomPlayer,IDamagable
/// <summary>
/// 左手上的枪
/// </summary>
private Transform leftGun;
// private Transform leftGun;
/// <summary>
/// 右手上的枪
@@ -99,7 +102,8 @@ public class Player : NetworkRoomPlayer,IDamagable
GameManager.Ins.AddData(index);
Collider.enabled = true;
}
GivePistol();
IsUserAirdropItem = false;
}
public void Update()
@@ -147,6 +151,16 @@ public class Player : NetworkRoomPlayer,IDamagable
AimVec = Aim.position;
}
}
if (IsUserAirdropItem && Guns[NowGunIndex].userTime > 0)
{
Guns[NowGunIndex].userTime-=Time.deltaTime;
if (Guns[NowGunIndex].userTime < 0)
{
IsUserAirdropItem = false;
DelWeapon();
}
}
}
@@ -180,7 +194,7 @@ public class Player : NetworkRoomPlayer,IDamagable
if(NowHandState!= HandState.Empty)
return;
Debug.Log("创建武器中...");
PickUpGun(GunType.Pistol, -999);
PickUpGun(GunType.Pistol, GameManager.Ins.GunInfos[GunType.Pistol][1].BulletAmount);
}
[ClientRpc]
@@ -249,17 +263,10 @@ public class Player : NetworkRoomPlayer,IDamagable
Launcher find = null;
for (int i = 0; i < Guns.Count; i++)
{
for (int j = 0; j < Guns[i].Length; j++)
{
Launcher launcher = Guns[i][j];
if (launcher != null && launcher.type == gunType)
{
find = launcher;
break;
}
}
if (find != null)
Launcher launcher = Guns[i];
if (launcher != null && launcher.type == gunType)
{
find = launcher;
break;
}
}
@@ -275,15 +282,9 @@ public class Player : NetworkRoomPlayer,IDamagable
Debug.Log("增加新武器 - " + gunType);
Launcher left = null;
Launcher right = null;
switch (gunType)
{
case GunType.Pistol:
left = LoadGun(HandType.Left, gunType);
right = LoadGun(HandType.Right, gunType);
break;
}
Launcher[] launchers = { left, right };
Guns.Add(launchers);
right = LoadGun(HandType.Right, gunType);
right.SetBulletAmount(amount);
Guns.Add(right);
Swith2TargetGun(gunType);
}
}
@@ -374,17 +375,10 @@ public class Player : NetworkRoomPlayer,IDamagable
int find = -1;
for (int i = 0; i < Guns.Count; i++)
{
for (int j = 0; j < Guns[i].Length; j++)
{
Launcher launcher = Guns[i][j];
if (launcher != null && launcher.type == type)
{
find = i;
break;
}
}
if (find != -1)
Launcher launcher = Guns[i];
if (launcher != null && launcher.type == type)
{
find = i;
break;
}
}
@@ -415,12 +409,12 @@ public class Player : NetworkRoomPlayer,IDamagable
[Server]
public void UpdateWeapons()
{
if (leftGun != null)
{
leftGun.gameObject.SetActive(false);
NetworkServer.UnSpawn(leftGun.gameObject);
leftGun = null;
}
// if (leftGun != null)
// {
// leftGun.gameObject.SetActive(false);
// NetworkServer.UnSpawn(leftGun.gameObject);
// leftGun = null;
// }
if (rightGun != null)
{
@@ -433,19 +427,13 @@ public class Player : NetworkRoomPlayer,IDamagable
{
if (i == NowGunIndex)
{
Launcher l1 = Guns[i][0];
Launcher l2 = Guns[i][1];
Launcher l1 = Guns[i];
if (l1 != null)
{
leftGun = l1.transform;
leftGun.gameObject.SetActive(true);
NetworkServer.Spawn(l1.gameObject, gameObject);
}
if (l2 != null)
{
rightGun = l2.transform;
IsUserAirdropItem = l1.type != GunType.Pistol;
rightGun = l1.transform;
rightGun.gameObject.SetActive(true);
NetworkServer.Spawn(l2.gameObject, gameObject);
NetworkServer.Spawn(l1.gameObject, gameObject);
}
}
}
@@ -460,15 +448,12 @@ public class Player : NetworkRoomPlayer,IDamagable
bool change = false;
for (int i = 0; i < Guns.Count; i++)
{
for (int j = 0; j < Guns[i].Length; j++)
Launcher launcher = Guns[i];
if (launcher != null && launcher.bullet_amount <= 0)
{
Launcher launcher = Guns[i][j];
if (launcher != null && launcher.bullet_amount <= 0 && launcher.bullet_amount != -999)
{
change = true;
Guns[i] = null;
break;
}
change = true;
Guns[i] = null;
break;
}
}
if (change)

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class GunUI : MonoBehaviour
{
public Launcher launcher;
public TMP_Text gunAmount;
private void Update()
{
if(launcher==null)
return;
if (launcher.bullet_amount <= 0)
{
gunAmount.text = "充能中...";
}
if (launcher.userTime > 0)
{
gunAmount.text = launcher.userTime.ToString();
}
if (launcher.bullet_amount > 0)
{
gunAmount.text= launcher.bullet_amount.ToString();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b6e58d2ef9ad2404c97d858acafa8f04
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: