diff --git a/Client/Assets/Prefab/BuildingPrefab Variant.prefab b/Client/Assets/Prefab/BuildingPrefab Variant.prefab index 5ee7d29..0a94705 100644 --- a/Client/Assets/Prefab/BuildingPrefab Variant.prefab +++ b/Client/Assets/Prefab/BuildingPrefab Variant.prefab @@ -8,6 +8,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 564740215097623485, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} propertyPath: m_LocalPosition.x value: -9.026831 @@ -56,24 +60,56 @@ PrefabInstance: propertyPath: entity value: objectReference: {fileID: 2985213147343140216} + - target: {fileID: 1550000129210799929, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: outlineCollider + value: + objectReference: {fileID: 0} - target: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} propertyPath: entity value: objectReference: {fileID: 2985213147343140216} + - target: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: outline + value: + objectReference: {fileID: 6487788869574860317} m_RemovedComponents: - {fileID: 7300440714681954677, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + - {fileID: 1724818962207668775, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + - {fileID: 1550000129210799929, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} insertIndex: 2 addedObject: {fileID: 2985213147343140216} + - targetCorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + insertIndex: 3 + addedObject: {fileID: 6487788869574860317} + - targetCorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + insertIndex: 4 + addedObject: {fileID: 6245381882962021176} m_SourcePrefab: {fileID: 100100000, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} +--- !u!114 &1196523683669800718 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 8307348883874536545, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + m_PrefabInstance: {fileID: 7193170239846001519} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 605f185650fe46d89a6e0d60fb8fb11c, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &4949477718940635697 stripped GameObject: m_CorrespondingSourceObject: {fileID: 2838206730318674270, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} m_PrefabInstance: {fileID: 7193170239846001519} m_PrefabAsset: {fileID: 0} +--- !u!212 &6103973223718413091 stripped +SpriteRenderer: + m_CorrespondingSourceObject: {fileID: 3992139212329961548, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + m_PrefabInstance: {fileID: 7193170239846001519} + m_PrefabAsset: {fileID: 0} --- !u!1 &8035315966857772658 stripped GameObject: m_CorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} @@ -93,7 +129,73 @@ MonoBehaviour: m_EditorClassIdentifier: animatorPrefab: {fileID: 2113064398104960506, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3} imagePrefab: {fileID: 1922746734790246249, guid: a6657f26d735fab4690c8185980fda29, type: 3} + healthBarPrefab: {fileID: 1196523683669800718} direction: {x: 0, y: 0, z: 0} body: {fileID: 4949477718940635697} affiliation: canSelect: 1 + hitBarUIShowTime: 5 +--- !u!114 &6487788869574860317 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8035315966857772658} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ba93dffd1aec4bd5b1ef57df2597ba56, type: 3} + m_Name: + m_EditorClassIdentifier: + body: {fileID: 4949477718940635697} + outlineRenderer: {fileID: 6103973223718413091} + outlineCollider: {fileID: 0} + progressBarPrefab: {fileID: 1196523683669800718} + entity: {fileID: 2985213147343140216} + boxCollider: {fileID: 6245381882962021176} +--- !u!61 &6245381882962021176 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8035315966857772658} + m_Enabled: 1 + serializedVersion: 3 + m_Density: 1 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_CompositeOperation: 0 + m_CompositeOrder: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 diff --git a/Client/Assets/Prefab/BulletPrefab Variant.prefab b/Client/Assets/Prefab/BulletPrefab Variant.prefab new file mode 100644 index 0000000..2f66473 --- /dev/null +++ b/Client/Assets/Prefab/BulletPrefab Variant.prefab @@ -0,0 +1,111 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &6246229038671744578 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalPosition.x + value: -1.26556 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalPosition.y + value: -3.36505 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_Name + value: BulletPrefab Variant + objectReference: {fileID: 0} + - target: {fileID: 1550000129210799929, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: entity + value: + objectReference: {fileID: 6784914172229929974} + - target: {fileID: 1550000129210799929, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: progressBarPrefab + value: + objectReference: {fileID: 0} + - target: {fileID: 1724818962207668775, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: m_IsTrigger + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + propertyPath: entity + value: + objectReference: {fileID: 6784914172229929974} + m_RemovedComponents: + - {fileID: 7300440714681954677, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + - {fileID: 4717642781780051128, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + m_RemovedGameObjects: + - {fileID: 1328271255896522146, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + m_AddedGameObjects: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + insertIndex: 2 + addedObject: {fileID: 6784914172229929974} + m_SourcePrefab: {fileID: 100100000, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} +--- !u!1 &6557095110834133855 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + m_PrefabInstance: {fileID: 6246229038671744578} + m_PrefabAsset: {fileID: 0} +--- !u!114 &6784914172229929974 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6557095110834133855} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3ccb9e42ac9e4492bff031709d2d2e92, type: 3} + m_Name: + m_EditorClassIdentifier: + animatorPrefab: {fileID: 2113064398104960506, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3} + imagePrefab: {fileID: 1922746734790246249, guid: a6657f26d735fab4690c8185980fda29, type: 3} + healthBarPrefab: {fileID: 0} + direction: {x: 0, y: 0, z: 0} + body: {fileID: 8200005766896563996} + affiliation: + canSelect: 1 + hitBarUIShowTime: 5 +--- !u!1 &8200005766896563996 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2838206730318674270, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} + m_PrefabInstance: {fileID: 6246229038671744578} + m_PrefabAsset: {fileID: 0} diff --git a/Client/Assets/Prefab/BulletPrefab Variant.prefab.meta b/Client/Assets/Prefab/BulletPrefab Variant.prefab.meta new file mode 100644 index 0000000..83f87eb --- /dev/null +++ b/Client/Assets/Prefab/BulletPrefab Variant.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 29b2450a8636a104586e36333878f4d9 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Client/Assets/Scripts/Entity/Building.cs b/Client/Assets/Scripts/Entity/Building.cs index fd4dcd2..b7499ef 100644 --- a/Client/Assets/Scripts/Entity/Building.cs +++ b/Client/Assets/Scripts/Entity/Building.cs @@ -10,6 +10,10 @@ namespace Entity { } + public override void TryMove() + { + } + protected override void UpdatePlayerControls() { if (Input.GetKeyDown(KeyCode.W)) diff --git a/Client/Assets/Scripts/Entity/BuildingOutline.cs b/Client/Assets/Scripts/Entity/BuildingOutline.cs new file mode 100644 index 0000000..b955a91 --- /dev/null +++ b/Client/Assets/Scripts/Entity/BuildingOutline.cs @@ -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); + } + } + } +} \ No newline at end of file diff --git a/Client/Assets/Scripts/Entity/BuildingOutline.cs.meta b/Client/Assets/Scripts/Entity/BuildingOutline.cs.meta new file mode 100644 index 0000000..7af97de --- /dev/null +++ b/Client/Assets/Scripts/Entity/BuildingOutline.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ba93dffd1aec4bd5b1ef57df2597ba56 \ No newline at end of file diff --git a/Client/Assets/Scripts/Entity/Bullet.cs b/Client/Assets/Scripts/Entity/Bullet.cs new file mode 100644 index 0000000..d88517a --- /dev/null +++ b/Client/Assets/Scripts/Entity/Bullet.cs @@ -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()?.OnHit(this); + } + } +} \ No newline at end of file diff --git a/Client/Assets/Scripts/Entity/Bullet.cs.meta b/Client/Assets/Scripts/Entity/Bullet.cs.meta new file mode 100644 index 0000000..225afd6 --- /dev/null +++ b/Client/Assets/Scripts/Entity/Bullet.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3ccb9e42ac9e4492bff031709d2d2e92 +timeCreated: 1755146614 \ No newline at end of file diff --git a/Client/Assets/Scripts/Entity/Entity.cs b/Client/Assets/Scripts/Entity/Entity.cs index fd27364..2e0f55d 100644 --- a/Client/Assets/Scripts/Entity/Entity.cs +++ b/Client/Assets/Scripts/Entity/Entity.cs @@ -98,7 +98,10 @@ namespace Entity /// 表示实体是否已经死亡(生命值小于等于零)。 /// 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; - + /// /// 初始化实体的基本属性和行为树。 @@ -261,7 +263,7 @@ namespace Entity } } - if (isShowingOfHitBarUI) + if (IsShowingOfHitBarUI) { hitBarUIShowTimer -= Time.deltaTime; if (hitBarUIShowTimer <= 0) @@ -276,7 +278,7 @@ namespace Entity /// public virtual void TryAttack() { - if(attackCoroutine == null) + if(!IsAttacking) attackCoroutine = StartCoroutine(AttackFlow()); } @@ -296,6 +298,8 @@ namespace Entity /// 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 /// /// 自动行为逻辑,根据行为树执行任务。 /// - private void AutoBehave() + protected virtual void AutoBehave() { if (aiTree == null) return; diff --git a/Client/Assets/Scripts/Entity/Outline.cs b/Client/Assets/Scripts/Entity/Outline.cs index b0ae66e..c9a8dda 100644 --- a/Client/Assets/Scripts/Entity/Outline.cs +++ b/Client/Assets/Scripts/Entity/Outline.cs @@ -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()