(client) feat:右键菜单全局与UI分离,Building生成支持,双层地图重写

This commit is contained in:
m0_75251201
2025-08-11 12:45:52 +08:00
parent 670f778eee
commit 9922f06990
30 changed files with 1060 additions and 1986 deletions

View File

@ -0,0 +1,99 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &7193170239846001519
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalPosition.x
value: -9.026831
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalPosition.y
value: -0.9454966
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: m_Name
value: BuildingPrefab Variant
objectReference: {fileID: 0}
- target: {fileID: 1550000129210799929, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: entity
value:
objectReference: {fileID: 2985213147343140216}
- target: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
propertyPath: entity
value:
objectReference: {fileID: 2985213147343140216}
m_RemovedComponents:
- {fileID: 7300440714681954677, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
insertIndex: 2
addedObject: {fileID: 2985213147343140216}
m_SourcePrefab: {fileID: 100100000, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
--- !u!1 &4949477718940635697 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2838206730318674270, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
m_PrefabInstance: {fileID: 7193170239846001519}
m_PrefabAsset: {fileID: 0}
--- !u!1 &8035315966857772658 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 887327274103887133, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
m_PrefabInstance: {fileID: 7193170239846001519}
m_PrefabAsset: {fileID: 0}
--- !u!114 &2985213147343140216
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8035315966857772658}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2ea66d65f9414d18988cbdc1a322e334, type: 3}
m_Name:
m_EditorClassIdentifier:
animatorPrefab: {fileID: 2113064398104960506, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
imagePrefab: {fileID: 1922746734790246249, guid: a6657f26d735fab4690c8185980fda29, type: 3}
direction: {x: 0, y: 0, z: 0}
body: {fileID: 4949477718940635697}
affiliation:
canSelect: 1

View File

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

View File

@ -119,6 +119,139 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &111982856
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 111982858}
- component: {fileID: 111982857}
m_Layer: 0
m_Name: SelectRect
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!212 &111982857
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 111982856}
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: 21300000, guid: 811d3d3bfa653494784ee8ed56956471, 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!4 &111982858
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 111982856}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 2, y: 2, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &143894350
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 143894352}
- component: {fileID: 143894351}
m_Layer: 0
m_Name: rightMenu
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &143894351
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 143894350}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7f6fd5ff82ab4ce4aae8dd41118277f8, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
rightMenuPrefab: {fileID: 2120445622}
--- !u!4 &143894352
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 143894350}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2.57229, y: 0.67653, 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 &164739120
GameObject:
m_ObjectHideFlags: 0
@ -151,6 +284,8 @@ MonoBehaviour:
isGlobal: 1
entityLevel: {fileID: 1891846098}
entityPrefab: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
buildingLevel: {fileID: 651025902}
buildingPrefab: {fileID: 5615006624229444611, guid: d7b9277d8e6ac4541800044bdb0da063, type: 3}
defaultEntityPrefab: {fileID: 7975757421877276383, guid: 89661daa5f100c64783f0ad9cd37a7ff, type: 3}
--- !u!4 &164739122
Transform:
@ -161,7 +296,7 @@ Transform:
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_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -318,6 +453,37 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
--- !u!1 &651025902
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 651025903}
m_Layer: 0
m_Name: BuildingLevel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &651025903
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 651025902}
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: 1423222968}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!224 &689345800 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 2322698135530781468, guid: afbed11ea0c7e944aa36a71951b00ad6, type: 3}
@ -354,7 +520,6 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1084213391}
- {fileID: 1404524260}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &741561708
@ -369,8 +534,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 81339b242c794b8d9d28d7111a46bfbf, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
baseLevel: {fileID: 1084213392}
buildLevel: {fileID: 2005635200}
buildLevel: {fileID: 0}
plantLevel: {fileID: 0}
--- !u!1 &828003921
GameObject:
@ -383,6 +549,7 @@ GameObject:
- component: {fileID: 828003922}
- component: {fileID: 828003924}
- component: {fileID: 828003923}
- component: {fileID: 828003925}
m_Layer: 0
m_Name: Tilemap
m_TagString: Untagged
@ -495,6 +662,44 @@ Tilemap:
e31: 0
e32: 0
e33: 1
--- !u!19719996 &828003925
TilemapCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 828003921}
m_Enabled: 1
serializedVersion: 3
m_Density: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_ForceSendLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ForceReceiveLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ContactCaptureLayers:
serializedVersion: 2
m_Bits: 4294967295
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_UsedByEffector: 0
m_CompositeOperation: 0
m_CompositeOrder: 0
m_Offset: {x: 0, y: 0}
m_MaximumTileChangeCount: 1000
m_ExtrusionFactor: 0
m_UseDelaunayMesh: 0
--- !u!1 &1084213390
GameObject:
m_ObjectHideFlags: 0
@ -805,7 +1010,7 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 1633840166558733415, guid: 97884168f61531647ba02870b2e2160f, type: 3}
m_PrefabInstance: {fileID: 561707863834017811}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1404524259
--- !u!1 &1423222967
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -813,43 +1018,31 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1404524260}
- component: {fileID: 1404524261}
- component: {fileID: 1423222968}
m_Layer: 0
m_Name: Building
m_Name: Entity
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1404524260
--- !u!4 &1423222968
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1404524259}
m_GameObject: {fileID: 1423222967}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -1}
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: 2005635202}
m_Father: {fileID: 741561707}
- {fileID: 1891846100}
- {fileID: 651025903}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!156049354 &1404524261
Grid:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1404524259}
m_Enabled: 1
m_CellSize: {x: 1, y: 1, z: 0}
m_CellGap: {x: 0, y: 0, z: 0}
m_CellLayout: 0
m_CellSwizzle: 0
--- !u!1 &1468918169
GameObject:
m_ObjectHideFlags: 0
@ -935,141 +1128,18 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1891846098}
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_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_Father: {fileID: 1423222968}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!224 &1892335252 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 4227482396833377269, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
m_PrefabInstance: {fileID: 481559811017721991}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2005635199
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2005635202}
- component: {fileID: 2005635200}
- component: {fileID: 2005635201}
m_Layer: 0
m_Name: Tilemap
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1839735485 &2005635200
Tilemap:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2005635199}
m_Enabled: 1
m_Tiles: {}
m_AnimatedTiles: {}
m_TileAssetArray: []
m_TileSpriteArray: []
m_TileMatrixArray: []
m_TileColorArray: []
m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Origin: {x: 0, y: 0, z: 0}
m_Size: {x: 0, y: 0, z: 1}
m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
m_TileOrientation: 0
m_TileOrientationMatrix:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
--- !u!483693784 &2005635201
TilemapRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2005635199}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
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_ChunkSize: {x: 32, y: 32, z: 32}
m_ChunkCullingBounds: {x: 0, y: 0, z: 0}
m_MaxChunkCount: 16
m_MaxFrameAge: 16
m_SortOrder: 0
m_Mode: 0
m_DetectChunkCullingBounds: 0
m_MaskInteraction: 0
--- !u!4 &2005635202
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2005635199}
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: 1404524260}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!224 &2068504032 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 6806539210387795853, guid: 620f2670398686943a232c5a71a6f1d5, type: 3}
@ -1080,6 +1150,17 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
m_PrefabInstance: {fileID: 2673299386314699482}
m_PrefabAsset: {fileID: 0}
--- !u!114 &2120445622 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1536012154932022711, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
m_PrefabInstance: {fileID: 2673299386314699482}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e45cfe2f36eb4f589b6d8f331567974d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &481559811017721991
PrefabInstance:
m_ObjectHideFlags: 0
@ -1120,6 +1201,22 @@ PrefabInstance:
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2938422591565110871, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
propertyPath: m_Spacing.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2938422591565110871, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
propertyPath: m_Padding.m_Top
value: 5
objectReference: {fileID: 0}
- target: {fileID: 2938422591565110871, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
propertyPath: m_ChildAlignment
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3070964228632539618, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
propertyPath: m_SizeDelta.y
value: 4
objectReference: {fileID: 0}
- target: {fileID: 4028021113825693505, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
@ -1376,51 +1473,51 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
value: 80
objectReference: {fileID: 0}
- target: {fileID: 524436111069263832, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
value: -75
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
value: 80
objectReference: {fileID: 0}
- target: {fileID: 965650796640655482, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
value: -15
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
value: 80
objectReference: {fileID: 0}
- target: {fileID: 3066961863796270965, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
value: -45
objectReference: {fileID: 0}
- target: {fileID: 4821822984522114009, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_Name
@ -1428,7 +1525,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4821822984522114009, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_Pivot.x
@ -1456,11 +1553,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_SizeDelta.x
value: 0
value: 160
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_SizeDelta.y
value: 0
value: 90
objectReference: {fileID: 0}
- target: {fileID: 8974533068185241455, guid: 6a6b87c10209f534b926ee730079390c, type: 3}
propertyPath: m_LocalPosition.x
@ -1781,6 +1878,10 @@ PrefabInstance:
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7402578691222625163, guid: 1b140ccde6242874785fb30e18322eab, type: 3}
propertyPath: focusBox
value:
objectReference: {fileID: 111982856}
- target: {fileID: 8654739876786722101, guid: 1b140ccde6242874785fb30e18322eab, type: 3}
propertyPath: m_Pivot.x
value: 0.5
@ -1875,5 +1976,7 @@ SceneRoots:
- {fileID: 741561707}
- {fileID: 1236970686}
- {fileID: 603423468}
- {fileID: 1891846100}
- {fileID: 164739122}
- {fileID: 1423222968}
- {fileID: 111982858}
- {fileID: 143894352}

View File

@ -0,0 +1,31 @@
using System.Collections.Generic;
using Prefab;
using UnityEngine;
using UnityEngine.Events;
namespace Base
{
public class RightMenu : Utils.MonoSingleton<RightMenu>
{
public RightMenuPrefab rightMenuPrefab;
public void Show()
{
rightMenuPrefab.Show();
}
public void Hide()
{
rightMenuPrefab.Hide();
}
public void Init(List<(string name, UnityAction callback)> buttons)
{
rightMenuPrefab.Init(buttons);
}
protected override void OnStart()
{
Hide();
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7f6fd5ff82ab4ce4aae8dd41118277f8

View File

@ -1,7 +1,7 @@
namespace Data
{
public class BuildingDef:PawnDef
public class BuildingDef : PawnDef
{
public bool IsBlocked = true;
public float slowDown = 0f;
}
}

View File

@ -0,0 +1,36 @@
using Base;
using Data;
using UnityEngine;
namespace Entity
{
public class Building:Entity
{
public override void SetTarget(Vector3 pos)
{
}
protected override void UpdatePlayerControls()
{
if (Input.GetKeyDown(KeyCode.W))
{
transform.position += Vector3.up;
}
if (Input.GetKeyDown(KeyCode.A))
{
transform.position += Vector3.left;
}
if (Input.GetKeyDown(KeyCode.S))
{
transform.position += Vector3.down;
}
if (Input.GetKeyDown(KeyCode.D))
{
transform.position += Vector3.right;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2ea66d65f9414d18988cbdc1a322e334
timeCreated: 1754650409

View File

@ -1,10 +0,0 @@
namespace Entity
{
public class BuildingBase:Entity
{
public override void TryMove()
{
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: eb881a08fe004eb4ab0a6fa9d5d86d33
timeCreated: 1753100586

View File

@ -1,12 +0,0 @@
using Data;
namespace Entity
{
public class BuildingEntity:Entity
{
void Init(BuildingDef def)
{
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 703125e2813a463d9b714841a3f9995f
timeCreated: 1753702932

View File

@ -214,7 +214,7 @@ namespace Entity
currentJob.Update();
}
private void UpdatePlayerControls()
protected virtual void UpdatePlayerControls()
{
// 检测 Shift 键状态
var isHoldingShift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

View File

@ -90,7 +90,7 @@ namespace Entity
// 检测是否按下的是鼠标右键
if (Input.GetMouseButtonDown(1)) // 鼠标右键对应的是按钮索引 1
{
var rightMenu = Prefab.RightMenuPrefab.Instance;
var rightMenu = Base.RightMenu.Instance;
rightMenu.Init(GetMenu());
rightMenu.transform.position = Input.mousePosition;
rightMenu.Show();

View File

@ -13,6 +13,8 @@ namespace Managers
public GameObject entityLevel;
public EntityPrefab entityPrefab;
public GameObject buildingLevel;
public EntityPrefab buildingPrefab;
public EntityPrefab defaultEntityPrefab;
public List<EntityPrefab> FindEntitiesByFaction(string factionKey)
@ -63,7 +65,7 @@ namespace Managers
public void GenerateEntity(Data.PawnDef pawnDef, Vector3 pos)
{
// 检查 entityPrefab 是否为空
if (entityPrefab == null)
if (!entityPrefab)
{
Debug.LogError("Error: entityPrefab is null. Please assign a valid prefab.");
GenerateDefaultEntity(pos);
@ -89,7 +91,7 @@ namespace Managers
var entityComponent = instantiatedEntity.GetComponent<EntityPrefab>();
// 检查 EntityPrefab 组件是否存在
if (entityComponent == null)
if (!entityComponent)
{
throw new InvalidOperationException($"Error: EntityPrefab component not found on the instantiated object: {instantiatedEntity.name}");
}
@ -108,7 +110,7 @@ namespace Managers
catch (System.Exception ex)
{
// 如果有已实例化的对象,则销毁它
if (instantiatedEntity != null)
if (instantiatedEntity)
{
Destroy(instantiatedEntity); // 删除已创建的对象
}
@ -121,6 +123,67 @@ namespace Managers
}
}
public void GenerateBuildingEntity(Data.BuildingDef buildingDef, Vector3Int pos)
{
// 检查 entityPrefab 是否为空
if (!entityPrefab)
{
Debug.LogError("Error: entityPrefab is null. Please assign a valid prefab.");
GenerateDefaultEntity(pos);
return;
}
// 检查 pawnDef 是否为空
if (buildingDef == null)
{
Debug.LogError("Error: PawnDef is null. Cannot generate entity without a valid PawnDef.");
GenerateDefaultEntity(pos);
return;
}
GameObject instantiatedEntity = null; // 用于跟踪已实例化的对象
try
{
// 实例化实体对象
instantiatedEntity = Instantiate(buildingPrefab.gameObject, pos, Quaternion.identity, buildingLevel.transform);
// 获取 EntityPrefab 组件
var entityComponent = instantiatedEntity.GetComponent<EntityPrefab>();
// 检查 EntityPrefab 组件是否存在
if (!entityComponent)
{
throw new InvalidOperationException($"Error: EntityPrefab component not found on the instantiated object: {instantiatedEntity.name}");
}
// 初始化实体组件
entityComponent.Init(buildingDef);
// 确保派系键存在,并初始化对应的列表
var factionKey = buildingDef.attributes.label ?? "default"; // 使用 null 合并运算符简化代码
if (!factionEntities.ContainsKey(factionKey))
{
factionEntities[factionKey] = new List<EntityPrefab>();
}
factionEntities[factionKey].Add(entityComponent);
}
catch (System.Exception ex)
{
// 如果有已实例化的对象,则销毁它
if (instantiatedEntity)
{
Destroy(instantiatedEntity); // 删除已创建的对象
}
// 捕获并记录任何异常
Debug.LogError($"An error occurred while generating the entity: {ex.Message}\nStack Trace: {ex.StackTrace}");
// 调用默认生成方法
GenerateDefaultEntity(pos);
}
}
public void GenerateDefaultEntity(Vector3 pos)
{
var entity = Instantiate(defaultEntityPrefab.gameObject, pos, Quaternion.identity, entityLevel.transform);

View File

@ -5,30 +5,57 @@ using UnityEngine.Tilemaps;
namespace Managers
{
public class TileManager:Utils.Singleton<TileManager>
/// <summary>
/// 瓦片管理器,用于加载、初始化和管理瓦片资源。
/// </summary>
public class TileManager : Utils.Singleton<TileManager>
{
public Dictionary<string,TileBase> tileBaseMapping = new();
/// <summary>
/// 存储瓦片名称与瓦片对象的映射关系。
/// </summary>
public Dictionary<string, TileBase> tileBaseMapping = new();
/// <summary>
/// 存储瓦片索引与瓦片对象的映射关系。
/// 索引由四个整数组成,表示瓦片的组合方式。
/// </summary>
public Dictionary<(int, int, int, int), TileBase> tileToTileBaseMapping = new();
/// <summary>
/// 存储瓦片名称与唯一 ID 的映射关系。
/// </summary>
public Dictionary<string, int> tileID = new();
/// <summary>
/// 初始化瓦片管理器。
/// 加载所有瓦片定义、纹理映射表,并生成对应的瓦片对象。
/// </summary>
public void Init()
{
if (tileToTileBaseMapping.Count > 0)
return;
// 初始化图像包管理器
Managers.PackagesImageManager.Instance.Init();
var imagePack = Managers.PackagesImageManager.Instance;
// 获取所有瓦片定义
var tileType = Managers.DefineManager.Instance.QueryDefinesByType<TileDef>();
for (var i = 0; i < tileType.Length; i++)
{
tileID.Add(tileType[i].name, i);
}
var tileTextureMappingDef=Managers.DefineManager.Instance.QueryDefinesByType<TileMappingTableDef>();
// 处理瓦片纹理映射表定义
var tileTextureMappingDef = Managers.DefineManager.Instance.QueryDefinesByType<TileMappingTableDef>();
foreach (var mappingTableDef in tileTextureMappingDef)
{
foreach (var keyVal in mappingTableDef.tileDict)
{
var key = keyVal.Key;
var val = keyVal.Value;
// 检查键值格式是否合法
var parts = key.Split('_');
if (parts.Length != 4)
{
@ -37,6 +64,7 @@ namespace Managers
continue;
}
// 检查键值中是否存在未定义的瓦片名称
if (!(tileID.TryGetValue(parts[0], out var k1) &&
tileID.TryGetValue(parts[1], out var k2) &&
tileID.TryGetValue(parts[2], out var k3) &&
@ -47,7 +75,8 @@ namespace Managers
continue;
}
var sprite = imagePack.GetSprite(mappingTableDef.packID,val);
// 获取对应精灵
var sprite = imagePack.GetSprite(mappingTableDef.packID, val);
if (sprite == null)
{
var packName = Managers.DefineManager.Instance.GetDefinePackageName(mappingTableDef);
@ -55,6 +84,7 @@ namespace Managers
continue;
}
// 检查是否存在重复索引
if (tileToTileBaseMapping.ContainsKey((k1, k2, k3, k4)))
{
var packName = Managers.DefineManager.Instance.GetDefinePackageName(mappingTableDef);
@ -62,6 +92,7 @@ namespace Managers
continue;
}
// 加载瓦片并存储到映射表中
var tile = LoadTile(sprite);
tileToTileBaseMapping[(k1, k2, k3, k4)] = tile;
tileBaseMapping[val] = tile;
@ -69,18 +100,28 @@ namespace Managers
}
}
/// <summary>
/// 重新加载瓦片管理器。
/// 清空当前的瓦片映射表并重新初始化。
/// </summary>
public void Reload()
{
tileToTileBaseMapping.Clear();
Init();
}
public TileBase LoadTile(Sprite sprite)
/// <summary>
/// 将精灵加载为瓦片对象。
/// </summary>
/// <param name="sprite">要加载的精灵。</param>
/// <param name="colliderType">瓦片的碰撞体类型,默认为 None。</param>
/// <returns>返回加载成功的瓦片对象。</returns>
public TileBase LoadTile(Sprite sprite, Tile.ColliderType colliderType = Tile.ColliderType.None)
{
var newTile = ScriptableObject.CreateInstance<Tile>();
newTile.sprite = sprite;
newTile.color = Color.white;
newTile.colliderType = Tile.ColliderType.Sprite;
newTile.color = Color.white;
newTile.colliderType = colliderType;
return newTile;
}
}

View File

@ -9,103 +9,155 @@ namespace Map
{
public class DoubleMap : MonoBehaviour
{
public List<List<int>> mapData = new();
public List<List<int>> mapData = new List<List<int>>();
public Tilemap textureLevel;
public Dictionary<string, TileBase> tileDict = new();
private int offsetX = 0; // 地图数据的 X 偏移量
private int offsetY = 0; // 地图数据的 Y 偏移量
void Start()
public Vector2Int dataOffset = Vector2Int.zero; // 数据起始点偏移变量
// 初始化地图数据大小
public void InitializeData(int width, int height, int defaultValue = 0)
{
mapData.Clear();
for (int x = 0; x < width; x++)
{
List<int> column = new List<int>();
for (int y = 0; y < height; y++)
{
column.Add(defaultValue);
}
mapData.Add(column);
}
}
// 设置指定数据坐标的瓦片值并刷新相关瓦片
public void SetTile(int dataX, int dataY, int value)
{
// 检查坐标是否有效
if (dataX < 0 || dataY < 0 || dataX >= mapData.Count || dataY >= mapData[0].Count)
{
Debug.LogError($"SetTile: 坐标({dataX},{dataY})超出范围");
return;
}
// 更新数据
mapData[dataX][dataY] = value;
UpdateTexture();
// 刷新受影响的瓦片(当前点作为四个角影响的瓦片)
RefreshTile(dataX, dataY);
}
public void UpdateTexture()
// 获取指定数据坐标的瓦片值
public int GetTile(int dataX, int dataY)
{
for (int i = 0; i < mapData.Count; i++)
if (dataX < 0 || dataY < 0 || dataX >= mapData.Count || dataY >= mapData[0].Count)
{
for (int j = 0; j < mapData[i].Count; j++)
Debug.LogError($"GetTile: 坐标({dataX},{dataY})超出范围");
return -1;
}
return mapData[dataX][dataY];
}
// 刷新指定数据点影响的瓦片
public void RefreshTile(int dataX, int dataY)
{
// 计算该数据点影响的四个瓦片位置(该点作为四个角)
Vector2Int[] affectedTiles = new Vector2Int[]
{
new Vector2Int(dataX - 1, dataY - 1), // 作为右下角
new Vector2Int(dataX - 1, dataY), // 作为右上角
new Vector2Int(dataX, dataY - 1), // 作为左下角
new Vector2Int(dataX, dataY) // 作为左上角
};
foreach (var tilePos in affectedTiles)
{
UpdateTileAtTilemapPosition(tilePos.x, tilePos.y);
}
}
// 刷新整个瓦片地图
public void RefreshAllTiles()
{
if (mapData.Count == 0 || mapData[0].Count == 0) return;
// 计算瓦片地图的有效范围(考虑偏移)
int startX = dataOffset.x;
int startY = dataOffset.y;
int endX = startX + mapData.Count - 1;
int endY = startY + mapData[0].Count - 1;
// 遍历所有瓦片位置
for (int x = startX; x <= endX; x++)
{
for (int y = startY; y <= endY; y++)
{
UpdateTexture(i, j);
UpdateTileAtTilemapPosition(x, y);
}
}
}
public int GetTile(int x, int y)
// 更新指定瓦片位置的显示
private void UpdateTileAtTilemapPosition(int tileX, int tileY)
{
// 转换为相对于 mapData 的索引
int relativeX = x - offsetX;
int relativeY = y - offsetY;
// 计算对应的数据坐标(考虑偏移)
int dataX = tileX - dataOffset.x;
int dataY = tileY - dataOffset.y;
if (relativeX < 0 || relativeX >= mapData.Count)
{
return 0;
}
// 获取四个角的数据坐标
int topLeftX = dataX;
int topLeftY = dataY;
int topRightX = dataX + 1;
int topRightY = dataY;
int bottomLeftX = dataX;
int bottomLeftY = dataY + 1;
int bottomRightX = dataX + 1;
int bottomRightY = dataY + 1;
var col = mapData[relativeX];
if (relativeY < 0 || relativeY >= mapData.Count)
{
return 0;
}
// 检查边界并获取值
int topLeft = GetDataValue(topLeftX, topLeftY);
int topRight = GetDataValue(topRightX, topRightY);
int bottomLeft = GetDataValue(bottomLeftX, bottomLeftY);
int bottomRight = GetDataValue(bottomRightX, bottomRightY);
return col[relativeY];
// 获取对应的瓦片
TileBase tile = GetTileFromManager(topLeft, topRight, bottomLeft, bottomRight);
// 设置到瓦片地图
Vector3Int position = new Vector3Int(tileX, tileY, 0);
textureLevel.SetTile(position, tile);
}
public void SetTile(int x, int y, string tileName)
// 安全获取数据值(处理边界)
private int GetDataValue(int dataX, int dataY)
{
SetTile(x, y, TileManager.Instance.tileID.GetValueOrDefault(tileName));
if (dataX < 0 || dataY < 0 || dataX >= mapData.Count || dataY >= mapData[0].Count)
return 0; // 边界外返回默认值
return mapData[dataX][dataY];
}
public void SetTile(int x, int y, int id)
// 从TileManager获取对应瓦片
private TileBase GetTileFromManager(int topLeft, int topRight, int bottomLeft, int bottomRight)
{
// 转换为相对于 mapData 的索引
int relativeX = x - offsetX;
int relativeY = y - offsetY;
if (relativeX >= 0 && relativeX < mapData.Count &&
relativeY >= 0 && relativeY < mapData[relativeX].Count)
TileManager manager = TileManager.Instance;
if (manager == null)
{
mapData[relativeX][relativeY] = id;
UpdateTexture(x, y);
UpdateTexture(x, y - 1);
UpdateTexture(x - 1, y);
UpdateTexture(x - 1, y - 1);
}
}
/// <summary>
/// 更新对应坐标的贴图
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public void UpdateTexture(int x, int y)
{
// 转换为相对于 mapData 的索引
int relativeX = x - offsetX;
int relativeY = y - offsetY;
if (relativeX < 0 || relativeX >= mapData.Count ||
relativeY < 0 || relativeY >= mapData[relativeX].Count)
{
return; // 如果超出范围,直接返回
Debug.LogError("TileManager实例未找到");
return null;
}
var lt = GetTile(x, y + 1);
var rt = GetTile(x + 1, y + 1);
var lb = GetTile(x, y);
var rb = GetTile(x + 1, y);
if (TileManager.Instance.tileToTileBaseMapping.ContainsKey((lt, rt, lb, rb)))
// 尝试获取组合键对应的瓦片
var key = (topLeft, topRight, bottomLeft, bottomRight);
if (manager.tileToTileBaseMapping.TryGetValue(key, out TileBase tile))
{
textureLevel.SetTile(new Vector3Int(x, y, 0),
TileManager.Instance.tileToTileBaseMapping[(lt, rt, lb, rb)]);
return tile;
}
// 备用方案:尝试获取默认瓦片
if (manager.tileBaseMapping.TryGetValue("Default", out TileBase defaultTile))
{
return defaultTile;
}
Debug.LogError($"未找到对应瓦片: {key}");
return null;
}
}
}

View File

@ -4,7 +4,7 @@ using UnityEngine.Tilemaps;
namespace Map
{
public class MapGenerator:MonoBehaviour
public class MapGenerator:Utils.MonoSingleton<MapGenerator>
{
public DoubleMap baseLevel;
public Tilemap buildLevel;
@ -14,17 +14,22 @@ namespace Map
{
var perline= Utils.PerlinNoise.Instance;
int size = 100;
for (int i = -size; i <= size; i++)
{
for (int j = -size; j <= size; j++)
{
var val = perline.Noise(i, j);
if (val < 0)
{
}
}
}
baseLevel.InitializeData(size, size);
baseLevel.RefreshAllTiles();
}
public bool CanPassThrough(int x, int y)
{
return GetTileCost(x, y) < 1;
}
public float GetTileCost(int x, int y)
{
return 0;
}
protected override void OnStart()
{
}
}
}

View File

@ -5,7 +5,7 @@ using UnityEngine.EventSystems;
namespace Prefab
{
public class RightMenuPrefab: Utils.MonoSingleton<RightMenuPrefab>,IPointerExitHandler
public class RightMenuPrefab: MonoBehaviour,IPointerExitHandler
{
public GameObject menu;
public ButtonPrefab buttonPrefab;
@ -76,11 +76,6 @@ namespace Prefab
Destroy(child.gameObject);
}
}
protected override void OnStart()
{
Hide();
}
public void OnPointerExit(PointerEventData eventData)
{
Hide();

View File

@ -8,6 +8,7 @@ public class Program : MonoBehaviour
UnityLogger.Init();
Managers.DefineManager.Instance.Init();
Managers.PackagesImageManager.Instance.Init();
Managers.TileManager.Instance.Init();
}
private void Start()

View File

@ -25,6 +25,7 @@ namespace UI
InitEvent();
InitCharacter();
InitMonster();
InitBuilding();
}
@ -32,6 +33,10 @@ namespace UI
{
var title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "事件菜单";
title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "未定义任何事件";
title.text.color = Color.red;
// for (int i = 0; i < 30; i++)
// {
// var button= InstantiatePrefab(buttonTemplate, menuContent.transform);
@ -46,6 +51,36 @@ namespace UI
title.Label = "生成人物";
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.CharacterDef>();
if (defList == null || defList.Length == 0)
{
title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "未定义任何角色";
title.text.color = Color.red;
}
else
foreach (var def in defList)
{
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
button.Label = def.label;
var pawnDef = def;
button.AddListener(() => GenerateEntityCallback(pawnDef));
}
}
private void InitMonster()
{
var title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "生成怪物";
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.MonsterDef>();
if (defList == null || defList.Length == 0)
{
title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "未定义任何怪物";
title.text.color = Color.red;
}
else
foreach (var def in defList)
{
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
@ -55,19 +90,26 @@ namespace UI
}
}
private void InitMonster()
private void InitBuilding()
{
var title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "生成怪物";
title.Label = "生成建筑";
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.MonsterDef>();
foreach (var def in defList)
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.BuildingDef>();
if (defList == null || defList.Length == 0)
{
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
button.Label = def.label;
var pawnDef = def;
button.AddListener(() => GenerateEntityCallback(pawnDef));
title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "未定义任何建筑";
title.text.color = Color.red;
}
else
foreach (var def in defList)
{
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
button.Label = def.label;
var pawnDef = def;
button.AddListener(() => GenerateBuildingCallback(pawnDef));
}
}
/// <summary>
@ -103,13 +145,21 @@ namespace UI
{
entityPlacementUI.currentAction = () =>
{
// 将鼠标屏幕坐标转换为世界坐标,并确保 Z 值为 0
if (!Camera.main) return;
var worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
worldPosition.z = 0;
Managers.EntityManage.Instance.GenerateEntity(pawnDef, worldPosition);
Managers.EntityManage.Instance.GenerateEntity(pawnDef, Utils.MousePosition.GetWorldPosition());
};
entityPlacementUI.Prompt = $"当前生成器:\n名称{pawnDef.label}\n描述{pawnDef.description}";
entityPlacementUI.snapEnabled = false;
Base.UIInputControl.Instance.Show(entityPlacementUI);
}
private void GenerateBuildingCallback(BuildingDef def)
{
entityPlacementUI.currentAction = () =>
{
Managers.EntityManage.Instance.GenerateBuildingEntity(def, Utils.MousePosition.GetSnappedWorldPosition());
};
entityPlacementUI.Prompt = $"当前生成器:\n名称{def.label}\n描述{def.description}";
entityPlacementUI.snapEnabled = true;
Base.UIInputControl.Instance.Show(entityPlacementUI);
}
}

View File

@ -13,6 +13,9 @@ namespace UI
public NonReturnCallback currentAction;
public GameObject focusBox;
public bool snapEnabled = false;
public string Prompt
{
get => promptText.text;
@ -30,7 +33,28 @@ namespace UI
{
currentAction();
}
if (snapEnabled)
{
focusBox.transform.position = Utils.MousePosition.GetSnappedWorldPosition();
}
else
{
focusBox.transform.position = Utils.MousePosition.GetWorldPosition();
}
}
public override void Show()
{
base.Show();
focusBox.SetActive(true);
}
override public void Hide()
{
base.Hide();
focusBox.SetActive(false);
}
}
}

View File

@ -0,0 +1,53 @@
using UnityEngine;
namespace Utils
{
public static class MousePosition
{
/// <summary>
/// 获取鼠标的屏幕位置(以像素为单位)。
/// </summary>
/// <returns>鼠标的屏幕位置 (Vector2)。</returns>
public static Vector2 GetScreenPosition()
{
return Input.mousePosition;
}
/// <summary>
/// 获取鼠标的二维世界位置(基于主摄像机的屏幕到世界转换)。
/// </summary>
/// <param name="camera">用于计算的摄像机,默认为主摄像机。</param>
/// <returns>鼠标的二维世界位置 (Vector2)。</returns>
public static Vector2 GetWorldPosition(Camera camera = null)
{
// 如果未指定摄像机,则使用主摄像机
if (!camera)
{
camera = Camera.main;
}
// 获取鼠标屏幕位置
var mouseScreenPosition = Input.mousePosition;
// 将屏幕坐标转换为世界坐标
var worldPosition = camera.ScreenToWorldPoint(mouseScreenPosition);
// 返回二维坐标 (忽略 z 轴)
return new Vector2(worldPosition.x, worldPosition.y);
}
/// <summary>
/// 获取鼠标的二维世界位置并进行整数吸附(基于主摄像机的屏幕到世界转换)。
/// </summary>
/// <param name="camera">用于计算的摄像机,默认为主摄像机。</param>
/// <returns>吸附后的二维世界位置 (Vector2Int)。</returns>
public static Vector3Int GetSnappedWorldPosition(Camera camera = null)
{
// 获取世界位置
var worldPosition = GetWorldPosition(camera);
// 对世界位置进行整数吸附
return Vector3Int.RoundToInt(worldPosition);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1b85631dc1524743aa492d8f9b4bb7e1
timeCreated: 1754840873

View File

@ -0,0 +1,183 @@
using System.Collections.Generic;
using UnityEngine;
namespace Utils
{
public static class Pathfinder
{
public static List<Vector2> FindPath(Entity.Entity entity, Vector2 target, float maxDistance)
{
Vector2 start = entity.Position;
// 计算起点和终点所在的瓦片坐标
var startTile = GetTileCoord(start);
var endTile = GetTileCoord(target);
// 如果超出最大距离,直接返回直线路径或空路径
if (Vector2.Distance(start, target) > maxDistance)
{
return new List<Vector2> { start, target };
}
// A*算法数据结构
var cameFrom = new Dictionary<Vector2Int, Vector2Int>();
var gScore = new Dictionary<Vector2Int, float>();
var fScore = new Dictionary<Vector2Int, float>();
var openSet = new List<Vector2Int>();
// 初始化
gScore[startTile] = 0;
fScore[startTile] = Heuristic(startTile, endTile);
openSet.Add(startTile);
var closestNode = startTile;
var closestDist = Vector2.Distance(start, target);
while (openSet.Count > 0)
{
// 获取fScore最小的节点
var current = openSet[0];
foreach (var node in openSet)
{
if (fScore.GetValueOrDefault(node, float.MaxValue) <
fScore.GetValueOrDefault(current, float.MaxValue))
{
current = node;
}
}
// 检查是否到达目标
if (current == endTile)
{
return ReconstructPath(cameFrom, current, start, target);
}
openSet.Remove(current);
// 检查最大距离限制
var currentDist = Vector2.Distance(
new Vector2(current.x, current.y),
target);
if (currentDist < closestDist)
{
closestDist = currentDist;
closestNode = current;
}
if (gScore[current] > maxDistance)
{
return ReconstructPath(cameFrom, closestNode, start, target);
}
// 遍历邻居8方向
for (var dx = -1; dx <= 1; dx++)
{
for (var dy = -1; dy <= 1; dy++)
{
if (dx == 0 && dy == 0) continue;
var neighbor = new Vector2Int(current.x + dx, current.y + dy);
// 跳过不可通行区域
if (!Map.MapGenerator.Instance.CanPassThrough(neighbor.x, neighbor.y))
{
continue;
}
// 计算移动成本
var moveCost = GetMovementCost(current, neighbor);
var tentativeGScore = gScore[current] + moveCost;
// 跳过超出最大距离的路径
if (tentativeGScore > maxDistance)
{
continue;
}
// 发现新节点或找到更好路径
if (tentativeGScore < gScore.GetValueOrDefault(neighbor, float.MaxValue))
{
cameFrom[neighbor] = current;
gScore[neighbor] = tentativeGScore;
fScore[neighbor] = tentativeGScore + Heuristic(neighbor, endTile);
if (!openSet.Contains(neighbor))
{
openSet.Add(neighbor);
}
}
}
}
}
// 无法找到完整路径时返回局部最优解
return ReconstructPath(cameFrom, closestNode, start, target);
}
// 获取瓦片坐标每个瓦片覆盖±0.5范围)
private static Vector2Int GetTileCoord(Vector2 position)
{
return new Vector2Int(
Mathf.RoundToInt(position.x),
Mathf.RoundToInt(position.y)
);
}
// 计算启发式估值(欧几里得距离)
private static float Heuristic(Vector2Int a, Vector2Int b)
{
return Vector2.Distance(
new Vector2(a.x, a.y),
new Vector2(b.x, b.y)
);
}
// 获取移动成本
private static float GetMovementCost(Vector2Int from, Vector2Int to)
{
// 计算基础距离(正交=1对角=√2
var distance = (from.x == to.x || from.y == to.y) ? 1f : 1.4142f;
// 应用目标瓦片的速度削减率
var costModifier = Map.MapGenerator.Instance.GetTileCost(to.x, to.y);
// 成本 = 距离 × (1 + 速度削减率)
return distance * (1 + costModifier);
}
// 重建路径
private static List<Vector2> ReconstructPath(
Dictionary<Vector2Int, Vector2Int> cameFrom,
Vector2Int current,
Vector2 start,
Vector2 end)
{
// 构建瓦片路径
var tilePath = new List<Vector2Int>();
tilePath.Add(current);
while (cameFrom.ContainsKey(current))
{
current = cameFrom[current];
tilePath.Add(current);
}
tilePath.Reverse();
// 转换为实际坐标路径
var path = new List<Vector2>();
path.Add(start); // 添加精确起点
// 添加路径点(瓦片中心)
foreach (var tile in tilePath)
{
path.Add(new Vector2(tile.x, tile.y));
}
path.Add(end); // 添加精确终点
return path;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 586ed74166c04dae862f096bdc52f63b
timeCreated: 1754750432

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Define>
<BuildingDef>
<defName>ConcreteWall</defName>
<label>水泥墙</label>
<description>很常见的钢筋混凝土建筑墙壁</description>
<attributes>
<health>1000</health>
</attributes>
<affiliation>none</affiliation>
<slowDown>1</slowDown>
</BuildingDef>
</Define>

View File

@ -71,7 +71,7 @@
</attributes>
<affiliation>player</affiliation>
<drawingOrder>
<texturePath>Resources\Character\Test</texturePath>
<texturePath>res:Character\HighSpeed</texturePath>
<drawingOrder_down>
<node name="Body" />
</drawingOrder_down>