(client) feat:实现右键菜单

This commit is contained in:
m0_75251201
2025-07-23 18:53:14 +08:00
parent 046ebe3cfe
commit ac278fba46
19 changed files with 1146 additions and 790 deletions

View File

@ -104,6 +104,7 @@ MonoBehaviour:
body: {fileID: 2838206730318674270}
outlineRenderer: {fileID: 3992139212329961548}
outlineCollider: {fileID: 478384147413774568}
entity: {fileID: 7300440714681954677}
--- !u!70 &478384147413774568
CapsuleCollider2D:
m_ObjectHideFlags: 0
@ -204,6 +205,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
direction: {x: 0, y: 0, z: 0}
body: {fileID: 2838206730318674270}
affiliation:
canSelect: 1
--- !u!1 &2838206730318674270
GameObject:
@ -314,7 +316,7 @@ SpriteRenderer:
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_Color: {r: 0.17278391, g: 0.7283019, b: 0.108558126, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0

View File

@ -0,0 +1,460 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4821822984522114009
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8974533068185241455}
- component: {fileID: 6098472552964198111}
- component: {fileID: 7844228932229707948}
- component: {fileID: 504677424079507256}
- component: {fileID: 8276716053524560457}
- component: {fileID: 1536012154932022711}
m_Layer: 5
m_Name: RightMenu
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8974533068185241455
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4821822984522114009}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 965650796640655482}
- {fileID: 3066961863796270965}
- {fileID: 524436111069263832}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 342, y: -198}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.1, y: 0.9}
--- !u!222 &6098472552964198111
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4821822984522114009}
m_CullTransparentMesh: 1
--- !u!114 &7844228932229707948
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4821822984522114009}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.392}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &504677424079507256
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4821822984522114009}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59f8146938fff824cb5fd77236b75775, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 0
m_Spacing: 0
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
m_ChildControlWidth: 0
m_ChildControlHeight: 0
m_ChildScaleWidth: 0
m_ChildScaleHeight: 0
m_ReverseArrangement: 0
--- !u!114 &8276716053524560457
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4821822984522114009}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3245ec927659c4140ac4f8d17403cc18, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 1
m_VerticalFit: 1
--- !u!114 &1536012154932022711
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4821822984522114009}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e45cfe2f36eb4f589b6d8f331567974d, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
menu: {fileID: 4821822984522114009}
buttonPrefab: {fileID: 3166707847097429176, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
--- !u!1001 &1166868423299745271
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 8974533068185241455}
m_Modifications:
- target: {fileID: 190104900697248908, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Name
value: Test
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_SizeDelta.x
value: 160
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_SizeDelta.y
value: 30
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5723833987058492246, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_text
value: "\u53D8\u6210\u7B28\u86CB"
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
--- !u!224 &524436111069263832 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
m_PrefabInstance: {fileID: 1166868423299745271}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1878011162534849109
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 8974533068185241455}
m_Modifications:
- target: {fileID: 190104900697248908, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Name
value: Control
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_SizeDelta.x
value: 160
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_SizeDelta.y
value: 30
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5723833987058492246, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_text
value: "\u64CD\u63A7"
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
--- !u!224 &965650796640655482 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
m_PrefabInstance: {fileID: 1878011162534849109}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &4460444807628739930
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 8974533068185241455}
m_Modifications:
- target: {fileID: 190104900697248908, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Name
value: Delete
objectReference: {fileID: 0}
- target: {fileID: 190104900697248908, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_SizeDelta.x
value: 160
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_SizeDelta.y
value: 30
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5723833987058492246, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
propertyPath: m_text
value: "\u5220\u9664"
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
--- !u!224 &3066961863796270965 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
m_PrefabInstance: {fileID: 4460444807628739930}
m_PrefabAsset: {fileID: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6a6b87c10209f534b926ee730079390c
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,53 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: animationTest
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves: []
m_PPtrCurves: []
m_SampleRate: 60
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings: []
pptrCurveMapping: []
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 1
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 1
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves: []
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8bdfdaa2024b283409a4d6a4095c02c9
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,72 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1102 &-5314867381662587561
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: animationTest
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 8bdfdaa2024b283409a4d6a4095c02c9, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1107 &-991703144119142111
AnimatorStateMachine:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: -5314867381662587561}
m_Position: {x: 200, y: 0, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 800, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: -5314867381662587561}
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: "\u52A8\u753B\u6D4B\u8BD5"
serializedVersion: 5
m_AnimatorParameters: []
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: -991703144119142111}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 42771044e260c3e48b00e50abb7e01e3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 9100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -257,6 +257,53 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 1690722858018107951, guid: f0afd08be12de0d43af753af4f618da4, type: 3}
m_PrefabInstance: {fileID: 39049902}
m_PrefabAsset: {fileID: 0}
--- !u!1 &164739120
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 164739122}
- component: {fileID: 164739121}
m_Layer: 0
m_Name: EntityManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &164739121
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 164739120}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa378b7511b04429b8b6b0efbcce825a, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
entityLevel: {fileID: 1891846098}
entityPrefab: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
--- !u!4 &164739122
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 164739120}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.54611, y: -0.12631, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &323725406
GameObject:
m_ObjectHideFlags: 0
@ -773,6 +820,7 @@ RectTransform:
- {fileID: 1892335252}
- {fileID: 2068504032}
- {fileID: 1401161120}
- {fileID: 2120445621}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@ -794,7 +842,7 @@ GameObject:
- component: {fileID: 1239746124}
m_Layer: 0
m_Name: Camera
m_TagString: Untagged
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@ -1141,7 +1189,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1891846100}
- component: {fileID: 1891846099}
m_Layer: 0
m_Name: EntityLevel
m_TagString: Untagged
@ -1149,20 +1196,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1891846099
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1891846098}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa378b7511b04429b8b6b0efbcce825a, type: 3}
m_Name:
m_EditorClassIdentifier:
entityLevel: {fileID: 1891846098}
entityPrefab: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
--- !u!4 &1891846100
Transform:
m_ObjectHideFlags: 0
@ -1233,6 +1266,11 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
actionButton: 112
--- !u!224 &2120445621 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
m_PrefabInstance: {fileID: 2673299386314699482}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &481559811017721991
PrefabInstance:
m_ObjectHideFlags: 0
@ -1418,6 +1456,151 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
--- !u!1001 &2673299386314699482
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1236970686}
m_Modifications:
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4821822984522114009, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_Name
value: RightMenu
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_Pivot.x
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_Pivot.y
value: 0.9
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 342
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.y
value: -198
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
@ -1427,3 +1610,4 @@ SceneRoots:
- {fileID: 1236970686}
- {fileID: 603423468}
- {fileID: 1891846100}
- {fileID: 164739122}

