|
|
@@ -7,21 +7,22 @@ public class BulletManager : MonoBehaviour
|
|
|
{
|
|
|
public Image[] bulletImages;
|
|
|
public Sprite bulletSprite;
|
|
|
+ public Sprite bulletHalfSprite;
|
|
|
public Sprite emptyBulletSprite;
|
|
|
- //Ĭ���ӵ�����
|
|
|
+ //默认子弹数量
|
|
|
public int defaultBulletCount = 15;
|
|
|
private int bulletCount;
|
|
|
|
|
|
public GameObject parent ;
|
|
|
|
|
|
[SerializeField]
|
|
|
- [Tooltip("�����ӵ�������ʾ��λ���Ƿ�����������")]
|
|
|
+ [Tooltip("生成子弹不足提示的位置是否在是正中心")]
|
|
|
bool bCenter = false;
|
|
|
|
|
|
[SerializeField]
|
|
|
- [Tooltip("�����ӵ�������ʾ��������ɫ")]
|
|
|
+ [Tooltip("生成子弹不足提示的字体颜色")]
|
|
|
Color bulletTipColor;
|
|
|
- //�����
|
|
|
+ //射击数
|
|
|
private int numberOfShotsFired = 0;
|
|
|
public int getBulletCount {
|
|
|
get {
|
|
|
@@ -30,6 +31,12 @@ public class BulletManager : MonoBehaviour
|
|
|
}
|
|
|
void Awake()
|
|
|
{
|
|
|
+ if (BluetoothAim.ins && BluetoothAim.ins.isMainConnectToGunType().isGun && BluetoothAim.ins.isMainConnectToGunType().gunType == AimDeviceType.RifleM416)
|
|
|
+ {
|
|
|
+ //m416 连接蓝牙的情况下,设置默认子弹数量
|
|
|
+ defaultBulletCount = 30;
|
|
|
+ }
|
|
|
+
|
|
|
numberOfShotsFired = 0;
|
|
|
ResetBullets();
|
|
|
}
|
|
|
@@ -49,7 +56,7 @@ public class BulletManager : MonoBehaviour
|
|
|
{
|
|
|
bulletCount--;
|
|
|
UpdateBullets();
|
|
|
- //��¼���������
|
|
|
+ //记录射击的总数
|
|
|
numberOfShotsFired++;
|
|
|
}
|
|
|
}
|
|
|
@@ -60,7 +67,7 @@ public class BulletManager : MonoBehaviour
|
|
|
UpdateBullets();
|
|
|
}
|
|
|
|
|
|
- //�Ƿ��ж������ʹ��
|
|
|
+ //是否判断射击完使用
|
|
|
public bool NumberOfShotsFired() {
|
|
|
return numberOfShotsFired >= defaultBulletCount ? true : false;
|
|
|
}
|
|
|
@@ -70,34 +77,33 @@ public class BulletManager : MonoBehaviour
|
|
|
|
|
|
if (SceneManager.GetActiveScene().name == "InfraredGameDouble")
|
|
|
{
|
|
|
- //���ҷ�����ʾ
|
|
|
Create(parent.transform, bCenter, bulletTipColor, false, playerType == PlayerType.FirstPlayer? - Screen.width / 4f : Screen.width / 4f);
|
|
|
}
|
|
|
else {
|
|
|
Create(parent.transform, bCenter, bulletTipColor);
|
|
|
}
|
|
|
-
|
|
|
- //��ʱ�Զ�ˢ��,����Э�����Ч��
|
|
|
+
|
|
|
+ //暂时自动刷新,接入协议后修改效果
|
|
|
//ResetBullets();
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// ����Ҫ�Զ�ɾ��
|
|
|
+ /// 不需要自动删除
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public bool bulletZeroNotDelete() {
|
|
|
if (getBulletCount == 0)
|
|
|
{
|
|
|
- //�����Զ�ɾ��
|
|
|
+ //禁用自动删除
|
|
|
Create(parent.transform, bCenter, bulletTipColor,true);
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// �ⲿ���ã��ֶ�ɾ������ TipBulletNumber
|
|
|
+ /// 外部调用:手动删除所有 TipBulletNumber
|
|
|
/// </summary>
|
|
|
public static void RemoveBulletExternally()
|
|
|
{
|
|
|
@@ -113,15 +119,40 @@ public class BulletManager : MonoBehaviour
|
|
|
|
|
|
private void UpdateBullets()
|
|
|
{
|
|
|
- for (int i = 0; i < bulletImages.Length; i++)
|
|
|
+ if (defaultBulletCount == 30)
|
|
|
{
|
|
|
- if (i < bulletCount)
|
|
|
+ int fullUnits = bulletCount / 2;
|
|
|
+ bool hasHalf = bulletCount % 2 == 1;
|
|
|
+
|
|
|
+ for (int i = 0; i < bulletImages.Length; i++)
|
|
|
{
|
|
|
- bulletImages[i].sprite = bulletSprite;
|
|
|
+ if (i < fullUnits)
|
|
|
+ {
|
|
|
+ bulletImages[i].sprite = bulletSprite;
|
|
|
+ }
|
|
|
+ else if (i == fullUnits && hasHalf)
|
|
|
+ {
|
|
|
+ bulletImages[i].sprite = bulletHalfSprite;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bulletImages[i].sprite = emptyBulletSprite;
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 原逻辑:每发子弹一格
|
|
|
+ for (int i = 0; i < bulletImages.Length; i++)
|
|
|
{
|
|
|
- bulletImages[i].sprite = emptyBulletSprite;
|
|
|
+ if (i < bulletCount)
|
|
|
+ {
|
|
|
+ bulletImages[i].sprite = bulletSprite;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bulletImages[i].sprite = emptyBulletSprite;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -130,7 +161,7 @@ public class BulletManager : MonoBehaviour
|
|
|
static List<TipBulletNumber> bulletNumber = new();
|
|
|
public static void Create(Transform parentTran,bool centerPos,Color color, bool disableAutoDelete = false ,float posX = 0)
|
|
|
{
|
|
|
- //��ն���
|
|
|
+ //清空对象
|
|
|
//for (int i = bulletNumber.Count - 1; i >= 0; i--)
|
|
|
//{
|
|
|
// Destroy(bulletNumber[i].gameObject);
|
|
|
@@ -139,17 +170,17 @@ public class BulletManager : MonoBehaviour
|
|
|
RemoveBulletExternally();
|
|
|
|
|
|
GameObject o = Instantiate(Resources.Load<GameObject>("Common/TipBulletNumber"));
|
|
|
- // ����Transform����
|
|
|
+ // 重置Transform属性
|
|
|
o.transform.SetParent(parentTran);
|
|
|
TipBulletNumber tip = o.GetComponent<TipBulletNumber>();
|
|
|
tip.SetOutTipColor(color);
|
|
|
- tip.SetDisableAutoDelete(disableAutoDelete); // �����Ƿ�����Զ�ɾ��
|
|
|
+ tip.SetDisableAutoDelete(disableAutoDelete); // 设置是否禁用自动删除
|
|
|
bulletNumber.Add(tip);
|
|
|
|
|
|
- // ��ȡRectTransform���
|
|
|
+ // 获取RectTransform组件
|
|
|
RectTransform rectTransform = o.GetComponent<RectTransform>();
|
|
|
|
|
|
- // ���������ê���ƫ��λ��
|
|
|
+ // 设置相对于锚点的偏移位置
|
|
|
if (centerPos)
|
|
|
{
|
|
|
rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
|