UnityCommon/Role/Bullet.cs

97 lines
3.2 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,
Lightning
}
public enum BulletMoveType
{/// <summary>
/// <20>ӵ<EFBFBD><D3B5>ƶ<EFBFBD><C6B6><EFBFBD>ʽ:<3A><><EFBFBD>Ե<EFBFBD>,
/// </summary>
PeerToPeer,
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
/// </summary>
PointToDirection
}
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;
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>")] public float BulletSpeed = 10f;
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ")] public float BulletAttackCooldown = 1f;
[Header("<22>ӵ<EFBFBD><D3B5>˺<EFBFBD>")] public float attack = 0;
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;
[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;
private void Update()
{
switch (this.bulletMoveType)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ƶ<EFBFBD>
case BulletMoveType.PeerToPeer:
this.gameObject.transform.Translate(Vector3.up);
break;
case BulletMoveType.PointToDirection:
break;
}
}
private async void Start()
{
await Task.Delay(1000);
Destroy(gameObject);
}
private void OnTriggerEnter2D(Collider2D collision)
{
Role Crole = collision.gameObject.GetComponent<Role>();
if(Crole)
{
if(Crole.camp!= role.camp)
{
Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role });
}
}
}
}