View File

@ -333,6 +333,60 @@ Transform:
- {fileID: 9462743}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &865935899
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 865935901}
- component: {fileID: 865935900}
m_Layer: 0
m_Name: "\u52A8\u753B\u6D4B\u8BD5"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!95 &865935900
Animator:
serializedVersion: 7
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 865935899}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 42771044e260c3e48b00e50abb7e01e3, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_AnimatePhysics: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!4 &865935901
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 865935899}
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: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1057087086
GameObject:
m_ObjectHideFlags: 0
@ -683,6 +737,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: aa378b7511b04429b8b6b0efbcce825a, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
entityLevel: {fileID: 309861628}
entityPrefab: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
--- !u!114 &2036983434
@ -752,3 +807,4 @@ SceneRoots:
- {fileID: 309861630}
- {fileID: 2036983432}
- {fileID: 1371068282}
- {fileID: 865935901}

View File

@ -29,6 +29,7 @@ namespace Data
public class DrawingOrderDef : Define
{
public List<DrawNodeDef> drawNodes = new();
public string texturePath;
public override bool Init(XElement xmlDef)
{
base.Init(xmlDef);
@ -43,7 +44,7 @@ namespace Data
drawNode.Init(node);
drawNodes.Add(drawNode);
}
texturePath= xmlDef.Element("texturePath")?.Value;
return true;;
}
// 重载 == 运算符

