(client) chore:修改了角色的身体结构的定义方式,现在图片资源统一使用ImageDef加载,使用了更节省资源的初始化方式;fix:修复了定义加载数组时只能初始化数组而不能初始化列表的问题

This commit is contained in:
m0_75251201
2025-08-22 20:43:55 +08:00
parent 3e099137a1
commit 8916440e7e
28 changed files with 1411 additions and 954 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,117 +0,0 @@
fileFormatVersion: 2
guid: 4c104c5bdad21f64280d4ff6f61729a8
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,117 +0,0 @@
fileFormatVersion: 2
guid: 7571ddf1e08eadd4993e266277f72bc1
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,117 +0,0 @@
fileFormatVersion: 2
guid: 0a4e42651d5472f429a1a7616d901b54
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,117 +0,0 @@
fileFormatVersion: 2
guid: 44220241de7589d46bb09f8ed4cd10ee
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f6da55e681f7bfa4790215292f123f99
guid: 415f4453b90ac044fb3ba8d150d0dc14
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
@ -34,16 +34,16 @@ TextureImporter:
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
filterMode: 0
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0

View File

@ -457,11 +457,11 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 1
m_Left: 5
m_Right: 5
m_Top: 5
m_Bottom: 5
m_ChildAlignment: 0
m_StartCorner: 0
m_StartAxis: 1
m_CellSize: {x: 100, y: 25}

View File

