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)
|
|
|
|
|
{
|
2024-12-12 23:03:57 +08:00
|
|
|
|
attackObj.bulltes.Remove(this.gameObject);
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + attackObj.bulltes.Count);
|
2024-12-12 17:06:08 +08:00
|
|
|
|
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-18 20:43:54 +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-12 23:03:57 +08:00
|
|
|
|
Debug.Log(this.role.gameObject.name+"<22><><EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
2024-12-18 20:43:54 +08:00
|
|
|
|
int direction=0;
|
2024-12-18 21:07:57 +08:00
|
|
|
|
if (collision.transform.position.x>transform.position.x)//<2F>ӵ<EFBFBD><D3B5><EFBFBD><F2B5BDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ұ<EFBFBD>
|
2024-12-18 20:43:54 +08:00
|
|
|
|
{
|
|
|
|
|
direction = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role },direction);
|
2024-12-12 23:03:57 +08:00
|
|
|
|
attackObj.bulltes.Remove(this.gameObject);
|
|
|
|
|
|
|
|
|
|
if (myBulletType!=BulletType.Spraying)
|
|
|
|
|
{
|
|
|
|
|
attackObj.bulltes.Remove(this.gameObject);
|
2024-12-14 23:20:36 +08:00
|
|
|
|
//Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + attackObj.bulltes.Count);
|
2024-12-12 23:03:57 +08:00
|
|
|
|
Destroy(this.gameObject);
|
2024-12-18 20:43:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private float lastDamageTime = 0f;
|
|
|
|
|
private void OnTriggerStay2D(Collider2D collision)
|
|
|
|
|
{
|
|
|
|
|
Role Crole = collision.gameObject.GetComponent<Role>();
|
|
|
|
|
if (Crole)
|
|
|
|
|
{
|
|
|
|
|
if (Crole.camp != role.camp)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int direction = 0;
|
|
|
|
|
if (collision.transform.position.x >= transform.position.x)//<2F>ӵ<EFBFBD><D3B5><EFBFBD><F2B5BDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ұ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
direction = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (myBulletType == BulletType.Spraying)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (Time.time - lastDamageTime > 1f) // ÿ<><C3BF><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ѫ
|
|
|
|
|
{
|
|
|
|
|
Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role });
|
|
|
|
|
lastDamageTime = Time.time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-12-05 16:25:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-18 20:43:54 +08:00
|
|
|
|
}
|
2024-12-05 16:25:46 +08:00
|
|
|
|
}
|
2024-12-12 23:03:57 +08:00
|
|
|
|
|
2024-12-18 20:43:54 +08:00
|
|
|
|
|
2024-12-12 23:03:57 +08:00
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
|
|
|
{
|
2024-12-14 23:20:36 +08:00
|
|
|
|
//Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⷶΧ");
|
2024-12-12 23:03:57 +08:00
|
|
|
|
Role Crole = collision.gameObject.GetComponent<Role>();
|
|
|
|
|
if (Crole)
|
|
|
|
|
{
|
|
|
|
|
if (Crole.camp != role.camp)
|
|
|
|
|
{
|
2024-12-17 17:15:32 +08:00
|
|
|
|
|
2024-12-14 23:20:36 +08:00
|
|
|
|
//Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + attackObj.bulltes.Count);
|
2024-12-17 17:15:32 +08:00
|
|
|
|
if (myBulletType != BulletType.Spraying)
|
|
|
|
|
{
|
|
|
|
|
attackObj.bulltes.Remove(this.gameObject);
|
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 23:03:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-05 16:25:46 +08:00
|
|
|
|
}
|