View File

@ -8,8 +8,6 @@ namespace Data
public class PawnDef : Define
{
public AttributesDef attributes;
public string aiController;
public string texturePath = null;
public DrawingOrderDef
drawingOrder_down,
drawingOrder_up,
@ -17,7 +15,7 @@ namespace Data
drawingOrder_right;
public BehaviorTreeDef behaviorTree;
public AffiliationDef affiliation;
public string affiliation;
public DrawingOrderDef GetDrawingOrder(Orientation orientation)

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using AI;
using Base;
@ -14,6 +15,7 @@ namespace Entity
public AttributesDef attributes;
public Vector3 direction;
public GameObject body;
public string affiliation;
public bool canSelect = true;
public bool IsChase { set; get; } = true;
@ -21,21 +23,34 @@ namespace Entity
{
set
{
if (!value)
if (value)
{
IsChase = true;
currentJob = null;
}
_isPlayerControlled = value;
}
get => _isPlayerControlled;
}
public bool IsDead => attributes.health <= 0;
private bool _isPlayerControlled = false;
private bool _warning = false;
public virtual void Init(PawnDef pawnDef)
{
attributes = pawnDef.attributes.Clone();
aiTree = ConvertToAIBase(pawnDef.behaviorTree);
affiliation=pawnDef.affiliation;
//定义的tag有限不用这个了
// if(!string.IsNullOrEmpty(affiliation))
// gameObject.CompareTag(affiliation);
}
public void Tick()
{
if (PlayerControlled)
if (_isPlayerControlled)
{
UpdatePlayerControls();
}
@ -72,9 +87,9 @@ namespace Entity
direction = (pos - transform.position).normalized;
}
public virtual void Kill(float delay = 0)
public virtual void Kill()
{
Destroy(gameObject,delay);
attributes.health = 0;
}
private void AutoBehave()
@ -99,42 +114,97 @@ namespace Entity
private void UpdatePlayerControls()
{
// 获取当前键盘输入状态
var inputDirection = new Vector3();
// 检测 Shift 键状态
var isHoldingShift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
IsChase = !isHoldingShift; // 按住 Shift 时 IsChase = false否则 true
// 获取当前键盘输入状态2D 移动,只使用 X 和 Y 轴)
var inputDirection = Vector2.zero;
// 检测 WASD 输入
// 检测 WASD 或方向键输入
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
inputDirection += Vector3.forward; // 向移动
inputDirection += Vector2.up; // 向移动Y 轴正方向)
}
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
{
inputDirection += Vector3.back; // 向移动
inputDirection += Vector2.down; // 向移动Y 轴负方向)
}
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
inputDirection += Vector3.left; // 向左移动
inputDirection += Vector2.left; // 向左移动X 轴负方向)
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
inputDirection += Vector3.right; // 向右移动
inputDirection += Vector2.right; // 向右移动X 轴正方向)
}
// 如果有输入方向,则设置目标位置并尝试移动
if (inputDirection != Vector3.zero)
if (inputDirection == Vector2.zero) return;
// 归一化方向向量,确保对角线移动速度一致
inputDirection = inputDirection.normalized;
// 设置目标位置2D 移动Z 轴保持不变)
var targetPosition = transform.position + new Vector3(inputDirection.x, inputDirection.y, 0);
// 调用 SetTarget 方法设置目标位置
SetTarget(targetPosition);
// 调用 TryMove 方法处理实际移动逻辑
TryMove();
}
public static AIBase ConvertToAIBase(BehaviorTreeDef behaviorTreeDef)
{
if (behaviorTreeDef == null)
return null;
var aiBase = CreateAIBaseInstance(behaviorTreeDef.className);
if (behaviorTreeDef.childTree != null)
{
// 归一化方向向量,确保对角线移动速度一致
inputDirection = inputDirection.normalized;
// 设置目标位置(假设当前位置为 transform.position
Vector3 targetPosition = transform.position + inputDirection;
// 调用 SetTarget 方法设置目标位置
SetTarget(targetPosition);
// 调用 TryMove 方法处理实际移动逻辑
TryMove();
foreach (var child in behaviorTreeDef.childTree)
{
if (child != null)
{
aiBase.children.Add(ConvertToAIBase(child));
}
}
}
return aiBase;
}
// 使用反射根据 className 创建具体的 AIBase 子类实例
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 的子类");
}
}
}