@ -627,6 +627,11 @@ TilemapCollider2D:
m_MaximumTileChangeCount: 1000
m_ExtrusionFactor: 0
m_UseDelaunayMesh: 0
--- !u!224 &981108095 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
m_PrefabInstance: {fileID: 2031076800}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1084213390
GameObject:
m_ObjectHideFlags: 0
@ -773,6 +778,7 @@ RectTransform:
- {fileID: 1672332560}
- {fileID: 1401161120}
- {fileID: 689345800}
- {fileID: 981108095}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@ -988,6 +994,443 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 4227482396833377269, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
m_PrefabInstance: {fileID: 481559811017721991}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &2031076800
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1236970686}
m_Modifications:
- target: {fileID: 63467561189681800, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 63467561189681800, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 63467561189681800, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 63467561189681800, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 63467561189681800, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -255
objectReference: {fileID: 0}
- target: {fileID: 588209722058685216, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 588209722058685216, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 588209722058685216, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 588209722058685216, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 588209722058685216, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -305
objectReference: {fileID: 0}
- target: {fileID: 1810958936199593402, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1810958936199593402, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1810958936199593402, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.x
value: 0.95
objectReference: {fileID: 0}
- target: {fileID: 2429789058168529657, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2429789058168529657, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: -17
objectReference: {fileID: 0}
- target: {fileID: 2900881902830087411, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2900881902830087411, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2900881902830087411, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 2900881902830087411, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 2900881902830087411, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -550
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3161252966921572831, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3582015553262914482, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3582015553262914482, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3582015553262914482, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 3582015553262914482, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 3582015553262914482, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -415
objectReference: {fileID: 0}
- target: {fileID: 3601227794910465630, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3601227794910465630, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3601227794910465630, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 3601227794910465630, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 3601227794910465630, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -20
objectReference: {fileID: 0}
- target: {fileID: 3680955383656381233, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3680955383656381233, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.y
value: -17
objectReference: {fileID: 0}
- target: {fileID: 4469608227242572628, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4469608227242572628, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4469608227242572628, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 312.99994
objectReference: {fileID: 0}
- target: {fileID: 4469608227242572628, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -85
objectReference: {fileID: 0}
- target: {fileID: 5052061354656426297, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5052061354656426297, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5052061354656426297, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5250766324582680904, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5250766324582680904, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5250766324582680904, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 5250766324582680904, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 5250766324582680904, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -205
objectReference: {fileID: 0}
- target: {fileID: 5877050460090954826, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5877050460090954826, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5877050460090954826, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 5877050460090954826, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 5877050460090954826, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -105
objectReference: {fileID: 0}
- target: {fileID: 6688065346470750453, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6688065346470750453, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6688065346470750453, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 532.99994
objectReference: {fileID: 0}
- target: {fileID: 6688065346470750453, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -85
objectReference: {fileID: 0}
- target: {fileID: 6826727892685997569, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6826727892685997569, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6826727892685997569, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 6826727892685997569, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 6826727892685997569, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -155
objectReference: {fileID: 0}
- target: {fileID: 7005200858412477501, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_Name
value: SettingUI
objectReference: {fileID: 0}
- target: {fileID: 7005200858412477501, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7318315172311564703, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7318315172311564703, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7318315172311564703, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 0.30161297
objectReference: {fileID: 0}
- target: {fileID: 8050889462025142423, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_Size
value: 0.698387
objectReference: {fileID: 0}
- target: {fileID: 8050889462025142423, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_Value
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8058820546803683956, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.y
value: 620
objectReference: {fileID: 0}
- target: {fileID: 8180193916669563286, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_Size
value: 0.99999994
objectReference: {fileID: 0}
- target: {fileID: 8180193916669563286, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_Value
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8320059764338655046, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8320059764338655046, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8320059764338655046, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 422.99994
objectReference: {fileID: 0}
- target: {fileID: 8320059764338655046, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -85
objectReference: {fileID: 0}
- target: {fileID: 8372402552497025236, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8372402552497025236, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8372402552497025236, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 8372402552497025236, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 8372402552497025236, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -340
objectReference: {fileID: 0}
- target: {fileID: 8669098655635635614, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8669098655635635614, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8669098655635635614, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: 582.99994
objectReference: {fileID: 0}
- target: {fileID: 8669098655635635614, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 391.49997
objectReference: {fileID: 0}
- target: {fileID: 8669098655635635614, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchoredPosition.y
value: -465
objectReference: {fileID: 0}
- target: {fileID: 8893679260950019636, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8893679260950019636, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8893679260950019636, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.x
value: -17
objectReference: {fileID: 0}
- target: {fileID: 8893679260950019636, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
propertyPath: m_SizeDelta.y
value: -17
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6846a4c7db6ab7e49812b377bdf8df7d, type: 3}
--- !u!224 &2068504032 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 6806539210387795853, guid: 620f2670398686943a232c5a71a6f1d5, type: 3}

View File

@ -1414,6 +1414,53 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1145531077}
m_CullTransparentMesh: 1
--- !u!1 &1200712021
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1200712023}
- component: {fileID: 1200712022}
m_Layer: 0
m_Name: RightMenuManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1200712022
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1200712021}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 409b8017bbd6443eb2dde17ea6fd5e29, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
_canvas: {fileID: 0}
_rightMenuPrefab: {fileID: 0}
--- !u!4 &1200712023
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1200712021}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 82.63557, y: 36.06109, 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 &1344781619
GameObject:
m_ObjectHideFlags: 0
@ -2206,3 +2253,4 @@ SceneRoots:
- {fileID: 2131333544}
- {fileID: 336157946}
- {fileID: 597126023}
- {fileID: 1200712023}

View File

@ -203,7 +203,7 @@ namespace Base
{
SceneManager.sceneLoaded += OnSceneLoaded;
// RegisterAllWindows();
RegisterAllWindows();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)

View File

@ -1,5 +1,6 @@
using Base;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace CameraControl
{
@ -17,7 +18,29 @@ namespace CameraControl
private Camera _camera;
private void OnDestroy()
{
// 移除事件监听
SceneManager.sceneLoaded -= OnSceneLoaded;
}
protected override void OnStart()
{
// 注册场景加载事件
SceneManager.sceneLoaded += OnSceneLoaded;
// 初始化时调用一次
Init();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
// 场景加载完成后调用 Init 方法
Init();
}
private void Init()
{
_camera = Camera.main;
if (_camera == null)
@ -44,10 +67,18 @@ namespace CameraControl
public void TickUI()
{
if (!_camera)
return;
HandleMiddleMouseDrag();
HandleMouseZoom();
}
public void SetPosition(Vector3 position)
{
if (_camera)
_camera.transform.position = position;
}
private void HandleMiddleMouseDrag()
{
// Start drag
@ -79,7 +110,8 @@ namespace CameraControl
var newSize = _camera.orthographicSize - scroll * _zoomSpeed;
_camera.orthographicSize = Mathf.Clamp(newSize, _minZoom, _maxZoom);
}
}
}

View File

@ -303,27 +303,40 @@ namespace Data
private static object ProcessArrayField(FieldInfo field, XElement element)
{
var elementType = field.FieldType.GetElementType();
// 获取集合元素的类型
Type elementType = field.FieldType.IsArray
? field.FieldType.GetElementType()
: field.FieldType.GetGenericArguments()[0];
if (elementType == null) return null;
var arrayElements = new List<object>();
// 遍历 XML 元素中的子元素
foreach (var liElement in element.Elements())
{
if (elementType.IsSubclassOf(typeof(Define)))
{
// 如果是 Define 类型或其子类
var nestedDefine = (Define)Activator.CreateInstance(elementType);
DefaultInitDefine(nestedDefine, liElement, elementType);
arrayElements.Add(nestedDefine);
}
else if (elementType.IsArray) // 嵌套数组处理
else if (elementType.IsArray || typeof(IList).IsAssignableFrom(elementType))
{
// 递归处理嵌套数组
// 嵌套数组处理(递归调用)
var pseudoField = new { FieldType = elementType };
var nestedArray = ProcessArrayField(
new { FieldType = elementType }.GetType().GetField("FieldType"),
pseudoField.GetType().GetField("FieldType"),
liElement
);
arrayElements.Add(nestedArray);
}
else if (elementType.IsEnum)
{
// 枚举类型处理
arrayElements.Add(Enum.Parse(elementType, liElement.Value));
}
else
{
// 基本类型处理
@ -331,14 +344,35 @@ namespace Data
}
}
// 构建结果数组
var resultArray = Array.CreateInstance(elementType, arrayElements.Count);
for (var i = 0; i < arrayElements.Count; i++)
// 根据目标字段的类型构建结果
if (field.FieldType.IsArray)
{
resultArray.SetValue(arrayElements[i], i);
// 如果目标字段是数组类型
var resultArray = Array.CreateInstance(elementType, arrayElements.Count);
for (var i = 0; i < arrayElements.Count; i++)
{
resultArray.SetValue(arrayElements[i], i);
}
return resultArray;
}
return resultArray;
else if (typeof(IList).IsAssignableFrom(field.FieldType))
{
// 如果目标字段是泛型集合类型(如 List<T>
var listType = typeof(List<>).MakeGenericType(elementType);
var resultList = (IList)Activator.CreateInstance(listType);
foreach (var item in arrayElements)
{
resultList.Add(item);
}
return resultList;
}
return null;
}
/// <summary>
/// 从 List<c>XDocument</c> 中查找指定根元素名称的文档。
/// </summary>

View File

@ -14,84 +14,221 @@ namespace Data
Up
}
public enum DrawNodeType
public enum EntityState
{
Image,
Animation
Idle,
Walking,
MeleeAttack,
RangedAttack,
}
public class DrawingOrderDef : Define
{
public DrawNodeDef drawingOrder_down;
public DrawNodeDef drawingOrder_up;
public DrawNodeDef drawingOrder_left;
public DrawNodeDef drawingOrder_right;
public string texturePath;
public float pixelsPerUnit = 16;
public DrawNodeDef GetDrawingOrder(Orientation orientation, out Orientation sourceOrientation)
public DrawNodeDef idle_down;
public DrawNodeDef idle_up;
public DrawNodeDef idle_left;
public DrawNodeDef idle_right;
public DrawNodeDef walk_down;
public DrawNodeDef walk_up;
public DrawNodeDef walk_left;
public DrawNodeDef walk_right;
public DrawNodeDef meleeAttack_down;
public DrawNodeDef meleeAttack_up;
public DrawNodeDef meleeAttack_left;
public DrawNodeDef meleeAttack_right;
public DrawNodeDef rangedAttack_down;
public DrawNodeDef rangedAttack_up;
public DrawNodeDef rangedAttack_left;
public DrawNodeDef rangedAttack_right;
public DrawNodeDef GetDrawNodeDef(EntityState state, Orientation orientation,
out Orientation? fallbackOrientation)
{
// 定义一个临时变量用于存储结果
DrawNodeDef result = null;
fallbackOrientation = null;
// 初始化 sourceOrientation 为默认值
sourceOrientation = Orientation.Down;
// 根据状态和方向获取对应的DrawNodeDef
var result = GetDrawNodeDefInternal(state, orientation);
// 根据传入的 Orientation 获取对应的 DrawingOrderDef
if (result != null)
{
return result;
}
// 如果找不到,按照规则查找替补
switch (orientation)
{
case Orientation.Down:
result = drawingOrder_down;
sourceOrientation = Orientation.Down;
break;
case Orientation.Up:
result = drawingOrder_up;
sourceOrientation = Orientation.Up;
// 上方向优先找下方向
result = GetDrawNodeDefInternal(state, Orientation.Down);
if (result != null)
{
fallbackOrientation = Orientation.Down;
return result;
}
// 其次找左右方向
result = GetDrawNodeDefInternal(state, Orientation.Left);
if (result != null)
{
fallbackOrientation = Orientation.Left;
return result;
}
result = GetDrawNodeDefInternal(state, Orientation.Right);
if (result != null)
{
fallbackOrientation = Orientation.Right;
return result;
}
break;
case Orientation.Down:
// 下方向优先找上方向
result = GetDrawNodeDefInternal(state, Orientation.Up);
if (result != null)
{
fallbackOrientation = Orientation.Up;
return result;
}
// 其次找左右方向
result = GetDrawNodeDefInternal(state, Orientation.Left);
if (result != null)
{
fallbackOrientation = Orientation.Left;
return result;
}
result = GetDrawNodeDefInternal(state, Orientation.Right);
if (result != null)
{
fallbackOrientation = Orientation.Right;
return result;
}
break;
case Orientation.Left:
result = drawingOrder_left;
sourceOrientation = Orientation.Left;
// 左方向优先找右方向
result = GetDrawNodeDefInternal(state, Orientation.Right);
if (result != null)
{
fallbackOrientation = Orientation.Right;
return result;
}
// 其次找上下方向
result = GetDrawNodeDefInternal(state, Orientation.Up);
if (result != null)
{
fallbackOrientation = Orientation.Up;
return result;
}
result = GetDrawNodeDefInternal(state, Orientation.Down);
if (result != null)
{
fallbackOrientation = Orientation.Down;
return result;
}
break;
case Orientation.Right:
result = drawingOrder_right;
sourceOrientation = Orientation.Right;
// 右方向优先找左方向
result = GetDrawNodeDefInternal(state, Orientation.Left);
if (result != null)
{
fallbackOrientation = Orientation.Left;
return result;
}
// 其次找上下方向
result = GetDrawNodeDefInternal(state, Orientation.Up);
if (result != null)
{
fallbackOrientation = Orientation.Up;
return result;
}
result = GetDrawNodeDefInternal(state, Orientation.Down);
if (result != null)
{
fallbackOrientation = Orientation.Down;
return result;
}
break;
default:
throw new ArgumentException("Invalid orientation value.");
throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null);
}
// 如果当前方向的结果为空,则尝试用 drawingOrder_down 填充
if (result == null)
// 如果所有替补都找不到返回null
return null;
}
private DrawNodeDef GetDrawNodeDefInternal(EntityState state, Orientation orientation)
{
// 根据状态和方向获取对应的DrawNodeDef
switch (state)
{
result = drawingOrder_down;
sourceOrientation = Orientation.Down; // 更新 sourceOrientation
case EntityState.Idle:
switch (orientation)
{
case Orientation.Down: return idle_down;
case Orientation.Up: return idle_up;
case Orientation.Left: return idle_left;
case Orientation.Right: return idle_right;
}
break;
case EntityState.Walking:
switch (orientation)
{
case Orientation.Down: return walk_down;
case Orientation.Up: return walk_up;
case Orientation.Left: return walk_left;
case Orientation.Right: return walk_right;
}
break;
case EntityState.MeleeAttack:
switch (orientation)
{
case Orientation.Down: return meleeAttack_down;
case Orientation.Up: return meleeAttack_up;
case Orientation.Left: return meleeAttack_left;
case Orientation.Right: return meleeAttack_right;
}
break;
case EntityState.RangedAttack:
switch (orientation)
{
case Orientation.Down: return rangedAttack_down;
case Orientation.Up: return rangedAttack_up;
case Orientation.Left: return rangedAttack_left;
case Orientation.Right: return rangedAttack_right;
}
break;
}
// 如果 drawingOrder_down 仍然为空,则尝试用其他非空方向填充
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 null;
}
}
public class DrawNodeDef : Define
{
public List<DrawNodeDef> children = new();
public DrawNodeType drawNodeType = DrawNodeType.Image;
public List<string> animationTextures = new();
public List<DrawNodeDef> nodes = new();
public string nodeName;
public Vector2 position = new(0, 0);
public float FPS = 0.5f;
@ -101,19 +238,9 @@ namespace Data
base.Init(xmlDef);
nodeName = xmlDef.Attribute("name")?.Value??"noName";
drawNodeType = Enum.TryParse(xmlDef.Attribute("type")?.Value, true, out DrawNodeType typeResult)
? typeResult
: DrawNodeType.Image;
position = StringToVector(xmlDef.Attribute("position")?.Value ?? "(0 0)");
FPS = float.TryParse(xmlDef.Attribute("FPS")?.Value, out float result) ? result : 1.0f;
foreach (var childNode in xmlDef.Elements())
{
var child = new DrawNodeDef();
child.Init(childNode);
children.Add(child);
}
return true;
FPS = float.TryParse(xmlDef.Attribute("FPS")?.Value, out var result) ? result : 1.0f;
return false;
}
public Vector2 StringToVector(string vectorDef)
{
@ -132,35 +259,10 @@ namespace Data
// 返回 Vector2 对象
return new Vector2(x, y);
}
else
{
return Vector2.zero;
}
return Vector2.zero;
}
// 判断两个 DrawNodeDef 是否相等
public static bool AreEqual(DrawNodeDef a, DrawNodeDef b)
{
if (ReferenceEquals(a, b)) return true; // 如果是同一个对象,直接返回 true
if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) return false; // 如果其中一个为 null返回 false
// 比较基本属性
if (a.drawNodeType != b.drawNodeType ||
a.nodeName != b.nodeName ||
a.position != b.position ||
Math.Abs(a.FPS - b.FPS) > 0.001f) // 浮点数比较需要考虑精度
return false;
// 比较 children 的数量
if (a.children.Count != b.children.Count)
return false;
// 递归比较每个子节点
for (var i = 0; i < a.children.Count; i++)
{
if (!AreEqual(a.children[i], b.children[i]))
return false;
}
return true;
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using AI;
using Base;
using Data;
@ -98,7 +99,7 @@ namespace Entity
/// 表示实体是否已经死亡(生命值小于等于零)。
/// </summary>
public bool IsDead => attributes.health <= 0;
public bool IsShowingOfHitBarUI=>hitBarUIShowTimer > 0;
public bool IsShowingHealthBarUI=>hitBarUIShowTimer > 0;
public bool IsAttacking => attackCoroutine != null;
@ -108,18 +109,21 @@ namespace Entity
/// <summary>
/// 存储不同朝向下的动画节点集合。
/// </summary>
public Dictionary<Orientation, List<ITick>> bodyAnimationNode = new();
public Dictionary<EntityState, Dictionary<Orientation, List<ITick>>> bodyAnimationNode = new();
private List<ITick> currentAnimatorCache=new ();
/// <summary>
/// 存储不同朝向下的身体节点对象。
/// </summary>
private Dictionary<Orientation, GameObject> bodyNodes = new();
private Dictionary<EntityState, Dictionary<Orientation,GameObject>> bodyNodes = new();
/// <summary>
/// 当前实体的朝向。
/// </summary>
private Orientation currentOrientation = Orientation.Down;
/// <summary>
/// 当前实体的状态
/// </summary>
private EntityState currentState = EntityState.Idle;
/// <summary>
@ -162,83 +166,218 @@ namespace Entity
/// <param name="drawingOrder">绘制顺序定义。</param>
public virtual void InitBody(DrawingOrderDef drawingOrder)
{
// 定义方向枚举和对应的 GetDrawingOrder 调用
Orientation[] orientations = { Orientation.Down, Orientation.Up, Orientation.Left, Orientation.Right };
// 预缓存枚举值(避免每次循环重复调用 Enum.GetValues
var states = Enum.GetValues(typeof(EntityState)).Cast<EntityState>().ToArray();
var orientations = Enum.GetValues(typeof(Orientation)).Cast<Orientation>().ToArray();
foreach (var orientation in orientations)
// 预初始化字典结构(减少内层循环的字典检查)
foreach (var state in states)
{
currentOrientation = orientation;
bodyAnimationNode[orientation] = new();
// 获取当前方向的绘图节点
var drawNode = drawingOrder.GetDrawingOrder(orientation, out var realOrientation);
if (drawNode == null) continue;
var directionRoot = new GameObject(orientation.ToString());
directionRoot.transform.SetParent(body.transform, false);
InitBodyPart(drawNode, directionRoot, drawingOrder.texturePath,realOrientation);
bodyNodes[orientation] = directionRoot;
bodyNodes.TryAdd(state, new Dictionary<Orientation, GameObject>());
bodyAnimationNode.TryAdd(state, new Dictionary<Orientation, List<ITick>>());
}
currentOrientation = Orientation.Down;
foreach (var bodyNode in bodyNodes)
// 主初始化逻辑
foreach (var state in states)
{
bodyNode.Value.SetActive(false);
var stateBodyNodes = bodyNodes[state];
var stateAnimNodes = bodyAnimationNode[state];
foreach (var orientation in orientations)
{
// 获取节点定义(避免重复调用)
var nodeDef = drawingOrder.GetDrawNodeDef(state, orientation, out var original);
// 处理空节点定义(直接创建空对象)
if (nodeDef == null)
{
var obj = new GameObject { name = $"{state}_Empty" };
obj.transform.SetParent(body.transform, false);
stateBodyNodes[orientation] = obj;
continue; // 跳过后续动画处理
}
// 处理有效节点定义
GameObject targetObj;
if (original.HasValue && stateBodyNodes.TryGetValue(original.Value, out var reusedObj))
{
targetObj = reusedObj; // 复用已有对象
}
else
{
targetObj = InitBodyPart(nodeDef, body); // 创建新对象
}
stateBodyNodes[orientation] = targetObj;
// 提取动画组件(安全处理空组件情况)
var animators = targetObj.GetComponentsInChildren<SpriteAnimator>();
if (animators.Length > 0)
{
stateAnimNodes[orientation] = animators.Cast<ITick>().ToList();
}
// 无动画组件时保持 stateAnimNodes[orientation] 为 null符合原始逻辑
}
}
SetOrientation(Orientation.Down);
// 批量隐藏所有节点(使用字典值集合直接操作)
foreach (var nodeDict in bodyNodes.Values)
{
foreach (var obj in nodeDict.Values)
{
obj.SetActive(false);
}
}
SetBodyTexture(EntityState.Idle,Orientation.Down); // 激活默认朝向
}
/// <summary>
/// 递归初始化单个绘图节点及其子节点。
/// 递归初始化单个绘图节点及其子节点,具有更强的健壮性和错误处理
/// </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)
/// <returns>创建的GameObject如果失败则返回null</returns>
public virtual GameObject InitBodyPart(DrawNodeDef drawNode, GameObject parent)
{
if (drawNode == null) return;
GameObject nodeObject;
if (drawNode.nodeName == "noName")
try
{
nodeObject = new();
nodeObject.transform.SetParent(parent.transform);
}
else
{
switch (drawNode.drawNodeType)
// 参数验证
if (drawNode == null)
{
case DrawNodeType.Image:
Debug.LogWarning("InitBodyPart: drawNode参数为null");
return null;
}
if (parent == null)
{
Debug.LogWarning($"InitBodyPart: 父节点为null (节点名: {drawNode.nodeName})");
return null;
}
GameObject nodeObject = null;
// 根据纹理数量创建不同类型的节点
switch (drawNode.animationTextures?.Count ?? 0)
{
case 0:
// 无纹理节点
nodeObject = new GameObject(drawNode.nodeName);
nodeObject.transform.SetParent(parent.transform, false);
break;
case 1:
// 单纹理节点
if (imagePrefab == null)
{
Debug.LogError($"InitBodyPart: imagePrefab未设置 (节点名: {drawNode.nodeName})");
return null;
}
nodeObject = Instantiate(imagePrefab.gameObject, parent.transform);
var texture =
Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID, folderPath,
$"{drawNode.nodeName}_{realOrientation}");
var image = nodeObject.GetComponent<ImagePrefab>();
image.SetSprite(texture.Length > 0
? texture[0]
: Managers.PackagesImageManager.Instance.defaultSprite);
Managers.PackagesImageManager.Instance?.GetSprite(drawNode.packID,
drawNode.animationTextures[0]);
if (!texture)
{
Debug.LogWarning(
$"InitBodyPart: 无法获取纹理 (节点名: {drawNode.nodeName}, 纹理ID: {drawNode.animationTextures[0]})");
}
var imagePrefabCom = nodeObject.GetComponent<ImagePrefab>();
if (imagePrefabCom != null)
{
imagePrefabCom.SetSprite(texture);
}
else
{
Debug.LogWarning($"InitBodyPart: 无法获取ImagePrefab组件 (节点名: {drawNode.nodeName})");
}
break;
case DrawNodeType.Animation:
nodeObject = Instantiate(animatorPrefab.gameObject, parent.transform);
ITick tick = nodeObject.GetComponent<SpriteAnimator>();
if (tick != null)
bodyAnimationNode[currentOrientation].Add(tick);
var textures = Managers.PackagesImageManager.Instance.FindBodyTextures(drawNode.packID,
folderPath,
$"{drawNode.nodeName}_{realOrientation}");
var animator = nodeObject.GetComponent<SpriteAnimator>();
animator.SetSprites(textures);
break;
default:
throw new ArgumentOutOfRangeException();
// 多纹理动画节点
if (!animatorPrefab)
{
Debug.LogError($"InitBodyPart: animatorPrefab未设置 (节点名: {drawNode.nodeName})");
return null;
}
nodeObject = Instantiate(animatorPrefab.gameObject, parent.transform);
var animator = nodeObject.GetComponent<SpriteAnimator>();
if (animator == null)
{
Debug.LogWarning($"InitBodyPart: 无法获取SpriteAnimator组件 (节点名: {drawNode.nodeName})");
break;
}
animator.SetFPS(drawNode.FPS);
var animatedSprites = new List<Sprite>();
foreach (var textureId in drawNode.animationTextures)
{
try
{
var sprite =
Managers.PackagesImageManager.Instance?.GetSprite(drawNode.packID, textureId);
if (sprite != null)
{
animatedSprites.Add(sprite);
}
else
{
Debug.LogWarning(
$"InitBodyPart: 无法获取动画纹理 (节点名: {drawNode.nodeName}, 纹理ID: {textureId})");
}
}
catch (Exception ex)
{
Debug.LogError(
$"InitBodyPart: 加载动画纹理时出错 (节点名: {drawNode.nodeName}, 纹理ID: {textureId}): {ex.Message}");
}
}
if (animatedSprites.Count > 0)
{
animator.SetSprites(animatedSprites.ToArray());
}
else
{
Debug.LogWarning($"InitBodyPart: 没有有效的动画纹理 (节点名: {drawNode.nodeName})");
}
break;
}
// 设置节点属性
if (!nodeObject) return nodeObject;
nodeObject.transform.localPosition = drawNode.position;
nodeObject.name = drawNode.nodeName ?? "UnnamedNode";
// 递归初始化子节点
if (drawNode.nodes == null) return nodeObject;
foreach (var child in drawNode.nodes)
{
try
{
InitBodyPart(child, nodeObject);
}
catch (Exception ex)
{
Debug.LogError($"InitBodyPart: 初始化子节点失败 (父节点: {drawNode.nodeName}): {ex.Message}");
}
}
return nodeObject;
}
nodeObject.transform.localPosition = drawNode.position;
nodeObject.name = drawNode.nodeName;
// 递归初始化子节点
foreach (var child in drawNode.children)
catch (Exception ex)
{
InitBodyPart(child, nodeObject, folderPath,realOrientation);
Debug.LogError($"InitBodyPart: 初始化节点时发生未处理的异常 (节点名: {drawNode?.nodeName}): {ex}");
return null;
}
}
@ -255,15 +394,17 @@ namespace Entity
{
AutoBehave();
}
if (bodyAnimationNode.TryGetValue(currentOrientation, out var ticks))
if (currentAnimatorCache!=null)
{
foreach (var tick in ticks)
foreach (var animator in currentAnimatorCache)
{
tick.Tick();
animator.Tick();
}
}
if (IsShowingOfHitBarUI)
if (IsShowingHealthBarUI)
{
hitBarUIShowTimer -= Time.deltaTime;
if (hitBarUIShowTimer <= 0)
@ -281,24 +422,34 @@ namespace Entity
if(!IsAttacking)
attackCoroutine = StartCoroutine(AttackFlow());
}
/// <summary>
/// 设置实体的朝向。
/// </summary>
/// <param name="orientation">新的朝向。</param>
public virtual void SetOrientation(Orientation orientation)
public virtual void SetBodyTexture(EntityState state, Orientation orientation)
{
// 禁用当前朝向的节点
if (bodyNodes.TryGetValue(currentOrientation, out var currentNode))
if (bodyNodes.TryGetValue(currentState, out var stateNode))
{
currentNode.SetActive(false);
if (stateNode.TryGetValue(currentOrientation, out var node))
{
node.SetActive(false);
}
}
// 设置新的朝向
currentOrientation = orientation;
// 激活新朝向的节点
if (bodyNodes.TryGetValue(orientation, out var newNode))
if (bodyNodes.TryGetValue(state, out var showStateNode))
{
newNode.SetActive(true);
if (showStateNode.TryGetValue(orientation, out var showNode))
{
showNode.SetActive(true);
}
}
currentState = state;
currentOrientation = orientation;
if (bodyAnimationNode.TryGetValue(currentState, out var animationNode))
{
if (animationNode.TryGetValue(currentOrientation, out var value))
{
currentAnimatorCache=value;
}
}
}
@ -369,7 +520,8 @@ namespace Entity
// 水平方向优先
ori = direction.x > 0 ? Orientation.Right : Orientation.Left;
}
SetOrientation(ori);
SetBodyTexture(currentState, ori);
}
/// <summary>

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Data;
using UnityEngine;
namespace Managers
{

View File

@ -5,6 +5,7 @@ using Base;
using Entity;
using Prefab;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Serialization;
namespace Managers
@ -145,7 +146,6 @@ namespace Managers
// 如果层不存在,动态创建
var layerObject = new GameObject(layerName);
layerTransform = layerObject.transform;
layerTransform.SetParent(transform, false); // 将层附加到当前管理器下
}
// 将新创建的层加入缓存
@ -280,11 +280,23 @@ namespace Managers
entityComponent.DefaultInit();
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
protected override void OnStart()
{
factionEntities.Clear();
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
factionEntities.Clear();
layerCache.Clear();
pendingAdditions.Clear();
}
private void Start()

View File

@ -15,192 +15,265 @@ namespace Managers
public Dictionary<string, Dictionary<string, Texture2D>> packagesImages = new();
//包名,图片名
public Dictionary<string, Dictionary<string, Sprite>> sprites = new();
//包名,文件路径,身体部件名
public Dictionary<string, Dictionary<string, Dictionary<string, Sprite>>> bodyTexture = new();
public void Init()
{
if (packagesImages.Count > 0)
return;
defaultSprite = Resources.Load<Sprite>("Default/DefaultImage");
InitImageDef();
InitDrawOrder();
}
public void InitImageDef()
{
var textureCache = new Dictionary<string, Texture2D>();
var imageDef = Managers.DefineManager.Instance.QueryDefinesByType<ImageDef>();
foreach (var ima in imageDef)
{
if (ima.path == null || ima.packID == null)
continue;
var pack = Managers.DefineManager.Instance.GetDefinePackage(ima);
var path = Path.Combine(pack.packRootPath, ima.path);
var texture = Configs.ConfigProcessor.LoadTextureByIO(path);
if (!texture)
if (string.IsNullOrEmpty(ima.path) || string.IsNullOrEmpty(ima.packID))
continue;
var packId = ima.packID;
// 解析路径前缀
if (!packagesImages.ContainsKey(packId))
packagesImages[packId] = new Dictionary<string, Texture2D>();
packagesImages[packId].Add(ima.name, texture);
SplitTextureIntoSprites(packId, ima.name, texture, ima.hCount, ima.wCount, ima.pixelsPerUnit);
}
}
public void InitDrawOrder()
{
try
{
// 查询绘制顺序定义
var drawOrderDef = Managers.DefineManager.Instance.QueryDefinesByType<DrawingOrderDef>();
if (drawOrderDef == null || drawOrderDef.Length == 0)
try
{
Debug.LogWarning("No DrawingOrderDef found.");
return;
}
// 初始化包路径字典
Dictionary<string, string> packRootSite = new();
foreach (var drawOrder in drawOrderDef)
{
// 检查必要字段是否为空
if (string.IsNullOrEmpty(drawOrder.texturePath) || string.IsNullOrEmpty(drawOrder.packID))
string cacheKey;
Texture2D texture;
if (ima.path.StartsWith("res:"))
{
Debug.LogWarning(
$"Skipping invalid drawOrder: texturePath or packID is null or empty. PackID: {drawOrder.packID}");
continue;
}
// 处理Resources路径
var resPath = ima.path.Substring(4).Replace('\\', '/').TrimStart('/');
cacheKey = "res://" + resPath.ToLower();
// 获取包路径
if (!packRootSite.ContainsKey(drawOrder.packID))
{
var packagePath = Managers.DefineManager.Instance.GetPackagePath(drawOrder.packID);
if (string.IsNullOrEmpty(packagePath))
// 检查缓存
if (!textureCache.TryGetValue(cacheKey, out texture))
{
Debug.LogError($"Package path not found for packID: {drawOrder.packID}");
continue;
// 去掉扩展名
var cleanPath = Path.ChangeExtension(resPath, null);
texture = Resources.Load<Texture2D>(cleanPath);
if (texture)
textureCache[cacheKey] = texture;
}
packRootSite[drawOrder.packID] = packagePath;
}
// 判断是否为 Unity 资源路径
var isUnityResource = drawOrder.texturePath.StartsWith("res:", StringComparison.OrdinalIgnoreCase);
var rootPath = packRootSite[drawOrder.packID];
if (isUnityResource)
else if (ima.path.Contains(':'))
{
// 移除 "res:" 前缀并适配 Unity 资源路径规则
var resourceFolder = drawOrder.texturePath.Substring(4).TrimStart('/').Replace('\\', '/');
// 处理其他包ID前缀如 "PackageID:Path"
var splitIndex = ima.path.IndexOf(':');
var packageID = ima.path.Substring(0, splitIndex);
var relativePath = ima.path.Substring(splitIndex + 1);
// 加载文件夹下的所有纹理资源
var textures = Resources.LoadAll<Texture2D>(resourceFolder);
if (textures == null || textures.Length == 0)
{
Debug.LogWarning($"No textures found in Unity resource folder: {resourceFolder}");
// 获取包根路径
var packageRoot = Managers.DefineManager.Instance.GetPackagePath(packageID);
if (string.IsNullOrEmpty(packageRoot))
continue;
}
foreach (var image in textures)
var fullPath = Path.Combine(packageRoot, relativePath).Replace('\\', '/');
cacheKey = "file://" + fullPath.ToLower();
// 检查缓存
if (!textureCache.TryGetValue(cacheKey, out texture))
{
if (image == null)
{
Debug.LogWarning(
$"Texture loaded from Unity resource folder: {resourceFolder} is null.");
continue;
}
// 创建精灵
try
{
var spr = Sprite.Create(
image,
new Rect(0, 0, image.width, image.height),
new Vector2(0.5f, 0.5f), // 中心点
drawOrder.pixelsPerUnit
);
var name = image.name;
// 插入纹理
InsertBodyTexture(drawOrder.packID, drawOrder.texturePath, name, spr);
}
catch (Exception ex)
{
Debug.LogError(
$"Failed to create sprite from Unity resource: {image.name}. Error: {ex.Message}");
}
texture = Configs.ConfigProcessor.LoadTextureByIO(fullPath);
if (texture)
textureCache[cacheKey] = texture;
}
}
else
{
// 文件系统路径处理
var folderPath = Path.Combine(rootPath, drawOrder.texturePath);
// 无前缀:使用当前定义所在包的路径
var pack = Managers.DefineManager.Instance.GetDefinePackage(ima);
var fullPath = Path.Combine(pack.packRootPath, ima.path).Replace('\\', '/');
cacheKey = "file://" + fullPath.ToLower();
// 获取图像文件列表
try
// 检查缓存
if (!textureCache.TryGetValue(cacheKey, out texture))
{
var imagePath = Configs.ConfigProcessor.GetFilesByExtensions(folderPath,
new[] { "jpg", "jpeg", "png", "tga", "tif", "tiff", "psd", "bmp" });
foreach (var path in imagePath)
{
// 加载纹理
Texture2D image = null;
try
{
image = Configs.ConfigProcessor.LoadTextureByIO(path);
}
catch (Exception ex)
{
Debug.LogError($"Failed to load texture from path: {path}. Error: {ex.Message}");
continue;
}
if (image == null)
{
Debug.LogWarning($"Texture loaded from path: {path} is null.");
continue;
}
// 创建精灵
try
{
var spr = Sprite.Create(
image,
new Rect(0, 0, image.width, image.height),
new Vector2(0.5f, 0.5f), // 中心点
drawOrder.pixelsPerUnit
);
var name = Path.GetFileNameWithoutExtension(path);
// 插入纹理
InsertBodyTexture(drawOrder.packID, drawOrder.texturePath, name, spr);
}
catch (Exception ex)
{
Debug.LogError(
$"Failed to create sprite from texture: {path}. Error: {ex.Message}");
}
}
}
catch (Exception ex)
{
Debug.LogError($"Failed to retrieve files from folder: {folderPath}. Error: {ex.Message}");
texture = Configs.ConfigProcessor.LoadTextureByIO(fullPath);
if (texture)
textureCache[cacheKey] = texture;
}
}
// 资源加载失败
if (!texture)
{
Debug.LogError($"Failed to load texture: {ima.path} (PackID: {ima.packID}, Name: {ima.name})");
continue;
}
// 存储到包资源字典使用原始packID非路径中的包ID
var packId = ima.packID;
if (!packagesImages.ContainsKey(packId))
packagesImages[packId] = new Dictionary<string, Texture2D>();
// 避免同一包内重复添加(查重)
if (!packagesImages[packId].ContainsKey(ima.name))
packagesImages[packId].Add(ima.name, texture);
else
packagesImages[packId][ima.name] = texture; // 覆盖已存在的引用
// 切分精灵
SplitTextureIntoSprites(packId, ima.name, texture, ima.hCount, ima.wCount, ima.pixelsPerUnit);
}
catch (Exception ex)
{
// 捕获异常并打印详细错误信息
Debug.LogError(
$"Error processing image definition: {ima.name} (Path: {ima.path}, PackID: {ima.packID}). Exception: {ex.Message}");
}
}
catch (Exception ex)
{
Debug.LogError($"An unexpected error occurred in InitDrawOrder: {ex.Message}");
}
}
// public void InitDrawOrder()
// {
// try
// {
// // 查询绘制顺序定义
// var drawOrderDef = Managers.DefineManager.Instance.QueryDefinesByType<DrawingOrderDef>();
// if (drawOrderDef == null || drawOrderDef.Length == 0)
// {
// Debug.LogWarning("No DrawingOrderDef found.");
// return;
// }
//
// // 初始化包路径字典
// Dictionary<string, string> packRootSite = new();
//
// foreach (var drawOrder in drawOrderDef)
// {
// // 检查必要字段是否为空
// if (string.IsNullOrEmpty(drawOrder.texturePath) || string.IsNullOrEmpty(drawOrder.packID))
// {
// Debug.LogWarning(
// $"Skipping invalid drawOrder: texturePath or packID is null or empty. PackID: {drawOrder.packID}");
// continue;
// }
//
// // 获取包路径
// if (!packRootSite.ContainsKey(drawOrder.packID))
// {
// var packagePath = Managers.DefineManager.Instance.GetPackagePath(drawOrder.packID);
// if (string.IsNullOrEmpty(packagePath))
// {
// Debug.LogError($"Package path not found for packID: {drawOrder.packID}");
// continue;
// }
//
// packRootSite[drawOrder.packID] = packagePath;
// }
//
// // 判断是否为 Unity 资源路径
// var isUnityResource = drawOrder.texturePath.StartsWith("res:", StringComparison.OrdinalIgnoreCase);
// var rootPath = packRootSite[drawOrder.packID];
//
// if (isUnityResource)
// {
// // 移除 "res:" 前缀并适配 Unity 资源路径规则
// var resourceFolder = drawOrder.texturePath.Substring(4).TrimStart('/').Replace('\\', '/');
//
// // 加载文件夹下的所有纹理资源
// var textures = Resources.LoadAll<Texture2D>(resourceFolder);
// if (textures == null || textures.Length == 0)
// {
// Debug.LogWarning($"No textures found in Unity resource folder: {resourceFolder}");
// continue;
// }
//
// foreach (var image in textures)
// {
// if (image == null)
// {
// Debug.LogWarning(
// $"Texture loaded from Unity resource folder: {resourceFolder} is null.");
// continue;
// }
//
// // 创建精灵
// try
// {
// var spr = Sprite.Create(
// image,
// new Rect(0, 0, image.width, image.height),
// new Vector2(0.5f, 0.5f), // 中心点
// drawOrder.pixelsPerUnit
// );
// var name = image.name;
//
// // 插入纹理
// InsertBodyTexture(drawOrder.packID, drawOrder.texturePath, name, spr);
// }
// catch (Exception ex)
// {
// Debug.LogError(
// $"Failed to create sprite from Unity resource: {image.name}. Error: {ex.Message}");
// }
// }
// }
// else
// {
// // 文件系统路径处理
// var folderPath = Path.Combine(rootPath, drawOrder.texturePath);
//
// // 获取图像文件列表
// try
// {
// var imagePath = Configs.ConfigProcessor.GetFilesByExtensions(folderPath,
// new[] { "jpg", "jpeg", "png", "tga", "tif", "tiff", "psd", "bmp" });
//
// foreach (var path in imagePath)
// {
// // 加载纹理
// Texture2D image = null;
// try
// {
// image = Configs.ConfigProcessor.LoadTextureByIO(path);
// }
// catch (Exception ex)
// {
// Debug.LogError($"Failed to load texture from path: {path}. Error: {ex.Message}");
// continue;
// }
//
// if (image == null)
// {
// Debug.LogWarning($"Texture loaded from path: {path} is null.");
// continue;
// }
//
// // 创建精灵
// try
// {
// var spr = Sprite.Create(
// image,
// new Rect(0, 0, image.width, image.height),
// new Vector2(0.5f, 0.5f), // 中心点
// drawOrder.pixelsPerUnit
// );
//
// var name = Path.GetFileNameWithoutExtension(path);
//
// // 插入纹理
// InsertBodyTexture(drawOrder.packID, drawOrder.texturePath, name, spr);
// }
// catch (Exception ex)
// {
// Debug.LogError(
// $"Failed to create sprite from texture: {path}. Error: {ex.Message}");
// }
// }
// }
// catch (Exception ex)
// {
// Debug.LogError($"Failed to retrieve files from folder: {folderPath}. Error: {ex.Message}");
// }
// }
// }
// }
// catch (Exception ex)
// {
// Debug.LogError($"An unexpected error occurred in InitDrawOrder: {ex.Message}");
// }
// }
private void SplitTextureIntoSprites(
string packId,
@ -210,7 +283,7 @@ namespace Managers
int cols,
int pixelsPerUnit)
{
if (texture == null)
if (!texture)
{
Debug.LogError("Texture is null.");
return;
@ -256,7 +329,7 @@ namespace Managers
var index = (rows - row - 1) * cols + col;
var spriteName = $"{baseName}_{index}";
sprite.name = spriteName;
sprites[packId][spriteName] = sprite;
}
}
@ -297,96 +370,96 @@ namespace Managers
var fullName = $"{name}_{index}";
return GetSprite(packID, fullName);
}
/// <summary>
/// 向 bodyTexture 插入一张 Sprite。
/// 如果包名、路径或部件名原本不存在,会自动建立对应的 Dictionary。
/// </summary>
/// <param name="packageName">包名</param>
/// <param name="filePath">文件路径</param>
/// <param name="bodyPartName">身体部件名</param>
/// <param name="sprite">要插入的 Sprite</param>
public void InsertBodyTexture(string packageName,
string filePath,
string bodyPartName,
Sprite sprite)
{
if (sprite == null)
{
Debug.LogWarning("InsertBodyTexture: sprite 为 null已忽略。");
return;
}
// 1) 处理包名层级
if (!bodyTexture.TryGetValue(packageName, out var pathDict))
{
pathDict = new Dictionary<string, Dictionary<string, Sprite>>();
bodyTexture[packageName] = pathDict;
}
// 2) 处理文件路径层级
if (!pathDict.TryGetValue(filePath, out var partDict))
{
partDict = new Dictionary<string, Sprite>();
pathDict[filePath] = partDict;
}
// 3) 插入或覆盖部件名
partDict[bodyPartName] = sprite;
}
/// <summary>
/// 查找身体部件的所有Sprite变体支持带编号的图片
/// </summary>
/// <param name="packageName">包名</param>
/// <param name="filePath">文件路径</param>
/// <param name="bodyPartName">身体部件名</param>
/// <returns>按编号排序的Sprite数组未找到时返回空数组</returns>
public Sprite[] FindBodyTextures(string packageName, string filePath, string bodyPartName)
{
// 检查包名是否存在
if (!bodyTexture.TryGetValue(packageName, out var packageDict))
{
Debug.LogWarning($"Package '{packageName}' not found.");
return new[] { defaultSprite };
}
// 检查文件路径是否存在
if (!packageDict.TryGetValue(filePath, out var pathDict))
{
Debug.LogWarning($"File path '{filePath}' not found in package '{packageName}'.");
return new[] { defaultSprite };
}
// 收集所有匹配的Sprite
var sprites = new List<(int order, Sprite sprite)>();
// 查找完全匹配的项(无编号)
if (pathDict.TryGetValue(bodyPartName, out var baseSprite))
{
sprites.Add((0, baseSprite));
}
// 查找带编号的变体
var prefix = bodyPartName + "_";
foreach (var (key, value) in pathDict)
{
// 检查是否以部件名+下划线开头
if (key.StartsWith(prefix) && key.Length > prefix.Length)
{
var suffix = key.Substring(prefix.Length);
// 尝试解析编号
if (int.TryParse(suffix, out var number))
{
sprites.Add((number, value));
}
}
}
// 按编号排序无编号视为0
return sprites
.OrderBy(x => x.order)
.Select(x => x.sprite)
.ToArray();
}
// /// <summary>
// /// 向 bodyTexture 插入一张 Sprite。
// /// 如果包名、路径或部件名原本不存在,会自动建立对应的 Dictionary。
// /// </summary>
// /// <param name="packageName">包名</param>
// /// <param name="filePath">文件路径</param>
// /// <param name="bodyPartName">身体部件名</param>
// /// <param name="sprite">要插入的 Sprite</param>
// public void InsertBodyTexture(string packageName,
// string filePath,
// string bodyPartName,
// Sprite sprite)
// {
// if (sprite == null)
// {
// Debug.LogWarning("InsertBodyTexture: sprite 为 null已忽略。");
// return;
// }
//
// // 1) 处理包名层级
// if (!bodyTexture.TryGetValue(packageName, out var pathDict))
// {
// pathDict = new Dictionary<string, Dictionary<string, Sprite>>();
// bodyTexture[packageName] = pathDict;
// }
//
// // 2) 处理文件路径层级
// if (!pathDict.TryGetValue(filePath, out var partDict))
// {
// partDict = new Dictionary<string, Sprite>();
// pathDict[filePath] = partDict;
// }
//
// // 3) 插入或覆盖部件名
// partDict[bodyPartName] = sprite;
// }
// /// <summary>
// /// 查找身体部件的所有Sprite变体支持带编号的图片
// /// </summary>
// /// <param name="packageName">包名</param>
// /// <param name="filePath">文件路径</param>
// /// <param name="bodyPartName">身体部件名</param>
// /// <returns>按编号排序的Sprite数组未找到时返回空数组</returns>
// public Sprite[] FindBodyTextures(string packageName, string filePath, string bodyPartName)
// {
// // 检查包名是否存在
// if (!bodyTexture.TryGetValue(packageName, out var packageDict))
// {
// Debug.LogWarning($"Package '{packageName}' not found.");
// return new[] { defaultSprite };
// }
//
// // 检查文件路径是否存在
// if (!packageDict.TryGetValue(filePath, out var pathDict))
// {
// Debug.LogWarning($"File path '{filePath}' not found in package '{packageName}'.");
// return new[] { defaultSprite };
// }
//
// // 收集所有匹配的Sprite
// var sprites = new List<(int order, Sprite sprite)>();
//
// // 查找完全匹配的项(无编号)
// if (pathDict.TryGetValue(bodyPartName, out var baseSprite))
// {
// sprites.Add((0, baseSprite));
// }
//
// // 查找带编号的变体
// var prefix = bodyPartName + "_";
// foreach (var (key, value) in pathDict)
// {
// // 检查是否以部件名+下划线开头
// if (key.StartsWith(prefix) && key.Length > prefix.Length)
// {
// var suffix = key.Substring(prefix.Length);
//
// // 尝试解析编号
// if (int.TryParse(suffix, out var number))
// {
// sprites.Add((number, value));
// }
// }
// }
//
// // 按编号排序无编号视为0
// return sprites
// .OrderBy(x => x.order)
// .Select(x => x.sprite)
// .ToArray();
// }
}
}

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Data;
@ -9,17 +10,37 @@ namespace Map
{
public class DoubleMap : MonoBehaviour
{
public List<List<int>> mapData = new List<List<int>>();
public List<List<int>> mapData = new();
public Tilemap textureLevel;
public Vector2Int dataOffset = Vector2Int.zero; // 数据起始点偏移变量
private void Start()
{
var size = 100;
InitializeData(size, size);
for (var i = 0; i < size; i++)
{
for (var j = 0; j < size; j++)
{
var dx = i - size / 2;
var dy = j - size / 2;
mapData[i][j] = (int)(Math.Sqrt(dx * dx + dy * dy) / 5) & 1;
}
}
RefreshAllTiles();
CameraControl.CameraControl.Instance.SetPosition(new Vector3(size * 0.5f, size * 0.5f, -10));
}
// 初始化地图数据大小
public void InitializeData(int width, int height, int defaultValue = 0)
{
mapData.Clear();
for (int x = 0; x < width; x++)
for (var x = 0; x < width; x++)
{
List<int> column = new List<int>();
for (int y = 0; y < height; y++)
var column = new List<int>();
for (var y = 0; y < height; y++)
{
column.Add(defaultValue);
}
@ -59,7 +80,7 @@ namespace Map
public void RefreshTile(int dataX, int dataY)
{
// 计算该数据点影响的四个瓦片位置(该点作为四个角)
Vector2Int[] affectedTiles = new Vector2Int[]
var affectedTiles = new Vector2Int[]
{
new Vector2Int(dataX - 1, dataY - 1), // 作为右下角
new Vector2Int(dataX - 1, dataY), // 作为右上角
@ -79,15 +100,15 @@ namespace Map
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;
var startX = dataOffset.x;
var startY = dataOffset.y;
var endX = startX + mapData.Count - 1;
var endY = startY + mapData[0].Count - 1;
// 遍历所有瓦片位置
for (int x = startX; x <= endX; x++)
for (var x = startX; x <= endX; x++)
{
for (int y = startY; y <= endY; y++)
for (var y = startY; y <= endY; y++)
{
UpdateTileAtTilemapPosition(x, y);
}
@ -98,30 +119,30 @@ namespace Map
private void UpdateTileAtTilemapPosition(int tileX, int tileY)
{
// 计算对应的数据坐标(考虑偏移)
int dataX = tileX - dataOffset.x;
int dataY = tileY - dataOffset.y;
var dataX = tileX - dataOffset.x;
var dataY = tileY - dataOffset.y;
// 获取四个角的数据坐标
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 topLeftX = dataX;
var topLeftY = dataY + 1;
var topRightX = dataX + 1;
var topRightY = dataY + 1;
var bottomLeftX = dataX;
var bottomLeftY = dataY;
var bottomRightX = dataX + 1;
var bottomRightY = dataY;
// 检查边界并获取值
int topLeft = GetDataValue(topLeftX, topLeftY);
int topRight = GetDataValue(topRightX, topRightY);
int bottomLeft = GetDataValue(bottomLeftX, bottomLeftY);
int bottomRight = GetDataValue(bottomRightX, bottomRightY);
var topLeft = GetDataValue(topLeftX, topLeftY);
var topRight = GetDataValue(topRightX, topRightY);
var bottomLeft = GetDataValue(bottomLeftX, bottomLeftY);
var bottomRight = GetDataValue(bottomRightX, bottomRightY);
// 获取对应的瓦片
TileBase tile = GetTileFromManager(topLeft, topRight, bottomLeft, bottomRight);
var tile = GetTileFromManager(topLeft, topRight, bottomLeft, bottomRight);
// 设置到瓦片地图
Vector3Int position = new Vector3Int(tileX, tileY, 0);
var position = new Vector3Int(tileX, tileY, 0);
textureLevel.SetTile(position, tile);
}
@ -136,7 +157,7 @@ namespace Map
// 从TileManager获取对应瓦片
private TileBase GetTileFromManager(int topLeft, int topRight, int bottomLeft, int bottomRight)
{
TileManager manager = TileManager.Instance;
var manager = TileManager.Instance;
if (manager == null)
{
Debug.LogError("TileManager实例未找到");
@ -145,13 +166,13 @@ namespace Map
// 尝试获取组合键对应的瓦片
var key = (topLeft, topRight, bottomLeft, bottomRight);
if (manager.tileToTileBaseMapping.TryGetValue(key, out TileBase tile))
if (manager.tileToTileBaseMapping.TryGetValue(key, out var tile))
{
return tile;
}
// 备用方案:尝试获取默认瓦片
if (manager.tileBaseMapping.TryGetValue("Default", out TileBase defaultTile))
if (manager.tileBaseMapping.TryGetValue("Default", out var defaultTile))
{
return defaultTile;
}

View File

@ -10,21 +10,7 @@ namespace Map
public Tilemap buildLevel;
public Tilemap plantLevel;
public void Start()
{
var perline= Utils.PerlinNoise.Instance;
var size = 100;
baseLevel.InitializeData(size, size);
for (var i = 0; i < size; i++) {
for (var j = 0; j < size; j++) {
var dx = i - size/2;
var dy = j - size/2;
baseLevel.mapData[i][j] = (int)(Math.Sqrt(dx*dx + dy*dy) / 5) & 1;
}
}
baseLevel.RefreshAllTiles();
}
public bool CanPassThrough(int x, int y)
{
return GetTilePassCost(x, y) < 1;

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AI;
using Base;
@ -37,11 +38,17 @@ namespace Prefab
public void DefaultInit()
{
var animator = GetComponentsInChildren<SpriteAnimator>();
ITick[] inf = animator;
entity.bodyAnimationNode.Add(Orientation.Down,inf.ToList());
entity.bodyAnimationNode.Add(Orientation.Up,inf.ToList());
entity.bodyAnimationNode.Add(Orientation.Left,inf.ToList());
entity.bodyAnimationNode.Add(Orientation.Right,inf.ToList());
var inf = animator.Cast<ITick>().ToList();
foreach (EntityState state in Enum.GetValues(typeof(EntityState)))
{
var orientationDict = new Dictionary<Orientation, List<ITick>>();
foreach (Orientation orientation in Enum.GetValues(typeof(Orientation)))
{
orientationDict[orientation] = inf; // 所有值都指向同一个列表
}
entity.bodyAnimationNode[state] = orientationDict;
}
outline.Init();
outline.Hide();
}

View File

@ -1,5 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Define>
<!-- 贴图部分 -->
<ImageDef>
<defName>testPawn</defName>
<path>res:Character/Test/Body/idle_down</path>
<wCount>5</wCount>
<hCount>1</hCount>
</ImageDef>
<!-- 人物定义 -->
<CharacterDef>
<defName>testPawn</defName>
<label>测试小人</label>
@ -10,10 +19,15 @@
</attributes>
<affiliation>player</affiliation>
<drawingOrder>
<texturePath>res:Character\Test</texturePath>
<drawingOrder_down>
<node name="Body" type="Animation" FPS="0.5"/>
</drawingOrder_down>
<idle_down name="Body" FPS="2">
<animationTextures>
<li>testPawn_0</li>
<li>testPawn_1</li>
<li>testPawn_2</li>
<li>testPawn_3</li>
<li>testPawn_4</li>
</animationTextures>
</idle_down>
</drawingOrder>
<behaviorTree>
<Node className="JobGiver_RandomWander"/>