UnityCommon/Role/Bullet.cs

111 lines
3.6 KiB
C#
Raw Normal View History

2024-12-05 16:25:46 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;
public enum BulletType
{
Bullet,
2024-12-12 17:06:08 +08:00
Lightning,
Spraying //ԭ<><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-05 16:25:46 +08:00
}
public enum BulletMoveType
{/// <summary>
/// <20>ӵ<EFBFBD><D3B5>ƶ<EFBFBD><C6B6><EFBFBD>ʽ:<3A><><EFBFBD>Ե<EFBFBD>,
/// </summary>
PeerToPeer,
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
/// </summary>
2024-12-12 17:06:08 +08:00
PointToDirection,
Scope
2024-12-05 16:25:46 +08:00
}
2024-12-11 16:51:55 +08:00
2024-12-05 16:25:46 +08:00
public class BulletData
{
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD>͸<EFBFBD><CDB8><EFBFBD><EFBFBD>")] public int NumberOfBulletPenetrations = 1;
/// <summary>
/// <20>ӵ<EFBFBD>ɢ<EFBFBD><C9A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
[Header("<22>ӵ<EFBFBD>ɢ<EFBFBD><C9A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public int BulletScattering = 1;
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public int BulletBurstTimes = 1;
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public float BulletBurstInterval ;
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD>͸˥<CDB8><CBA5>")] public float BulletPenetrationAttenuation = 0.2f;
2024-12-11 16:51:55 +08:00
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>")] public float BulletSpeed = 5f;
2024-12-05 16:25:46 +08:00
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ")] public float BulletAttackCooldown = 1f;
2024-12-11 16:51:55 +08:00
[Header("<22>ӵ<EFBFBD><D3B5>˺<EFBFBD>")] public float attack = 10;
2024-12-05 16:25:46 +08:00
public BulletData()
{
}
public BulletData(int numberOfBulletPenetrations, int bulletScattering, int bulletBurstTimes, float bulletBurstInterval, float bulletPenetrationAttenuation, float bulletSpeed, float bulletAttackCooldown)
{
NumberOfBulletPenetrations = numberOfBulletPenetrations;
BulletScattering = bulletScattering;
BulletBurstTimes = bulletBurstTimes;
BulletBurstInterval = bulletBurstInterval;
BulletPenetrationAttenuation = bulletPenetrationAttenuation;
BulletSpeed = bulletSpeed;
BulletAttackCooldown = bulletAttackCooldown;
}
public override string ToString()
{
return
$"{nameof(NumberOfBulletPenetrations)}: {NumberOfBulletPenetrations}, {nameof(BulletScattering)}: {BulletScattering}, {nameof(BulletBurstTimes)}: {BulletBurstTimes}, {nameof(BulletBurstInterval)}: {BulletBurstInterval}, {nameof(BulletPenetrationAttenuation)}: {BulletPenetrationAttenuation}, {nameof(BulletSpeed)}: {BulletSpeed}, {nameof(BulletAttackCooldown)}: {BulletAttackCooldown}";
}
}
public class Bullet : MonoBehaviour
{
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>")] public Role role;
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>Χ<E4B7B6><CEA7><EFBFBD><EFBFBD>")] public Attack attackObj;
2024-12-12 17:06:08 +08:00
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>")] public BulletType myBulletType;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public BulletMoveType bulletMoveType;
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>")] public BulletData bulletData = new BulletData();
[Header("<22><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><><C4AC><EFBFBD><EFBFBD>10f")] public float BulletDeadTimer=10f;
2024-12-11 16:51:55 +08:00
private float timer = 0;
2024-12-05 16:25:46 +08:00
private void Update()
{
switch (this.bulletMoveType)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ƶ<EFBFBD>
case BulletMoveType.PeerToPeer:
2024-12-11 16:51:55 +08:00
this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed);
2024-12-12 17:06:08 +08:00
timer += Time.deltaTime;
if (timer > BulletDeadTimer)
{
Destroy(this.gameObject);
}
2024-12-05 16:25:46 +08:00
break;
case BulletMoveType.PointToDirection:
break;
2024-12-12 17:06:08 +08:00
case BulletMoveType.Scope:
break;
2024-12-05 16:25:46 +08:00
}
2024-12-11 16:51:55 +08:00
2024-12-12 17:06:08 +08:00
2024-12-11 16:51:55 +08:00
2024-12-05 16:25:46 +08:00
}
2024-12-11 16:51:55 +08:00
2024-12-05 16:25:46 +08:00
private void OnTriggerEnter2D(Collider2D collision)
{
2024-12-11 16:51:55 +08:00
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ");
2024-12-05 16:25:46 +08:00
Role Crole = collision.gameObject.GetComponent<Role>();
if(Crole)
{
if(Crole.camp!= role.camp)
{
2024-12-11 16:51:55 +08:00
Debug.Log("<22><><EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
2024-12-05 16:25:46 +08:00
Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role });
2024-12-11 16:51:55 +08:00
Destroy(this.gameObject);
2024-12-05 16:25:46 +08:00
}
}
}
}