View File

@ -1,13 +1,20 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace Entity
{
public class Outline:MonoBehaviour
public class Outline : MonoBehaviour
{
public GameObject body;
public SpriteRenderer outlineRenderer;
public CapsuleCollider2D outlineCollider;
public Entity entity;
private bool _select = false;
public void Init()
{
var size = GetSize();
@ -15,15 +22,17 @@ namespace Entity
outlineCollider.direction = size.x > size.y ? CapsuleDirection2D.Horizontal : CapsuleDirection2D.Vertical;
outlineCollider.size = size;
}
public void Show()
{
outlineRenderer.gameObject.SetActive(true);
outlineRenderer.enabled = true;
}
public void Hide()
{
outlineRenderer.gameObject.SetActive(false);
outlineRenderer.enabled = false;
}
/// <summary>
/// 获取指定对象及其所有子对象组成的图像的大小。
/// </summary>
@ -37,15 +46,52 @@ namespace Entity
if (renderers.Length == 0)
{
return new(-1,-1);
return new(-1, -1);
}
var totalBounds = renderers[0].bounds;
for (var i = 1; i < renderers.Length; i++)
{
totalBounds.Encapsulate(renderers[i].bounds);
}
var size = totalBounds.size;
return size;
}
private void OnMouseEnter()
{
Show();
_select = true;
}
private void OnMouseExit()
{
Hide();
_select = false;
}
private void OnMouseOver()
{
// 检测是否按下的是鼠标右键
if (Input.GetMouseButtonDown(1)) // 鼠标右键对应的是按钮索引 1
{
var rightMenu = Prefab.RightMenuPrefab.Instance;
rightMenu.Init(GetMenu());
rightMenu.transform.position=Input.mousePosition;
rightMenu.Show();
}
}
private List<(string name, UnityAction callback)> GetMenu()
{
var result = new List<(string name, UnityAction callback)>();
if(entity.PlayerControlled)
result.Add(("结束操控",()=>entity.PlayerControlled=false));
else
result.Add(("手动操控",()=>entity.PlayerControlled=true));
result.Add(("杀死",()=>entity.Kill()));
return result;
}
}
}

View File

