(client) feat:实现子弹定义 chore:将建筑碰撞体改为方形

This commit is contained in:
m0_75251201
2025-08-14 13:26:02 +08:00
parent 35924f3695
commit 12a4f9efaa
10 changed files with 287 additions and 10 deletions

View File

@ -10,6 +10,10 @@ namespace Entity
{
}
public override void TryMove()
{
}
protected override void UpdatePlayerControls()
{
if (Input.GetKeyDown(KeyCode.W))

View File

@ -0,0 +1,20 @@
using UnityEngine;
namespace Entity
{
public class BuildingOutline:Outline
{
public BoxCollider2D boxCollider;
override public void Init()
{
var size = GetSize();
outlineRenderer.size = size;
boxCollider.size = size;
if (progressBarPrefab)
{
progressBarPrefab.transform.localPosition += new Vector3(0f, size.y * 2 / 3, 0f);
progressBarPrefab.transform.localScale = new Vector3(size.x, 1f / 10f, 1);
}
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ba93dffd1aec4bd5b1ef57df2597ba56

View File

@ -0,0 +1,18 @@
using System;
using UnityEngine;
namespace Entity
{
public class Bullet:Entity
{
protected override void AutoBehave()
{
TryMove();
}
private void OnTriggerEnter2D(Collider2D other)
{
other.GetComponent<Entity>()?.OnHit(this);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3ccb9e42ac9e4492bff031709d2d2e92
timeCreated: 1755146614

View File

@ -98,7 +98,10 @@ namespace Entity
/// 表示实体是否已经死亡(生命值小于等于零)。
/// </summary>
public bool IsDead => attributes.health <= 0;
public bool IsShowingOfHitBarUI=>hitBarUIShowTimer > 0;
public bool IsAttacking => attackCoroutine != null;
private bool _isPlayerControlled = false;
private bool _warning = false;
@ -136,8 +139,7 @@ namespace Entity
public float hitBarUIShowTime = 5;
private float hitBarUIShowTimer = 0;
public bool isShowingOfHitBarUI=>hitBarUIShowTimer > 0;
/// <summary>
/// 初始化实体的基本属性和行为树。
@ -261,7 +263,7 @@ namespace Entity
}
}
if (isShowingOfHitBarUI)
if (IsShowingOfHitBarUI)
{
hitBarUIShowTimer -= Time.deltaTime;
if (hitBarUIShowTimer <= 0)
@ -276,7 +278,7 @@ namespace Entity
/// </summary>
public virtual void TryAttack()
{
if(attackCoroutine == null)
if(!IsAttacking)
attackCoroutine = StartCoroutine(AttackFlow());
}
@ -296,6 +298,8 @@ namespace Entity
/// </summary>
public virtual void TryMove()
{
if (IsAttacking)
return;
transform.position += direction * (attributes.moveSpeed * Time.deltaTime * (IsChase ? 1 : 0.5f));
}
@ -315,6 +319,8 @@ namespace Entity
public void ShowHealthBar()
{
if(!healthBarPrefab)
return;
healthBarPrefab.gameObject.SetActive(true);
healthBarPrefab.Progress = (float)attributes.health / entityDef.attributes.health;
hitBarUIShowTimer=hitBarUIShowTime;
@ -322,6 +328,8 @@ namespace Entity
public void HideHealthBar()
{
if(!healthBarPrefab)
return;
healthBarPrefab.gameObject.SetActive(false);
}
@ -358,7 +366,7 @@ namespace Entity
/// <summary>
/// 自动行为逻辑,根据行为树执行任务。
/// </summary>
private void AutoBehave()
protected virtual void AutoBehave()
{
if (aiTree == null)
return;

View File

@ -18,15 +18,17 @@ namespace Entity
public static Vector3 minimum=new(0.5f,0.5f,0.5f);
public void Init()
public virtual void Init()
{
var size = GetSize();
outlineRenderer.size = size;
outlineCollider.direction = size.x > size.y ? CapsuleDirection2D.Horizontal : CapsuleDirection2D.Vertical;
outlineCollider.size = size;
progressBarPrefab.transform.localPosition += new Vector3(0f,size.y * 2 / 3,0f);
progressBarPrefab.transform.localScale = new Vector3(size.x, size.x / 10, 1);
if (progressBarPrefab)
{
progressBarPrefab.transform.localPosition += new Vector3(0f, size.y * 2 / 3, 0f);
progressBarPrefab.transform.localScale = new Vector3(size.x, 1f / 10f, 1);
}
}
public void Show()