(client) feat:实现血条显示,实现攻击交互,添加碰撞体;fix:修复部分朝向贴图加载失败的问题;chore:规范工作类和行为获取类命名
This commit is contained in:
@ -100,7 +100,8 @@ GameObject:
|
|||||||
- component: {fileID: 7300440714681954677}
|
- component: {fileID: 7300440714681954677}
|
||||||
- component: {fileID: 1550000129210799929}
|
- component: {fileID: 1550000129210799929}
|
||||||
- component: {fileID: 1724818962207668775}
|
- component: {fileID: 1724818962207668775}
|
||||||
m_Layer: 0
|
- component: {fileID: 4717642781780051128}
|
||||||
|
m_Layer: 6
|
||||||
m_Name: EntityPrefab
|
m_Name: EntityPrefab
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
@ -122,6 +123,7 @@ Transform:
|
|||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 5549544358816209289}
|
- {fileID: 5549544358816209289}
|
||||||
- {fileID: 1697214530303839877}
|
- {fileID: 1697214530303839877}
|
||||||
|
- {fileID: 1404278780950315184}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!114 &3332598847335032684
|
--- !u!114 &3332598847335032684
|
||||||
@ -152,10 +154,12 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
animatorPrefab: {fileID: 2113064398104960506, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
animatorPrefab: {fileID: 2113064398104960506, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
imagePrefab: {fileID: 1922746734790246249, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
imagePrefab: {fileID: 1922746734790246249, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
healthBarPrefab: {fileID: 8307348883874536545}
|
||||||
direction: {x: 0, y: 0, z: 0}
|
direction: {x: 0, y: 0, z: 0}
|
||||||
body: {fileID: 2838206730318674270}
|
body: {fileID: 2838206730318674270}
|
||||||
affiliation:
|
affiliation:
|
||||||
canSelect: 1
|
canSelect: 1
|
||||||
|
hitBarUIShowTime: 5
|
||||||
--- !u!114 &1550000129210799929
|
--- !u!114 &1550000129210799929
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -171,6 +175,7 @@ MonoBehaviour:
|
|||||||
body: {fileID: 2838206730318674270}
|
body: {fileID: 2838206730318674270}
|
||||||
outlineRenderer: {fileID: 3992139212329961548}
|
outlineRenderer: {fileID: 3992139212329961548}
|
||||||
outlineCollider: {fileID: 1724818962207668775}
|
outlineCollider: {fileID: 1724818962207668775}
|
||||||
|
progressBarPrefab: {fileID: 8307348883874536545}
|
||||||
entity: {fileID: 7300440714681954677}
|
entity: {fileID: 7300440714681954677}
|
||||||
--- !u!70 &1724818962207668775
|
--- !u!70 &1724818962207668775
|
||||||
CapsuleCollider2D:
|
CapsuleCollider2D:
|
||||||
@ -209,6 +214,33 @@ CapsuleCollider2D:
|
|||||||
m_Offset: {x: 0, y: 0}
|
m_Offset: {x: 0, y: 0}
|
||||||
m_Size: {x: 1, y: 1}
|
m_Size: {x: 1, y: 1}
|
||||||
m_Direction: 0
|
m_Direction: 0
|
||||||
|
--- !u!50 &4717642781780051128
|
||||||
|
Rigidbody2D:
|
||||||
|
serializedVersion: 5
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 887327274103887133}
|
||||||
|
m_BodyType: 0
|
||||||
|
m_Simulated: 1
|
||||||
|
m_UseFullKinematicContacts: 0
|
||||||
|
m_UseAutoMass: 0
|
||||||
|
m_Mass: 1
|
||||||
|
m_LinearDamping: 0
|
||||||
|
m_AngularDamping: 0.05
|
||||||
|
m_GravityScale: 0
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_Interpolate: 0
|
||||||
|
m_SleepingMode: 1
|
||||||
|
m_CollisionDetection: 0
|
||||||
|
m_Constraints: 4
|
||||||
--- !u!1 &2838206730318674270
|
--- !u!1 &2838206730318674270
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -240,3 +272,80 @@ Transform:
|
|||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 697189026367054479}
|
m_Father: {fileID: 697189026367054479}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1001 &3478909419655914534
|
||||||
|
PrefabInstance:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TransformParent: {fileID: 697189026367054479}
|
||||||
|
m_Modifications:
|
||||||
|
- target: {fileID: 2461610838990723460, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_Name
|
||||||
|
value: ProgressBar
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2461610838990723460, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_IsActive
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: -0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: -0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: -0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_RemovedGameObjects: []
|
||||||
|
m_AddedGameObjects: []
|
||||||
|
m_AddedComponents: []
|
||||||
|
m_SourcePrefab: {fileID: 100100000, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
--- !u!4 &1404278780950315184 stripped
|
||||||
|
Transform:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 2538501538304779414, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 3478909419655914534}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!114 &8307348883874536545 stripped
|
||||||
|
MonoBehaviour:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 4831852659840235591, guid: c9e9ee0f8c58b5b45b2e85c7de8251b0, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 3478909419655914534}
|
||||||
|
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:
|
||||||
|
223
Client/Assets/Prefab/ProgressBar.prefab
Normal file
223
Client/Assets/Prefab/ProgressBar.prefab
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &1422760980158139632
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 6758793997642361128}
|
||||||
|
- component: {fileID: 3249131573413190125}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Square
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &6758793997642361128
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1422760980158139632}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0.5, y: 0, z: -0.1}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 6523508484757961969}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!212 &3249131573413190125
|
||||||
|
SpriteRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1422760980158139632}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 0
|
||||||
|
m_ReceiveShadows: 0
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 0
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 9dfc825aed78fcd4ba02077103263b40, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 0
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
|
||||||
|
m_Color: {r: 0.5188679, g: 0.09545213, b: 0.09545213, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
|
m_DrawMode: 0
|
||||||
|
m_Size: {x: 1, y: 1}
|
||||||
|
m_AdaptiveModeThreshold: 0.5
|
||||||
|
m_SpriteTileMode: 0
|
||||||
|
m_WasSpriteAssigned: 1
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_SpriteSortPoint: 0
|
||||||
|
--- !u!1 &2461610838990723460
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 2538501538304779414}
|
||||||
|
- component: {fileID: 9043291113494845527}
|
||||||
|
- component: {fileID: 4831852659840235591}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: ProgressBar
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 0
|
||||||
|
--- !u!4 &2538501538304779414
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2461610838990723460}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 0.1, z: 0.1}
|
||||||
|
m_ConstrainProportionsScale: 1
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 6523508484757961969}
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!212 &9043291113494845527
|
||||||
|
SpriteRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2461610838990723460}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 0
|
||||||
|
m_ReceiveShadows: 0
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 0
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 9dfc825aed78fcd4ba02077103263b40, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 0
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
|
m_DrawMode: 0
|
||||||
|
m_Size: {x: 1, y: 1}
|
||||||
|
m_AdaptiveModeThreshold: 0.5
|
||||||
|
m_SpriteTileMode: 0
|
||||||
|
m_WasSpriteAssigned: 1
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_SpriteSortPoint: 0
|
||||||
|
--- !u!114 &4831852659840235591
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2461610838990723460}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 605f185650fe46d89a6e0d60fb8fb11c, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_progress: {fileID: 2916926755211552789}
|
||||||
|
--- !u!1 &2916926755211552789
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 6523508484757961969}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: GameObject
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &6523508484757961969
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2916926755211552789}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: -0.5, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 6758793997642361128}
|
||||||
|
m_Father: {fileID: 2538501538304779414}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
7
Client/Assets/Prefab/ProgressBar.prefab.meta
Normal file
7
Client/Assets/Prefab/ProgressBar.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c9e9ee0f8c58b5b45b2e85c7de8251b0
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -40,10 +40,10 @@ TextureImporter:
|
|||||||
wrapU: 0
|
wrapU: 0
|
||||||
wrapV: 0
|
wrapV: 0
|
||||||
wrapW: 0
|
wrapW: 0
|
||||||
nPOTScale: 1
|
nPOTScale: 0
|
||||||
lightmap: 0
|
lightmap: 0
|
||||||
compressionQuality: 50
|
compressionQuality: 50
|
||||||
spriteMode: 0
|
spriteMode: 1
|
||||||
spriteExtrude: 1
|
spriteExtrude: 1
|
||||||
spriteMeshType: 1
|
spriteMeshType: 1
|
||||||
alignment: 0
|
alignment: 0
|
||||||
@ -100,7 +100,7 @@ TextureImporter:
|
|||||||
customData:
|
customData:
|
||||||
physicsShape: []
|
physicsShape: []
|
||||||
bones: []
|
bones: []
|
||||||
spriteID:
|
spriteID: 5e97eb03825dee720800000000000000
|
||||||
internalID: 0
|
internalID: 0
|
||||||
vertices: []
|
vertices: []
|
||||||
indices:
|
indices:
|
||||||
|
@ -135,7 +135,7 @@ GameObject:
|
|||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 1
|
m_IsActive: 0
|
||||||
--- !u!212 &111982857
|
--- !u!212 &111982857
|
||||||
SpriteRenderer:
|
SpriteRenderer:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -184,7 +184,7 @@ SpriteRenderer:
|
|||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
m_FlipX: 0
|
m_FlipX: 0
|
||||||
m_FlipY: 0
|
m_FlipY: 0
|
||||||
m_DrawMode: 0
|
m_DrawMode: 1
|
||||||
m_Size: {x: 1, y: 1}
|
m_Size: {x: 1, y: 1}
|
||||||
m_AdaptiveModeThreshold: 0.5
|
m_AdaptiveModeThreshold: 0.5
|
||||||
m_SpriteTileMode: 0
|
m_SpriteTileMode: 0
|
||||||
@ -201,7 +201,7 @@ Transform:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
m_LocalScale: {x: 2, y: 2, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
@ -746,6 +746,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
textureLevel: {fileID: 828003924}
|
textureLevel: {fileID: 828003924}
|
||||||
|
dataOffset: {x: 0, y: 0}
|
||||||
--- !u!1 &1236970682
|
--- !u!1 &1236970682
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -934,8 +935,8 @@ Camera:
|
|||||||
m_GameObject: {fileID: 1239746123}
|
m_GameObject: {fileID: 1239746123}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_ClearFlags: 1
|
m_ClearFlags: 2
|
||||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
m_BackGroundColor: {r: 0.26415092, g: 0.26415092, b: 0.26415092, a: 0}
|
||||||
m_projectionMatrixMode: 1
|
m_projectionMatrixMode: 1
|
||||||
m_GateFitMode: 2
|
m_GateFitMode: 2
|
||||||
m_FOVAxisMode: 0
|
m_FOVAxisMode: 0
|
||||||
|
@ -11,7 +11,7 @@ namespace AI
|
|||||||
public abstract JobBase GetJob(Entity.Entity target);
|
public abstract JobBase GetJob(Entity.Entity target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Selector : AIBase
|
public class ThinkNode_Selector : AIBase
|
||||||
{
|
{
|
||||||
public override JobBase GetJob(Entity.Entity target)
|
public override JobBase GetJob(Entity.Entity target)
|
||||||
{
|
{
|
||||||
@ -24,13 +24,13 @@ namespace AI
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class ConditionalAI : Selector
|
public class ThinkNode_Conditional : ThinkNode_Selector
|
||||||
{
|
{
|
||||||
// 条件函数,返回 true 表示满足条件
|
// 条件函数,返回 true 表示满足条件
|
||||||
private Func<Entity.Entity, bool> condition;
|
private Func<Entity.Entity, bool> condition;
|
||||||
|
|
||||||
// 构造函数,传入条件函数
|
// 构造函数,传入条件函数
|
||||||
public ConditionalAI(Func<Entity.Entity, bool> conditionFunc)
|
public ThinkNode_Conditional(Func<Entity.Entity, bool> conditionFunc)
|
||||||
{
|
{
|
||||||
condition = conditionFunc;
|
condition = conditionFunc;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ namespace AI
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class SequenceAI : AIBase
|
public class ThinkNode_Sequence : AIBase
|
||||||
{
|
{
|
||||||
public override JobBase GetJob(Entity.Entity target)
|
public override JobBase GetJob(Entity.Entity target)
|
||||||
{
|
{
|
||||||
@ -61,33 +61,5 @@ namespace AI
|
|||||||
return null; // 所有子节点完成时返回 null
|
return null; // 所有子节点完成时返回 null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class ContinuousMove : AIBase
|
|
||||||
{
|
|
||||||
public override JobBase GetJob(Entity.Entity target)
|
|
||||||
{
|
|
||||||
return new MoveJob();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TrackPlayer : AIBase
|
|
||||||
{
|
|
||||||
public override JobBase GetJob(Entity.Entity target)
|
|
||||||
{
|
|
||||||
return new TrackPlayerJob();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class RandomWander : AIBase
|
|
||||||
{
|
|
||||||
public override JobBase GetJob(Entity.Entity target)
|
|
||||||
{
|
|
||||||
return new WanderJob();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class Idel : AIBase
|
|
||||||
{
|
|
||||||
public override JobBase GetJob(Entity.Entity target)
|
|
||||||
{
|
|
||||||
return new IdleJob();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
33
Client/Assets/Scripts/AI/JobGiver.cs
Normal file
33
Client/Assets/Scripts/AI/JobGiver.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
namespace AI
|
||||||
|
{
|
||||||
|
public class JobGiver_ContinuousMove : AIBase
|
||||||
|
{
|
||||||
|
public override JobBase GetJob(Entity.Entity target)
|
||||||
|
{
|
||||||
|
return new MoveJob();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class JobGiver_Enemies : AIBase
|
||||||
|
{
|
||||||
|
public override JobBase GetJob(Entity.Entity target)
|
||||||
|
{
|
||||||
|
return new TrackPlayerJob();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class JobGiver_RandomWander : AIBase
|
||||||
|
{
|
||||||
|
public override JobBase GetJob(Entity.Entity target)
|
||||||
|
{
|
||||||
|
return new WanderJob();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class JobGiver_Idel : AIBase
|
||||||
|
{
|
||||||
|
public override JobBase GetJob(Entity.Entity target)
|
||||||
|
{
|
||||||
|
return new IdleJob();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
Client/Assets/Scripts/AI/JobGiver.cs.meta
Normal file
3
Client/Assets/Scripts/AI/JobGiver.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 30648f750dce43e493f5e94cb735988c
|
||||||
|
timeCreated: 1754974329
|
@ -9,6 +9,17 @@ namespace Base
|
|||||||
{
|
{
|
||||||
public RightMenuPrefab rightMenuPrefab;
|
public RightMenuPrefab rightMenuPrefab;
|
||||||
|
|
||||||
|
public Vector3 Position
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
rightMenuPrefab.transform.position = value;
|
||||||
|
}
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return rightMenuPrefab.transform.position;
|
||||||
|
}
|
||||||
|
}
|
||||||
public void Show()
|
public void Show()
|
||||||
{
|
{
|
||||||
rightMenuPrefab.Show();
|
rightMenuPrefab.Show();
|
||||||
|
@ -1,7 +1,18 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Data
|
namespace Data
|
||||||
{
|
{
|
||||||
|
public enum Relation
|
||||||
|
{
|
||||||
|
Neutral,
|
||||||
|
Hostile,
|
||||||
|
Friendly,
|
||||||
|
}
|
||||||
public class AffiliationDef : Define
|
public class AffiliationDef : Define
|
||||||
{
|
{
|
||||||
|
public Relation defaultRelation = Relation.Neutral;
|
||||||
|
public List<string> hostileFactions;
|
||||||
|
public List<string> neutralFactions;
|
||||||
|
public List<string> friendlyFactions;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ namespace Data
|
|||||||
public class BehaviorTreeDef : Define
|
public class BehaviorTreeDef : Define
|
||||||
{
|
{
|
||||||
public BehaviorTreeDef[] childTree;
|
public BehaviorTreeDef[] childTree;
|
||||||
public string className="Selector";
|
public string className= "ThinkNode_Selector";
|
||||||
public string value;
|
public string value;
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,37 +26,63 @@ namespace Data
|
|||||||
public DrawNodeDef drawingOrder_left;
|
public DrawNodeDef drawingOrder_left;
|
||||||
public DrawNodeDef drawingOrder_right;
|
public DrawNodeDef drawingOrder_right;
|
||||||
public string texturePath;
|
public string texturePath;
|
||||||
public int pixelsPerUnit = 16;
|
public float pixelsPerUnit = 16;
|
||||||
|
|
||||||
public DrawNodeDef GetDrawingOrder(Orientation orientation)
|
public DrawNodeDef GetDrawingOrder(Orientation orientation, out Orientation sourceOrientation)
|
||||||
{
|
{
|
||||||
// 定义一个临时变量用于存储结果
|
// 定义一个临时变量用于存储结果
|
||||||
DrawNodeDef result = null;
|
DrawNodeDef result = null;
|
||||||
|
|
||||||
|
// 初始化 sourceOrientation 为默认值
|
||||||
|
sourceOrientation = Orientation.Down;
|
||||||
|
|
||||||
// 根据传入的 Orientation 获取对应的 DrawingOrderDef
|
// 根据传入的 Orientation 获取对应的 DrawingOrderDef
|
||||||
switch (orientation)
|
switch (orientation)
|
||||||
{
|
{
|
||||||
case Orientation.Down:
|
case Orientation.Down:
|
||||||
result = drawingOrder_down;
|
result = drawingOrder_down;
|
||||||
|
sourceOrientation = Orientation.Down;
|
||||||
break;
|
break;
|
||||||
case Orientation.Up:
|
case Orientation.Up:
|
||||||
result = drawingOrder_up;
|
result = drawingOrder_up;
|
||||||
|
sourceOrientation = Orientation.Up;
|
||||||
break;
|
break;
|
||||||
case Orientation.Left:
|
case Orientation.Left:
|
||||||
result = drawingOrder_left;
|
result = drawingOrder_left;
|
||||||
|
sourceOrientation = Orientation.Left;
|
||||||
break;
|
break;
|
||||||
case Orientation.Right:
|
case Orientation.Right:
|
||||||
result = drawingOrder_right;
|
result = drawingOrder_right;
|
||||||
|
sourceOrientation = Orientation.Right;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("Invalid orientation value.");
|
throw new ArgumentException("Invalid orientation value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果当前方向的结果为空,则尝试用 drawingOrder_down 填充
|
// 如果当前方向的结果为空,则尝试用 drawingOrder_down 填充
|
||||||
if (result == null) result = drawingOrder_down;
|
if (result == null)
|
||||||
|
{
|
||||||
|
result = drawingOrder_down;
|
||||||
|
sourceOrientation = Orientation.Down; // 更新 sourceOrientation
|
||||||
|
}
|
||||||
|
|
||||||
// 如果 drawingOrder_down 仍然为空,则尝试用其他非空方向填充
|
// 如果 drawingOrder_down 仍然为空,则尝试用其他非空方向填充
|
||||||
if (result == null) result = drawingOrder_up ?? drawingOrder_left ?? drawingOrder_right;
|
if (result != null) return result;
|
||||||
|
if (drawingOrder_up != null)
|
||||||
|
{
|
||||||
|
result = drawingOrder_up;
|
||||||
|
sourceOrientation = Orientation.Up; // 更新 sourceOrientation
|
||||||
|
}
|
||||||
|
else if (drawingOrder_left != null)
|
||||||
|
{
|
||||||
|
result = drawingOrder_left;
|
||||||
|
sourceOrientation = Orientation.Left; // 更新 sourceOrientation
|
||||||
|
}
|
||||||
|
else if (drawingOrder_right != null)
|
||||||
|
{
|
||||||
|
result = drawingOrder_right;
|
||||||
|
sourceOrientation = Orientation.Right; // 更新 sourceOrientation
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
namespace Data
|
namespace Data
|
||||||
{
|
{
|
||||||
|
public enum ItemRarity
|
||||||
|
{
|
||||||
|
Common,
|
||||||
|
Uncommon,
|
||||||
|
Rare,
|
||||||
|
Epic,
|
||||||
|
Legendary
|
||||||
|
}
|
||||||
public class ItemDef:Define
|
public class ItemDef:Define
|
||||||
{
|
{
|
||||||
public ImageDef texture;
|
public ImageDef texture;
|
||||||
public AttributesDef attributes;
|
public ItemRarity rarity = ItemRarity.Common;
|
||||||
|
public int maxStack = 1; // 最大堆叠数量,默认为1
|
||||||
|
public bool ssEquippable = false; // 是否可装备
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WeaponDef : ItemDef
|
public class WeaponDef : ItemDef
|
||||||
{
|
{
|
||||||
|
public AttributesDef attributes;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using UnityEngine.Tilemaps;
|
||||||
|
|
||||||
namespace Data
|
namespace Data
|
||||||
{
|
{
|
||||||
@ -7,6 +8,7 @@ namespace Data
|
|||||||
{
|
{
|
||||||
public ImageDef texture;
|
public ImageDef texture;
|
||||||
public string name = "";
|
public string name = "";
|
||||||
|
public Tile.ColliderType collider = Tile.ColliderType.None;
|
||||||
|
|
||||||
public override bool Init(XElement xmlDef)
|
public override bool Init(XElement xmlDef)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ namespace Entity
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
aiTree = new RandomWander();
|
aiTree = new JobGiver_RandomWander();
|
||||||
attributes = new AttributesDef();
|
attributes = new AttributesDef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using AI;
|
using AI;
|
||||||
using Base;
|
using Base;
|
||||||
@ -7,23 +8,73 @@ using Prefab;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
|
|
||||||
namespace Entity
|
namespace Entity
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 表示游戏中的实体类,继承自 MonoBehaviour 并实现 ITick 接口。
|
||||||
|
/// </summary>
|
||||||
public class Entity : MonoBehaviour, ITick
|
public class Entity : MonoBehaviour, ITick
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 动画预制体,用于管理实体的动画逻辑。
|
||||||
|
/// </summary>
|
||||||
public SpriteAnimator animatorPrefab;
|
public SpriteAnimator animatorPrefab;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图像预制体,用于管理实体的静态图像显示。
|
||||||
|
/// </summary>
|
||||||
public ImagePrefab imagePrefab;
|
public ImagePrefab imagePrefab;
|
||||||
|
|
||||||
|
public ProgressBarPrefab healthBarPrefab;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 人工智能行为树,定义实体的行为逻辑。
|
||||||
|
/// </summary>
|
||||||
public AIBase aiTree;
|
public AIBase aiTree;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前实体正在执行的任务。
|
||||||
|
/// </summary>
|
||||||
public JobBase currentJob;
|
public JobBase currentJob;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体的属性定义,包括生命值、攻击力、防御力等。
|
||||||
|
/// </summary>
|
||||||
public AttributesDef attributes = new();
|
public AttributesDef attributes = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体当前的移动方向。
|
||||||
|
/// </summary>
|
||||||
public Vector3 direction;
|
public Vector3 direction;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体的身体部分,用于挂载动画和图像节点。
|
||||||
|
/// </summary>
|
||||||
public GameObject body;
|
public GameObject body;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体所属的阵营或派系。
|
||||||
|
/// </summary>
|
||||||
public string affiliation;
|
public string affiliation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 表示实体是否可以被选择。
|
||||||
|
/// </summary>
|
||||||
public bool canSelect = true;
|
public bool canSelect = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 表示实体是否处于追逐状态(影响移动速度)。
|
||||||
|
/// </summary>
|
||||||
public bool IsChase { set; get; } = true;
|
public bool IsChase { set; get; } = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 表示实体是否由玩家控制。
|
||||||
|
/// </summary>
|
||||||
public bool PlayerControlled
|
public bool PlayerControlled
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
@ -37,26 +88,76 @@ namespace Entity
|
|||||||
}
|
}
|
||||||
get => _isPlayerControlled;
|
get => _isPlayerControlled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取实体当前位置。
|
||||||
|
/// </summary>
|
||||||
public Vector3 Position => transform.position;
|
public Vector3 Position => transform.position;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 表示实体是否已经死亡(生命值小于等于零)。
|
||||||
|
/// </summary>
|
||||||
public bool IsDead => attributes.health <= 0;
|
public bool IsDead => attributes.health <= 0;
|
||||||
|
|
||||||
private bool _isPlayerControlled = false;
|
private bool _isPlayerControlled = false;
|
||||||
private bool _warning = false;
|
private bool _warning = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 存储不同朝向下的动画节点集合。
|
||||||
|
/// </summary>
|
||||||
public Dictionary<Orientation, List<ITick>> bodyAnimationNode = new();
|
public Dictionary<Orientation, List<ITick>> bodyAnimationNode = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 存储不同朝向下的身体节点对象。
|
||||||
|
/// </summary>
|
||||||
private Dictionary<Orientation, GameObject> bodyNodes = new();
|
private Dictionary<Orientation, GameObject> bodyNodes = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前实体的朝向。
|
||||||
|
/// </summary>
|
||||||
private Orientation currentOrientation = Orientation.Down;
|
private Orientation currentOrientation = Orientation.Down;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 攻击动画的持续时间(秒)。
|
||||||
|
/// </summary>
|
||||||
|
private const float attackAnimationDuration = 0.1f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 抖动的偏移量。
|
||||||
|
/// </summary>
|
||||||
|
private const float shakeOffset = 0.5f;
|
||||||
|
// 协程引用
|
||||||
|
private Coroutine attackCoroutine;
|
||||||
|
|
||||||
|
protected PawnDef entityDef;
|
||||||
|
|
||||||
|
|
||||||
|
public float hitBarUIShowTime = 5;
|
||||||
|
private float hitBarUIShowTimer = 0;
|
||||||
|
public bool isShowingOfHitBarUI=>hitBarUIShowTimer > 0;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化实体的基本属性和行为树。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pawnDef">实体的定义数据。</param>
|
||||||
public virtual void Init(PawnDef pawnDef)
|
public virtual void Init(PawnDef pawnDef)
|
||||||
{
|
{
|
||||||
attributes = pawnDef.attributes.Clone();
|
attributes = pawnDef.attributes.Clone();
|
||||||
aiTree = ConvertToAIBase(pawnDef.behaviorTree);
|
aiTree = Utils.BehaviorTree.ConvertToAIBase(pawnDef.behaviorTree);
|
||||||
affiliation = pawnDef.affiliation;
|
affiliation = pawnDef.affiliation;
|
||||||
InitBody(pawnDef.drawingOrder);
|
InitBody(pawnDef.drawingOrder);
|
||||||
|
entityDef = pawnDef;
|
||||||
|
|
||||||
|
HideHealthBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化实体的身体部分,包括不同朝向下的绘图节点。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawingOrder">绘制顺序定义。</param>
|
||||||
public virtual void InitBody(DrawingOrderDef drawingOrder)
|
public virtual void InitBody(DrawingOrderDef drawingOrder)
|
||||||
{
|
{
|
||||||
// 定义方向枚举和对应的 GetDrawingOrder 调用
|
// 定义方向枚举和对应的 GetDrawingOrder 调用
|
||||||
@ -67,12 +168,12 @@ namespace Entity
|
|||||||
currentOrientation = orientation;
|
currentOrientation = orientation;
|
||||||
bodyAnimationNode[orientation] = new();
|
bodyAnimationNode[orientation] = new();
|
||||||
// 获取当前方向的绘图节点
|
// 获取当前方向的绘图节点
|
||||||
var drawNode = drawingOrder.GetDrawingOrder(orientation);
|
var drawNode = drawingOrder.GetDrawingOrder(orientation, out var realOrientation);
|
||||||
|
|
||||||
if (drawNode == null) continue;
|
if (drawNode == null) continue;
|
||||||
var directionRoot = new GameObject(orientation.ToString());
|
var directionRoot = new GameObject(orientation.ToString());
|
||||||
directionRoot.transform.SetParent(body.transform, false);
|
directionRoot.transform.SetParent(body.transform, false);
|
||||||
InitBodyPart(drawNode, directionRoot, drawingOrder.texturePath);
|
InitBodyPart(drawNode, directionRoot, drawingOrder.texturePath,realOrientation);
|
||||||
bodyNodes[orientation] = directionRoot;
|
bodyNodes[orientation] = directionRoot;
|
||||||
}
|
}
|
||||||
currentOrientation = Orientation.Down;
|
currentOrientation = Orientation.Down;
|
||||||
@ -84,8 +185,13 @@ namespace Entity
|
|||||||
SetOrientation(Orientation.Down);
|
SetOrientation(Orientation.Down);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 递归初始化单个绘图节点及其子节点
|
/// <summary>
|
||||||
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent, string folderPath)
|
/// 递归初始化单个绘图节点及其子节点。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawNode">绘图节点定义。</param>
|
||||||
|
/// <param name="parent">父节点对象。</param>
|
||||||
|
/// <param name="folderPath">纹理资源路径。</param>
|
||||||
|
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent, string folderPath,Orientation realOrientation)
|
||||||
{
|
{
|
||||||
if (drawNode == null) return;
|
if (drawNode == null) return;
|
||||||
|
|
||||||
@ -103,12 +209,11 @@ namespace Entity
|
|||||||
nodeObject = Instantiate(imagePrefab.gameObject, parent.transform);
|
nodeObject = Instantiate(imagePrefab.gameObject, parent.transform);
|
||||||
var texture =
|
var texture =
|
||||||
Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID, folderPath,
|
Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID, folderPath,
|
||||||
$"{drawNode.nodeName}_{currentOrientation}");
|
$"{drawNode.nodeName}_{realOrientation}");
|
||||||
if (texture.Length > 0)
|
var image = nodeObject.GetComponent<ImagePrefab>();
|
||||||
{
|
image.SetSprite(texture.Length > 0
|
||||||
var image = nodeObject.GetComponent<ImagePrefab>();
|
? texture[0]
|
||||||
image.SetSprite(texture[0]);
|
: Managers.PackagesImageManager.Instance.defaultSprite);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DrawNodeType.Animation:
|
case DrawNodeType.Animation:
|
||||||
@ -118,7 +223,7 @@ namespace Entity
|
|||||||
bodyAnimationNode[currentOrientation].Add(tick);
|
bodyAnimationNode[currentOrientation].Add(tick);
|
||||||
var textures = Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID,
|
var textures = Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID,
|
||||||
folderPath,
|
folderPath,
|
||||||
$"{drawNode.nodeName}_{currentOrientation}");
|
$"{drawNode.nodeName}_{realOrientation}");
|
||||||
var animator = nodeObject.GetComponent<SpriteAnimator>();
|
var animator = nodeObject.GetComponent<SpriteAnimator>();
|
||||||
animator.SetSprites(textures);
|
animator.SetSprites(textures);
|
||||||
break;
|
break;
|
||||||
@ -131,9 +236,13 @@ namespace Entity
|
|||||||
// 递归初始化子节点
|
// 递归初始化子节点
|
||||||
foreach (var child in drawNode.children)
|
foreach (var child in drawNode.children)
|
||||||
{
|
{
|
||||||
InitBodyPart(child, nodeObject, folderPath);
|
InitBodyPart(child, nodeObject, folderPath,realOrientation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新实体的逻辑,包括玩家控制和自动行为。
|
||||||
|
/// </summary>
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
if (_isPlayerControlled)
|
if (_isPlayerControlled)
|
||||||
@ -151,47 +260,104 @@ namespace Entity
|
|||||||
tick.Tick();
|
tick.Tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isShowingOfHitBarUI)
|
||||||
|
{
|
||||||
|
hitBarUIShowTimer -= Time.deltaTime;
|
||||||
|
if (hitBarUIShowTimer <= 0)
|
||||||
|
{
|
||||||
|
HideHealthBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尝试攻击目标实体。
|
||||||
|
/// </summary>
|
||||||
public virtual void TryAttack()
|
public virtual void TryAttack()
|
||||||
{
|
{
|
||||||
|
if(attackCoroutine == null)
|
||||||
|
attackCoroutine = StartCoroutine(AttackFlow());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置实体的朝向。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="orientation">新的朝向。</param>
|
||||||
public virtual void SetOrientation(Orientation orientation)
|
public virtual void SetOrientation(Orientation orientation)
|
||||||
{
|
{
|
||||||
bodyNodes[currentOrientation]?.SetActive(false);
|
bodyNodes[currentOrientation]?.SetActive(false);
|
||||||
currentOrientation = orientation;
|
currentOrientation = orientation;
|
||||||
bodyNodes[orientation]?.SetActive(true);
|
bodyNodes[orientation]?.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 往对应朝向移动moveSpeed*deltaTime的距离
|
/// 根据方向尝试移动实体。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void TryMove()
|
public virtual void TryMove()
|
||||||
{
|
{
|
||||||
transform.position += direction * (attributes.moveSpeed * Time.deltaTime * (IsChase ? 1 : 0.5f));
|
transform.position += direction * (attributes.moveSpeed * Time.deltaTime * (IsChase ? 1 : 0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理实体受到攻击的逻辑。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="from">攻击来源实体。</param>
|
||||||
public virtual void OnHit(Entity from)
|
public virtual void OnHit(Entity from)
|
||||||
{
|
{
|
||||||
var hit = from.attributes.attack - attributes.defense;
|
var hit = from.attributes.attack - attributes.defense;
|
||||||
if (hit < 0)
|
if (hit < 0)
|
||||||
hit = from.attributes.attack / 100;
|
hit = from.attributes.attack / 100;
|
||||||
attributes.health -= hit;
|
attributes.health -= hit;
|
||||||
|
currentJob?.StopJob();
|
||||||
currentJob.StopJob();
|
ShowHealthBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void SetTarget(Vector3 pos)
|
public void ShowHealthBar()
|
||||||
{
|
{
|
||||||
direction = (pos - transform.position).normalized;
|
healthBarPrefab.gameObject.SetActive(true);
|
||||||
|
healthBarPrefab.Progress = (float)attributes.health / entityDef.attributes.health;
|
||||||
|
hitBarUIShowTimer=hitBarUIShowTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HideHealthBar()
|
||||||
|
{
|
||||||
|
healthBarPrefab.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 杀死实体,设置生命值为零。
|
||||||
|
/// </summary>
|
||||||
public virtual void Kill()
|
public virtual void Kill()
|
||||||
{
|
{
|
||||||
attributes.health = 0;
|
attributes.health = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置实体的目标位置。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos">目标位置。</param>
|
||||||
|
public virtual void SetTarget(Vector3 pos)
|
||||||
|
{
|
||||||
|
direction = (pos - transform.position).normalized;
|
||||||
|
Orientation ori;
|
||||||
|
// 判断方向向量最接近哪个朝向
|
||||||
|
if (Mathf.Abs(direction.y) > Mathf.Abs(direction.x))
|
||||||
|
{
|
||||||
|
// 垂直方向优先
|
||||||
|
ori = direction.y > 0 ? Orientation.Up : Orientation.Down;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 水平方向优先
|
||||||
|
ori = direction.x > 0 ? Orientation.Right : Orientation.Left;
|
||||||
|
}
|
||||||
|
SetOrientation(ori);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自动行为逻辑,根据行为树执行任务。
|
||||||
|
/// </summary>
|
||||||
private void AutoBehave()
|
private void AutoBehave()
|
||||||
{
|
{
|
||||||
if (aiTree == null)
|
if (aiTree == null)
|
||||||
@ -214,12 +380,16 @@ namespace Entity
|
|||||||
currentJob.Update();
|
currentJob.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新玩家控制的逻辑,处理输入和移动。
|
||||||
|
/// </summary>
|
||||||
protected virtual void UpdatePlayerControls()
|
protected virtual void UpdatePlayerControls()
|
||||||
{
|
{
|
||||||
// 检测 Shift 键状态
|
// 检测 Shift 键状态
|
||||||
var isHoldingShift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
var isHoldingShift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
||||||
IsChase = !isHoldingShift; // 按住 Shift 时 IsChase = false,否则 true
|
IsChase = !isHoldingShift; // 按住 Shift 时 IsChase = false,否则 true
|
||||||
// 获取当前键盘输入状态(2D 移动,只使用 X 和 Y 轴)
|
// 获取当前键盘输入状态(2D 移动,只使用 X 和 Y 轴)
|
||||||
var inputDirection = Vector2.zero;
|
var inputDirection = Vector2.zero;
|
||||||
|
|
||||||
// 检测 WASD 或方向键输入
|
// 检测 WASD 或方向键输入
|
||||||
@ -239,7 +409,10 @@ namespace Entity
|
|||||||
{
|
{
|
||||||
inputDirection += Vector2.right; // 向右移动(X 轴正方向)
|
inputDirection += Vector2.right; // 向右移动(X 轴正方向)
|
||||||
}
|
}
|
||||||
|
if (Input.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
TryAttack();
|
||||||
|
}
|
||||||
// 如果有输入方向,则设置目标位置并尝试移动
|
// 如果有输入方向,则设置目标位置并尝试移动
|
||||||
if (inputDirection == Vector2.zero) return;
|
if (inputDirection == Vector2.zero) return;
|
||||||
// 归一化方向向量,确保对角线移动速度一致
|
// 归一化方向向量,确保对角线移动速度一致
|
||||||
@ -253,61 +426,76 @@ namespace Entity
|
|||||||
|
|
||||||
// 调用 TryMove 方法处理实际移动逻辑
|
// 调用 TryMove 方法处理实际移动逻辑
|
||||||
TryMove();
|
TryMove();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public static AIBase ConvertToAIBase(BehaviorTreeDef behaviorTreeDef)
|
// 攻击流程协程
|
||||||
|
IEnumerator AttackFlow()
|
||||||
{
|
{
|
||||||
if (behaviorTreeDef == null)
|
// 播放攻击动画并获取动画持续时间
|
||||||
return null;
|
var animationDuration = PlayAttackAnimation();
|
||||||
var aiBase = CreateAIBaseInstance(behaviorTreeDef.className);
|
// 等待动画执行完毕
|
||||||
if (behaviorTreeDef.childTree != null)
|
yield return new WaitForSeconds(animationDuration);
|
||||||
{
|
// 调用检测并攻击敌人的方法
|
||||||
foreach (var child in behaviorTreeDef.childTree)
|
DetectAndAttackEnemies();
|
||||||
{
|
// 攻击流程结束,清理协程引用
|
||||||
if (child != null)
|
attackCoroutine = null;
|
||||||
{
|
|
||||||
aiBase.children.Add(ConvertToAIBase(child));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return aiBase;
|
|
||||||
}
|
}
|
||||||
// 使用反射根据 className 创建具体的 AIBase 子类实例
|
|
||||||
private static AIBase CreateAIBaseInstance(string className)
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 播放攻击动画。
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>开始检测攻击范围内敌人的时间。</returns>
|
||||||
|
public float PlayAttackAnimation()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(className))
|
// 启动协程来执行攻击动画
|
||||||
throw new ArgumentException("className 不能为空");
|
StartCoroutine(ShakeInDirectionCoroutine());
|
||||||
if (className.Equals("AIBase", StringComparison.OrdinalIgnoreCase))
|
|
||||||
|
// 返回检测敌人的起始时间
|
||||||
|
return attackAnimationDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator ShakeInDirectionCoroutine()
|
||||||
|
{
|
||||||
|
var originalPosition = transform.position; // 记录原始位置
|
||||||
|
transform.position += direction * shakeOffset;
|
||||||
|
yield return new WaitForSeconds(attackAnimationDuration);
|
||||||
|
transform.position = originalPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DetectAndAttackEnemies()
|
||||||
|
{
|
||||||
|
const int attackRange = 3;
|
||||||
|
var attackCount = 3;
|
||||||
|
|
||||||
|
// 获取攻击范围内的所有碰撞体,使用LayerMask过滤掉非敌人
|
||||||
|
var hits = Physics2D.OverlapCircleAll(
|
||||||
|
transform.position,
|
||||||
|
attackRange,
|
||||||
|
LayerMask.GetMask("Entity"));
|
||||||
|
|
||||||
|
// 或者使用标签过滤(如果敌人有特定标签)
|
||||||
|
// Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, attackRange);
|
||||||
|
|
||||||
|
Debug.Log($"Found {hits.Length} potential targets in attack range");
|
||||||
|
|
||||||
|
foreach (var hit in hits)
|
||||||
{
|
{
|
||||||
return (AIBase)Activator.CreateInstance(typeof(AIBase));
|
if (attackCount <= 0) break;
|
||||||
|
|
||||||
|
// 检查是否是自身(额外安全措施)
|
||||||
|
if (hit.gameObject == this.gameObject) continue;
|
||||||
|
|
||||||
|
// 获取Entity组件
|
||||||
|
var entity = hit.GetComponent<Entity>();
|
||||||
|
if (!entity) continue;
|
||||||
|
|
||||||
|
// 执行攻击
|
||||||
|
entity.OnHit(this);
|
||||||
|
attackCount--;
|
||||||
}
|
}
|
||||||
// 定义可能的命名空间列表
|
|
||||||
var possibleNamespaces = new[] { "AI" };
|
|
||||||
|
|
||||||
foreach (var ns in possibleNamespaces)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// 获取当前程序集
|
|
||||||
var assembly = typeof(AIBase).Assembly;
|
|
||||||
|
|
||||||
// 尝试查找类型
|
|
||||||
var type = assembly.GetType($"{ns}.{className}");
|
|
||||||
|
|
||||||
if (type != null && typeof(AIBase).IsAssignableFrom(type))
|
|
||||||
{
|
|
||||||
// 如果找到合适的类型,则创建实例并返回
|
|
||||||
return (AIBase)Activator.CreateInstance(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// 忽略单个命名空间的错误,继续尝试下一个命名空间
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果所有命名空间都未找到对应的类型,抛出异常
|
|
||||||
throw new InvalidOperationException($"无法找到类型 {className} 或该类型不是 AIBase 的子类");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
70
Client/Assets/Scripts/Entity/Inventory.cs
Normal file
70
Client/Assets/Scripts/Entity/Inventory.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Item;
|
||||||
|
|
||||||
|
namespace Entity
|
||||||
|
{
|
||||||
|
public class Inventory
|
||||||
|
{
|
||||||
|
public Entity from; // 物品所属实体
|
||||||
|
public List<ItemBase> items = new List<ItemBase>(); // 背包中的物品列表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加物品到背包
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">要添加的物品</param>
|
||||||
|
/// <param name="count">添加的数量</param>
|
||||||
|
public void AddItem(ItemResource resource, int count)
|
||||||
|
{
|
||||||
|
if (count <= 0) return; // 如果数量小于等于0,直接返回
|
||||||
|
|
||||||
|
// 检查背包中是否已存在相同物品
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
if (item.resource.Equals(resource))
|
||||||
|
{
|
||||||
|
item.count += count; // 增加数量
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有找到相同物品,则创建新物品并添加到背包
|
||||||
|
var newItem = new ItemBase { resource = resource, count = count };
|
||||||
|
items.Add(newItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从背包中取出物品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemName">物品名称</param>
|
||||||
|
/// <param name="count">取出的数量</param>
|
||||||
|
/// <returns>是否成功取出</returns>
|
||||||
|
public bool RemoveItem(string itemName, int count)
|
||||||
|
{
|
||||||
|
if (count <= 0) return false; // 如果数量小于等于0,直接返回失败
|
||||||
|
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
if (item.resource.name == itemName)
|
||||||
|
{
|
||||||
|
if (item.count >= count)
|
||||||
|
{
|
||||||
|
item.count -= count; // 减少数量
|
||||||
|
if (item.count == 0)
|
||||||
|
{
|
||||||
|
items.Remove(item); // 如果数量为0,则移除该物品
|
||||||
|
}
|
||||||
|
|
||||||
|
return true; // 成功取出
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false; // 数量不足
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false; // 未找到物品
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
3
Client/Assets/Scripts/Entity/Inventory.cs.meta
Normal file
3
Client/Assets/Scripts/Entity/Inventory.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3da96d312e8e4c65b9157548281f7826
|
||||||
|
timeCreated: 1755061766
|
@ -1,12 +1,9 @@
|
|||||||
namespace Entity
|
namespace Entity
|
||||||
{
|
{
|
||||||
public class Monster
|
public class Monster:Entity
|
||||||
{
|
{
|
||||||
public Protocol.MonsterPack ToPack()
|
|
||||||
{
|
|
||||||
var pack= new Protocol.MonsterPack();
|
|
||||||
return pack;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Prefab;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ namespace Entity
|
|||||||
public GameObject body;
|
public GameObject body;
|
||||||
public SpriteRenderer outlineRenderer;
|
public SpriteRenderer outlineRenderer;
|
||||||
public CapsuleCollider2D outlineCollider;
|
public CapsuleCollider2D outlineCollider;
|
||||||
|
public ProgressBarPrefab progressBarPrefab;
|
||||||
|
|
||||||
public Entity entity;
|
public Entity entity;
|
||||||
|
|
||||||
@ -23,6 +24,9 @@ namespace Entity
|
|||||||
outlineRenderer.size = size;
|
outlineRenderer.size = size;
|
||||||
outlineCollider.direction = size.x > size.y ? CapsuleDirection2D.Horizontal : CapsuleDirection2D.Vertical;
|
outlineCollider.direction = size.x > size.y ? CapsuleDirection2D.Horizontal : CapsuleDirection2D.Vertical;
|
||||||
outlineCollider.size = size;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Show()
|
public void Show()
|
||||||
@ -76,23 +80,23 @@ namespace Entity
|
|||||||
private void OnMouseEnter()
|
private void OnMouseEnter()
|
||||||
{
|
{
|
||||||
Show();
|
Show();
|
||||||
_select = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMouseExit()
|
private void OnMouseExit()
|
||||||
{
|
{
|
||||||
Hide();
|
Hide();
|
||||||
_select = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMouseOver()
|
private void OnMouseOver()
|
||||||
{
|
{
|
||||||
|
if (!entity.canSelect)
|
||||||
|
return;
|
||||||
// 检测是否按下的是鼠标右键
|
// 检测是否按下的是鼠标右键
|
||||||
if (Input.GetMouseButtonDown(1)) // 鼠标右键对应的是按钮索引 1
|
if (Input.GetMouseButtonDown(1)) // 鼠标右键对应的是按钮索引 1
|
||||||
{
|
{
|
||||||
var rightMenu = Base.RightMenu.Instance;
|
var rightMenu = Base.RightMenu.Instance;
|
||||||
rightMenu.Init(GetMenu());
|
rightMenu.Init(GetMenu());
|
||||||
rightMenu.transform.position = Input.mousePosition;
|
rightMenu.Position = Input.mousePosition;
|
||||||
rightMenu.Show();
|
rightMenu.Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,6 +108,14 @@ namespace Entity
|
|||||||
result.Add(("结束操控", EndControl));
|
result.Add(("结束操控", EndControl));
|
||||||
else
|
else
|
||||||
result.Add(("手动操控", StartControl));
|
result.Add(("手动操控", StartControl));
|
||||||
|
if (CameraControl.CameraControl.Instance.focusedEntity == entity)
|
||||||
|
{
|
||||||
|
result.Add(("取消跟随", ()=>CameraControl.CameraControl.Instance.focusedEntity=null));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.Add(("视角跟随", ()=>CameraControl.CameraControl.Instance.focusedEntity=entity));
|
||||||
|
}
|
||||||
result.Add(("杀死", () => entity.Kill()));
|
result.Add(("杀死", () => entity.Kill()));
|
||||||
result.Add(("变成笨蛋", BecomeDefault));
|
result.Add(("变成笨蛋", BecomeDefault));
|
||||||
return result;
|
return result;
|
||||||
|
3
Client/Assets/Scripts/Item.meta
Normal file
3
Client/Assets/Scripts/Item.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 89870f1a36ce43558b90c49513f55f10
|
||||||
|
timeCreated: 1755061695
|
12
Client/Assets/Scripts/Item/ItemBase.cs
Normal file
12
Client/Assets/Scripts/Item/ItemBase.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Item
|
||||||
|
{
|
||||||
|
public class ItemBase
|
||||||
|
{
|
||||||
|
public ItemResource resource;
|
||||||
|
|
||||||
|
public int count=0;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
3
Client/Assets/Scripts/Item/ItemBase.cs.meta
Normal file
3
Client/Assets/Scripts/Item/ItemBase.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 01a2843d5856483fa5b6967e2e01db62
|
||||||
|
timeCreated: 1755061705
|
12
Client/Assets/Scripts/Item/ItemResource.cs
Normal file
12
Client/Assets/Scripts/Item/ItemResource.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Item
|
||||||
|
{
|
||||||
|
public class ItemResource
|
||||||
|
{
|
||||||
|
public string name;
|
||||||
|
public string description;
|
||||||
|
|
||||||
|
public Sprite icon;
|
||||||
|
}
|
||||||
|
}
|
3
Client/Assets/Scripts/Item/ItemResource.cs.meta
Normal file
3
Client/Assets/Scripts/Item/ItemResource.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e85c1b3671d1471e85a7ec96eadfabe2
|
||||||
|
timeCreated: 1755061828
|
45
Client/Assets/Scripts/Managers/ItemResourceManager.cs
Normal file
45
Client/Assets/Scripts/Managers/ItemResourceManager.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Data;
|
||||||
|
using Item;
|
||||||
|
|
||||||
|
namespace Managers
|
||||||
|
{
|
||||||
|
public class ItemResourceManager:Utils.Singleton<ItemResourceManager>
|
||||||
|
{
|
||||||
|
//定义名,物品
|
||||||
|
public Dictionary<string,Item.ItemResource> items;
|
||||||
|
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
var itemDefs = Managers.DefineManager.Instance.QueryDefinesByType<ItemDef>();
|
||||||
|
foreach (var itemDef in itemDefs)
|
||||||
|
{
|
||||||
|
var item=new Item.ItemResource();
|
||||||
|
item.name = itemDef.label;
|
||||||
|
item.description = itemDef.description;
|
||||||
|
|
||||||
|
item.icon = Managers.PackagesImageManager.Instance.GetSprite(itemDef.texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemResource GetItem(string defName)
|
||||||
|
{
|
||||||
|
return items.GetValueOrDefault(defName,null);
|
||||||
|
}
|
||||||
|
// <summary>
|
||||||
|
/// 按物品名称查找物品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemName">要查找的物品名称</param>
|
||||||
|
/// <returns>找到的物品对象,如果未找到则返回 null</returns>
|
||||||
|
public ItemResource FindItemByName(string itemName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(itemName))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return items.Values.FirstOrDefault(item => item.name == itemName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eafd50f3a0594a6e845ecf87b04744ce
|
||||||
|
timeCreated: 1755062360
|
@ -90,16 +90,16 @@ namespace Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否为 Unity 资源路径
|
// 判断是否为 Unity 资源路径
|
||||||
bool isUnityResource = drawOrder.texturePath.StartsWith("res:", StringComparison.OrdinalIgnoreCase);
|
var isUnityResource = drawOrder.texturePath.StartsWith("res:", StringComparison.OrdinalIgnoreCase);
|
||||||
string rootPath = packRootSite[drawOrder.packID];
|
var rootPath = packRootSite[drawOrder.packID];
|
||||||
|
|
||||||
if (isUnityResource)
|
if (isUnityResource)
|
||||||
{
|
{
|
||||||
// 移除 "res:" 前缀并适配 Unity 资源路径规则
|
// 移除 "res:" 前缀并适配 Unity 资源路径规则
|
||||||
string resourceFolder = drawOrder.texturePath.Substring(4).TrimStart('/').Replace('\\', '/');
|
var resourceFolder = drawOrder.texturePath.Substring(4).TrimStart('/').Replace('\\', '/');
|
||||||
|
|
||||||
// 加载文件夹下的所有纹理资源
|
// 加载文件夹下的所有纹理资源
|
||||||
Texture2D[] textures = Resources.LoadAll<Texture2D>(resourceFolder);
|
var textures = Resources.LoadAll<Texture2D>(resourceFolder);
|
||||||
if (textures == null || textures.Length == 0)
|
if (textures == null || textures.Length == 0)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"No textures found in Unity resource folder: {resourceFolder}");
|
Debug.LogWarning($"No textures found in Unity resource folder: {resourceFolder}");
|
||||||
@ -124,7 +124,6 @@ namespace Managers
|
|||||||
new Vector2(0.5f, 0.5f), // 中心点
|
new Vector2(0.5f, 0.5f), // 中心点
|
||||||
drawOrder.pixelsPerUnit
|
drawOrder.pixelsPerUnit
|
||||||
);
|
);
|
||||||
|
|
||||||
var name = image.name;
|
var name = image.name;
|
||||||
|
|
||||||
// 插入纹理
|
// 插入纹理
|
||||||
@ -270,6 +269,10 @@ namespace Managers
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Sprite GetSprite(ImageDef ima)
|
||||||
|
{
|
||||||
|
return GetSprite(ima.packID,ima.name);
|
||||||
|
}
|
||||||
public Sprite GetSprite(string packID, string name)
|
public Sprite GetSprite(string packID, string name)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(packID))
|
if (string.IsNullOrEmpty(packID))
|
||||||
|
18
Client/Assets/Scripts/Prefab/ProgressBarPrefab.cs
Normal file
18
Client/Assets/Scripts/Prefab/ProgressBarPrefab.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Prefab
|
||||||
|
{
|
||||||
|
public class ProgressBarPrefab:MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject _progress;
|
||||||
|
public float Progress
|
||||||
|
{
|
||||||
|
get => _progress.transform.localScale.x;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
var x=Mathf.Clamp01(value);
|
||||||
|
_progress.transform.localScale = new Vector3(x, _progress.transform.localScale.y, _progress.transform.localScale.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Client/Assets/Scripts/Prefab/ProgressBarPrefab.cs.meta
Normal file
3
Client/Assets/Scripts/Prefab/ProgressBarPrefab.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 605f185650fe46d89a6e0d60fb8fb11c
|
||||||
|
timeCreated: 1755091112
|
75
Client/Assets/Scripts/Utils/BehaviorTree.cs
Normal file
75
Client/Assets/Scripts/Utils/BehaviorTree.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using AI;
|
||||||
|
using Data;
|
||||||
|
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
|
||||||
|
public static class BehaviorTree
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 将行为树定义转换为 AIBase 类型。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="behaviorTreeDef">行为树定义。</param>
|
||||||
|
/// <returns>转换后的 AIBase 实例。</returns>
|
||||||
|
public static AIBase ConvertToAIBase(BehaviorTreeDef behaviorTreeDef)
|
||||||
|
{
|
||||||
|
if (behaviorTreeDef == null)
|
||||||
|
return null;
|
||||||
|
var aiBase = CreateAIBaseInstance(behaviorTreeDef.className);
|
||||||
|
if (behaviorTreeDef.childTree != null)
|
||||||
|
{
|
||||||
|
foreach (var child in behaviorTreeDef.childTree)
|
||||||
|
{
|
||||||
|
if (child != null)
|
||||||
|
{
|
||||||
|
aiBase.children.Add(ConvertToAIBase(child));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aiBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用反射根据类名创建 AIBase 的具体子类实例。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="className">类名。</param>
|
||||||
|
/// <returns>创建的 AIBase 子类实例。</returns>
|
||||||
|
private static AIBase CreateAIBaseInstance(string className)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(className))
|
||||||
|
throw new ArgumentException("className 不能为空");
|
||||||
|
if (className.Equals("AIBase", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return (AIBase)Activator.CreateInstance(typeof(AIBase));
|
||||||
|
}
|
||||||
|
// 定义可能的命名空间列表
|
||||||
|
var possibleNamespaces = new[] { "AI" };
|
||||||
|
|
||||||
|
foreach (var ns in possibleNamespaces)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 获取当前程序集
|
||||||
|
var assembly = typeof(AIBase).Assembly;
|
||||||
|
|
||||||
|
// 尝试查找类型
|
||||||
|
var type = assembly.GetType($"{ns}.{className}");
|
||||||
|
|
||||||
|
if (type != null && typeof(AIBase).IsAssignableFrom(type))
|
||||||
|
{
|
||||||
|
// 如果找到合适的类型,则创建实例并返回
|
||||||
|
return (AIBase)Activator.CreateInstance(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// 忽略单个命名空间的错误,继续尝试下一个命名空间
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果所有命名空间都未找到对应的类型,抛出异常
|
||||||
|
throw new InvalidOperationException($"无法找到类型 {className} 或该类型不是 AIBase 的子类");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Client/Assets/Scripts/Utils/BehaviorTree.cs.meta
Normal file
3
Client/Assets/Scripts/Utils/BehaviorTree.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6b711456a12f4bf6a29b0de14a2d7d8f
|
||||||
|
timeCreated: 1754982046
|
@ -16,7 +16,7 @@
|
|||||||
</drawingOrder_down>
|
</drawingOrder_down>
|
||||||
</drawingOrder>
|
</drawingOrder>
|
||||||
<behaviorTree>
|
<behaviorTree>
|
||||||
<Node className="RandomWander"/>
|
<Node className="JobGiver_RandomWander"/>
|
||||||
</behaviorTree>
|
</behaviorTree>
|
||||||
</CharacterDef>
|
</CharacterDef>
|
||||||
|
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</drawingOrder_down>
|
</drawingOrder_down>
|
||||||
</drawingOrder>
|
</drawingOrder>
|
||||||
<behaviorTree>
|
<behaviorTree>
|
||||||
<Node className="RandomWander"/>
|
<Node className="JobGiver_RandomWander"/>
|
||||||
</behaviorTree>
|
</behaviorTree>
|
||||||
</CharacterDef>
|
</CharacterDef>
|
||||||
|
|
||||||
@ -51,13 +51,13 @@
|
|||||||
<affiliation>player</affiliation>
|
<affiliation>player</affiliation>
|
||||||
<drawingOrder>
|
<drawingOrder>
|
||||||
<texturePath>res:Character\HighSpeed</texturePath>
|
<texturePath>res:Character\HighSpeed</texturePath>
|
||||||
<pixelsPerUnit>100</pixelsPerUnit>
|
<pixelsPerUnit>200</pixelsPerUnit>
|
||||||
<drawingOrder_down>
|
<drawingOrder_down>
|
||||||
<node name="Body"/>
|
<node name="Body"/>
|
||||||
</drawingOrder_down>
|
</drawingOrder_down>
|
||||||
</drawingOrder>
|
</drawingOrder>
|
||||||
<behaviorTree>
|
<behaviorTree>
|
||||||
<Node className="Idel"/>
|
<Node className="JobGiver_Idel"/>
|
||||||
</behaviorTree>
|
</behaviorTree>
|
||||||
</CharacterDef>
|
</CharacterDef>
|
||||||
|
|
||||||
@ -72,13 +72,13 @@
|
|||||||
<affiliation>player</affiliation>
|
<affiliation>player</affiliation>
|
||||||
<drawingOrder>
|
<drawingOrder>
|
||||||
<texturePath>res:Character\HighSpeed</texturePath>
|
<texturePath>res:Character\HighSpeed</texturePath>
|
||||||
|
<pixelsPerUnit>200</pixelsPerUnit>
|
||||||
<drawingOrder_down>
|
<drawingOrder_down>
|
||||||
<node name="Body" />
|
<node name="Body" />
|
||||||
</drawingOrder_down>
|
</drawingOrder_down>
|
||||||
</drawingOrder>
|
</drawingOrder>
|
||||||
<behaviorTree>
|
<behaviorTree>
|
||||||
|
<Node className="JobGiver_Idel"/>
|
||||||
<Node className="Idel"/>
|
|
||||||
</behaviorTree>
|
</behaviorTree>
|
||||||
</CharacterDef>
|
</CharacterDef>
|
||||||
|
|
||||||
|
@ -6,20 +6,6 @@
|
|||||||
<label>测试鸡</label>
|
<label>测试鸡</label>
|
||||||
<aiController>embrace</aiController>
|
<aiController>embrace</aiController>
|
||||||
<!-- <weapon>Claw</weapon> -->
|
<!-- <weapon>Claw</weapon> -->
|
||||||
<behaviorTree>
|
|
||||||
<!-- 如果名字叫做cxk -->
|
|
||||||
<Node className="ConditionalAI" value="entity.name=='cxk'">
|
|
||||||
<!-- 顺序执行 -->
|
|
||||||
<Node className="SequentialAI">
|
|
||||||
<!-- 追踪玩家 -->
|
|
||||||
<Node className="TrackPlayer"/>
|
|
||||||
<!-- 随机闲逛 -->
|
|
||||||
<Node className="RandomWander"/>
|
|
||||||
</Node>
|
|
||||||
</Node>
|
|
||||||
<!-- 随机闲逛 -->
|
|
||||||
<Node className="RandomWander"/>
|
|
||||||
</behaviorTree>
|
|
||||||
</MonsterDef>
|
</MonsterDef>
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
%TAG !u! tag:unity3d.com,2011:
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
--- !u!78 &1
|
--- !u!78 &1
|
||||||
TagManager:
|
TagManager:
|
||||||
serializedVersion: 2
|
serializedVersion: 3
|
||||||
tags: []
|
tags: []
|
||||||
layers:
|
layers:
|
||||||
- Default
|
- Default
|
||||||
@ -11,7 +11,7 @@ TagManager:
|
|||||||
-
|
-
|
||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
-
|
- Entity
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
@ -50,27 +50,3 @@ TagManager:
|
|||||||
- Light Layer 5
|
- Light Layer 5
|
||||||
- Light Layer 6
|
- Light Layer 6
|
||||||
- Light Layer 7
|
- Light Layer 7
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-
|
|
||||||
|
Reference in New Issue
Block a user