@ -1,30 +1,46 @@
using System.Collections.Generic;
using System.Linq;
using Base;
using Prefab;
using UnityEngine;
namespace Managers
{
public class EntityManage:Utils.MonoSingleton<EntityManage>
public class EntityManage:Utils.MonoSingleton<EntityManage>,ITick
{
public Dictionary<string, List<EntityPrefab>> factionEntities = new();
public GameObject entityLevel;
public EntityPrefab entityPrefab;
void Update()
{
// 检测鼠标左键是否按下
if (Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition); // 获取从相机发出的射线
if (Physics.Raycast(ray, out var hit)) // 检测射线是否击中物体
public void Tick()
{
foreach (var faction in factionEntities)
{
List<EntityPrefab> entitiesToRemove = new List<EntityPrefab>();
foreach (var entityPrefab in faction.Value)
{
Debug.Log("点击了物体: " + hit.collider.gameObject.name);
if (entityPrefab.entity.IsDead)
{
entitiesToRemove.Add(entityPrefab);
}
else
{
ITick itike = entityPrefab.entity;
itike.Tick();
}
}
// 删除所有标记为死亡的实体
foreach (var entityToRemove in entitiesToRemove)
{
faction.Value.Remove(entityToRemove);
Destroy(entityToRemove.gameObject);
}
}
}
/// <summary>
/// 根据给定的PawnDef生成一个实体对象。
/// </summary>
@ -75,8 +91,6 @@ namespace Managers
factionEntities[factionKey] = new List<EntityPrefab>();
}
factionEntities[factionKey].Add(entityComponent);
Base.Clock.AddTick(entity.GetComponent<Entity.Entity>());
}
catch (System.Exception ex)
{

View File

@ -16,66 +16,13 @@ namespace Prefab
public void Init(Data.PawnDef pawnDef)
{
entity.attributes = pawnDef.attributes.Clone();
entity.aiTree = ConvertToAIBase(pawnDef.behaviorTree);
entity.Init(pawnDef);
outline.Init();
outline.Hide();
}
public static AIBase ConvertToAIBase(BehaviorTreeDef behaviorTreeDef)
{
if (behaviorTreeDef == null)
return null;
AIBase aiBase = CreateAIBaseInstance(behaviorTreeDef.className);
if (behaviorTreeDef.childTree != null)
{
foreach (var child in behaviorTreeDef.childTree)
{
if (child != null)
{
aiBase.children.Add(ConvertToAIBase(child));
}
}
}
return aiBase;
}
// 使用反射根据 className 创建具体的 AIBase 子类实例
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 的子类");
}
}
}

View File

@ -0,0 +1,89 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace Prefab
{
public class RightMenuPrefab: Utils.MonoSingleton<RightMenuPrefab>,IPointerExitHandler
{
public GameObject menu;
public ButtonPrefab buttonPrefab;
public void Show()
{
gameObject.SetActive(true);
}
public void Hide()
{
gameObject.SetActive(false);
}
public void Init(List<(string name, UnityAction callback)> buttons)
{
if (menu == null || buttonPrefab == null)
{
Debug.LogError("Menu or ButtonPrefab is not assigned!");
return;
}
ClearMenu();
foreach (var (label, callback) in buttons)
{
// 实例化按钮预制体
var instantiatedButton = Instantiate(buttonPrefab.gameObject, menu.transform);
var buttonInstance = instantiatedButton.GetComponent<ButtonPrefab>();
if (buttonInstance != null)
{
// 设置按钮文本
buttonInstance.Label = label;
// 创建一个新的回调函数,包含原始回调和隐藏菜单的操作
UnityAction wrappedCallback = () =>
{
try
{
// 执行原始回调
callback?.Invoke();
}
catch (System.Exception e)
{
Debug.LogError($"Error executing callback for button '{label}': {e.Message}");
}
finally
{
// 隐藏菜单
Hide();
}
};
// 添加包装后的回调
buttonInstance.AddListener(wrappedCallback);
}
else
{
Debug.LogError("Failed to get ButtonPrefab component from instantiated object!");
}
}
}
public void ClearMenu()
{
// 遍历菜单下的所有子对象并销毁它们
foreach (Transform child in menu.transform)
{
Destroy(child.gameObject);
}
}
protected override void OnStart()
{
Hide();
}
public void OnPointerExit(PointerEventData eventData)
{
Hide();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e45cfe2f36eb4f589b6d8f331567974d
timeCreated: 1753196238

File diff suppressed because one or more lines are too long

View File

@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Define>
<AffiliationDef>
<defName>playerAffiliation</defName>
<label>player</label>
</AffiliationDef>
<AttributesDef>
<defName>TestCharacter</defName>
<health>100</health>
@ -15,9 +10,11 @@
<CharacterDef>
<defName>testPawn</defName>
<label>测试小人</label>
<description>用于测试功能的角色</description>
<attributes>TestCharacter</attributes>
<affiliation>playerAffiliation</affiliation>
<affiliation>player</affiliation>
<drawingOrder_down>
<texturePath>Resources/Character/CatGirl</texturePath>
<DrawNodeDef name="body"/>
</drawingOrder_down>
<behaviorTree>