(client)feat:实现动画组件和图片组件预制体
This commit is contained in:
105
Client/Assets/Prefab/Animation.prefab
Normal file
105
Client/Assets/Prefab/Animation.prefab
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &5021031438404678310
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 8563418329714102965}
|
||||||
|
- component: {fileID: 2521950769040898791}
|
||||||
|
- component: {fileID: 2113064398104960506}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Animation
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &8563418329714102965
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5021031438404678310}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: -6.6943, y: -0.3652, 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!212 &2521950769040898791
|
||||||
|
SpriteRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5021031438404678310}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 0
|
||||||
|
m_ReceiveShadows: 0
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 0
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: 9dfc825aed78fcd4ba02077103263b40, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 0
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
|
m_DrawMode: 0
|
||||||
|
m_Size: {x: 1, y: 1}
|
||||||
|
m_AdaptiveModeThreshold: 0.5
|
||||||
|
m_SpriteTileMode: 0
|
||||||
|
m_WasSpriteAssigned: 1
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_SpriteSortPoint: 0
|
||||||
|
--- !u!114 &2113064398104960506
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5021031438404678310}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 713a1742950a45d8b4be258a82321e45, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_sprites: []
|
||||||
|
_fps: 2
|
||||||
|
_staticSprite: {fileID: 21300000, guid: 620e16cb0aec3684db9ef80bdcc85695, type: 3}
|
7
Client/Assets/Prefab/Animation.prefab.meta
Normal file
7
Client/Assets/Prefab/Animation.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ea9af70ce0f4c8b4a9de58ac63074156
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -203,6 +203,8 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: fbde354e0bcc4409b3378ee9b698ddc0, type: 3}
|
m_Script: {fileID: 11500000, guid: fbde354e0bcc4409b3378ee9b698ddc0, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
animatorPrefab: {fileID: 2113064398104960506, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
imagePrefab: {fileID: 1922746734790246249, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
direction: {x: 0, y: 0, z: 0}
|
direction: {x: 0, y: 0, z: 0}
|
||||||
body: {fileID: 2838206730318674270}
|
body: {fileID: 2838206730318674270}
|
||||||
affiliation:
|
affiliation:
|
||||||
@ -235,94 +237,6 @@ Transform:
|
|||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children:
|
m_Children: []
|
||||||
- {fileID: 1715998378632490765}
|
|
||||||
m_Father: {fileID: 697189026367054479}
|
m_Father: {fileID: 697189026367054479}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1 &3562938223049611414
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 1715998378632490765}
|
|
||||||
- component: {fileID: 2346928675516876702}
|
|
||||||
m_Layer: 0
|
|
||||||
m_Name: Square
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!4 &1715998378632490765
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 3562938223049611414}
|
|
||||||
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: 5549544358816209289}
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!212 &2346928675516876702
|
|
||||||
SpriteRenderer:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 3562938223049611414}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_CastShadows: 0
|
|
||||||
m_ReceiveShadows: 0
|
|
||||||
m_DynamicOccludee: 1
|
|
||||||
m_StaticShadowCaster: 0
|
|
||||||
m_MotionVectors: 1
|
|
||||||
m_LightProbeUsage: 1
|
|
||||||
m_ReflectionProbeUsage: 1
|
|
||||||
m_RayTracingMode: 0
|
|
||||||
m_RayTraceProcedural: 0
|
|
||||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
|
||||||
m_RayTracingAccelStructBuildFlags: 1
|
|
||||||
m_SmallMeshCulling: 1
|
|
||||||
m_RenderingLayerMask: 1
|
|
||||||
m_RendererPriority: 0
|
|
||||||
m_Materials:
|
|
||||||
- {fileID: 2100000, guid: 9dfc825aed78fcd4ba02077103263b40, type: 2}
|
|
||||||
m_StaticBatchInfo:
|
|
||||||
firstSubMesh: 0
|
|
||||||
subMeshCount: 0
|
|
||||||
m_StaticBatchRoot: {fileID: 0}
|
|
||||||
m_ProbeAnchor: {fileID: 0}
|
|
||||||
m_LightProbeVolumeOverride: {fileID: 0}
|
|
||||||
m_ScaleInLightmap: 1
|
|
||||||
m_ReceiveGI: 1
|
|
||||||
m_PreserveUVs: 0
|
|
||||||
m_IgnoreNormalsForChartDetection: 0
|
|
||||||
m_ImportantGI: 0
|
|
||||||
m_StitchLightmapSeams: 1
|
|
||||||
m_SelectedEditorRenderState: 0
|
|
||||||
m_MinimumChartSize: 4
|
|
||||||
m_AutoUVMaxDistance: 0.5
|
|
||||||
m_AutoUVMaxAngle: 89
|
|
||||||
m_LightmapParameters: {fileID: 0}
|
|
||||||
m_SortingLayerID: 0
|
|
||||||
m_SortingLayer: 0
|
|
||||||
m_SortingOrder: 0
|
|
||||||
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
|
|
||||||
m_Color: {r: 0.17278391, g: 0.7283019, b: 0.108558126, 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
|
|
||||||
|
106
Client/Assets/Prefab/Image.prefab
Normal file
106
Client/Assets/Prefab/Image.prefab
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &5309816858037840717
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 4201281305206751642}
|
||||||
|
- component: {fileID: 4449291717156169799}
|
||||||
|
- component: {fileID: 1922746734790246249}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Image
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &4201281305206751642
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5309816858037840717}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: -5.781, y: -0.39, 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!212 &4449291717156169799
|
||||||
|
SpriteRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5309816858037840717}
|
||||||
|
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: 620e16cb0aec3684db9ef80bdcc85695, type: 3}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
|
m_DrawMode: 0
|
||||||
|
m_Size: {x: 1, y: 1}
|
||||||
|
m_AdaptiveModeThreshold: 0.5
|
||||||
|
m_SpriteTileMode: 0
|
||||||
|
m_WasSpriteAssigned: 1
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_SpriteSortPoint: 0
|
||||||
|
--- !u!114 &1922746734790246249
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5309816858037840717}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 0c360a9f1baf4eaf9afa85617c395b0d, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_defaultSprite: {fileID: 21300000, guid: 620e16cb0aec3684db9ef80bdcc85695, type: 3}
|
||||||
|
_tintColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
_alpha: 1
|
||||||
|
_preserveAspect: 1
|
7
Client/Assets/Prefab/Image.prefab.meta
Normal file
7
Client/Assets/Prefab/Image.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a6657f26d735fab4690c8185980fda29
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -638,64 +638,6 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
entityManager: {fileID: 2036983433}
|
entityManager: {fileID: 2036983433}
|
||||||
--- !u!1001 &1730922965
|
|
||||||
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: -7.6344624
|
|
||||||
objectReference: {fileID: 0}
|
|
||||||
- target: {fileID: 697189026367054479, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
|
|
||||||
propertyPath: m_LocalPosition.y
|
|
||||||
value: -0.584403
|
|
||||||
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: EntityPrefab
|
|
||||||
objectReference: {fileID: 0}
|
|
||||||
m_RemovedComponents: []
|
|
||||||
m_RemovedGameObjects:
|
|
||||||
- {fileID: 3562938223049611414, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
|
|
||||||
m_AddedGameObjects: []
|
|
||||||
m_AddedComponents: []
|
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
|
|
||||||
--- !u!1 &2036983430
|
--- !u!1 &2036983430
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -801,6 +743,120 @@ Transform:
|
|||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1001 &4078005684296227559
|
||||||
|
PrefabInstance:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications:
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: -5.781
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: -0.39
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4201281305206751642, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5309816858037840717, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
propertyPath: m_Name
|
||||||
|
value: Image
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_RemovedGameObjects: []
|
||||||
|
m_AddedGameObjects: []
|
||||||
|
m_AddedComponents: []
|
||||||
|
m_SourcePrefab: {fileID: 100100000, guid: a6657f26d735fab4690c8185980fda29, type: 3}
|
||||||
|
--- !u!1001 &7665142047032752812
|
||||||
|
PrefabInstance:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications:
|
||||||
|
- target: {fileID: 5021031438404678310, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_Name
|
||||||
|
value: Animation
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: -7.758
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: -0.34
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8563418329714102965, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_RemovedGameObjects: []
|
||||||
|
m_AddedGameObjects: []
|
||||||
|
m_AddedComponents: []
|
||||||
|
m_SourcePrefab: {fileID: 100100000, guid: ea9af70ce0f4c8b4a9de58ac63074156, type: 3}
|
||||||
--- !u!1660057539 &9223372036854775807
|
--- !u!1660057539 &9223372036854775807
|
||||||
SceneRoots:
|
SceneRoots:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -811,4 +867,5 @@ SceneRoots:
|
|||||||
- {fileID: 309861630}
|
- {fileID: 309861630}
|
||||||
- {fileID: 2036983432}
|
- {fileID: 2036983432}
|
||||||
- {fileID: 1371068282}
|
- {fileID: 1371068282}
|
||||||
- {fileID: 1730922965}
|
- {fileID: 7665142047032752812}
|
||||||
|
- {fileID: 4078005684296227559}
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using AI;
|
using AI;
|
||||||
using Base;
|
using Base;
|
||||||
using Data;
|
using Data;
|
||||||
|
using Prefab;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
@ -10,6 +11,9 @@ namespace Entity
|
|||||||
{
|
{
|
||||||
public class Entity:MonoBehaviour,ITick
|
public class Entity:MonoBehaviour,ITick
|
||||||
{
|
{
|
||||||
|
public SpriteAnimator animatorPrefab;
|
||||||
|
public ImagePrefab imagePrefab;
|
||||||
|
|
||||||
public AIBase aiTree;
|
public AIBase aiTree;
|
||||||
public JobBase currentJob;
|
public JobBase currentJob;
|
||||||
public AttributesDef attributes;
|
public AttributesDef attributes;
|
||||||
@ -38,6 +42,8 @@ namespace Entity
|
|||||||
private bool _isPlayerControlled = false;
|
private bool _isPlayerControlled = false;
|
||||||
private bool _warning = false;
|
private bool _warning = false;
|
||||||
|
|
||||||
|
private Dictionary<Orientation,List<ITick>> bodyNode=new();
|
||||||
|
private Orientation currentOrientation=Orientation.Down;
|
||||||
|
|
||||||
public virtual void Init(PawnDef pawnDef)
|
public virtual void Init(PawnDef pawnDef)
|
||||||
{
|
{
|
||||||
@ -54,6 +60,8 @@ namespace Entity
|
|||||||
|
|
||||||
foreach (var orientation in orientations)
|
foreach (var orientation in orientations)
|
||||||
{
|
{
|
||||||
|
currentOrientation=orientation;
|
||||||
|
bodyNode[orientation]=new();
|
||||||
// 获取当前方向的绘图节点
|
// 获取当前方向的绘图节点
|
||||||
var drawNode = drawingOrder.GetDrawingOrder(orientation);
|
var drawNode = drawingOrder.GetDrawingOrder(orientation);
|
||||||
|
|
||||||
@ -63,32 +71,26 @@ namespace Entity
|
|||||||
|
|
||||||
InitBodyPart(drawNode, directionRoot);
|
InitBodyPart(drawNode, directionRoot);
|
||||||
}
|
}
|
||||||
|
currentOrientation=Orientation.Down;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 递归初始化单个绘图节点及其子节点
|
// 递归初始化单个绘图节点及其子节点
|
||||||
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent)
|
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent)
|
||||||
{
|
{
|
||||||
if(drawNode==null) return;
|
if(drawNode==null) return;
|
||||||
// 创建新的 GameObject 表示当前节点
|
|
||||||
var nodeObject = new GameObject(drawNode.nodeName);
|
|
||||||
|
|
||||||
// 设置节点的父对象
|
GameObject nodeObject;
|
||||||
nodeObject.transform.SetParent(parent.transform, false);
|
|
||||||
|
|
||||||
// 设置节点的位置
|
|
||||||
nodeObject.transform.localPosition = new Vector3(drawNode.position.x, drawNode.position.y, 0);
|
|
||||||
|
|
||||||
// 根据节点类型设置其他特性(例如动画或图片)
|
|
||||||
switch (drawNode.drawNodeType)
|
switch (drawNode.drawNodeType)
|
||||||
{
|
{
|
||||||
case DrawNodeType.Image:
|
case DrawNodeType.Image:
|
||||||
var spriteRenderer = nodeObject.AddComponent<SpriteRenderer>();
|
nodeObject = Instantiate(imagePrefab.gameObject);
|
||||||
spriteRenderer.color = Color.white; // 默认颜色
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DrawNodeType.Animation:
|
case DrawNodeType.Animation:
|
||||||
var animator = nodeObject.AddComponent<Animator>();
|
nodeObject = Instantiate(animatorPrefab.gameObject);
|
||||||
animator.runtimeAnimatorController = null; // 需要手动设置动画控制器
|
ITick tick = nodeObject.GetComponent<SpriteAnimator>();
|
||||||
|
if (tick != null)
|
||||||
|
bodyNode[currentOrientation].Add(tick);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
@ -110,6 +112,14 @@ namespace Entity
|
|||||||
{
|
{
|
||||||
AutoBehave();
|
AutoBehave();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var bodyPart in bodyNode.Values)
|
||||||
|
{
|
||||||
|
foreach (var tick in bodyPart)
|
||||||
|
{
|
||||||
|
tick.Tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void TryAttck()
|
public virtual void TryAttck()
|
||||||
|
@ -1,151 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Entity
|
|
||||||
{
|
|
||||||
public class SpriteAnimator : MonoBehaviour
|
|
||||||
{
|
|
||||||
// 引用 SpriteRenderer 组件
|
|
||||||
[SerializeField] private SpriteRenderer spriteRenderer;
|
|
||||||
|
|
||||||
// 精灵列表
|
|
||||||
[SerializeField] private Sprite[] sprites;
|
|
||||||
|
|
||||||
// 动画帧率 (Frames Per Second)
|
|
||||||
[SerializeField] private float fps = 10f;
|
|
||||||
|
|
||||||
// 是否暂停动画
|
|
||||||
[SerializeField] private bool isPaused = false;
|
|
||||||
|
|
||||||
// 暂停时显示的静态精灵索引 (-1 表示不显示静态精灵)
|
|
||||||
[SerializeField] private int staticSpriteIndex = -1;
|
|
||||||
|
|
||||||
// 当前帧索引
|
|
||||||
private int currentFrameIndex = 0;
|
|
||||||
|
|
||||||
// 帧间隔时间
|
|
||||||
private float frameInterval;
|
|
||||||
|
|
||||||
// 计时器
|
|
||||||
private float timer;
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
// 初始化帧间隔时间
|
|
||||||
frameInterval = 1f / fps;
|
|
||||||
|
|
||||||
// 如果指定了静态精灵索引,则直接显示静态精灵
|
|
||||||
if (staticSpriteIndex >= 0 && staticSpriteIndex < sprites.Length)
|
|
||||||
{
|
|
||||||
ShowStaticSprite(staticSpriteIndex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 否则从第一个精灵开始
|
|
||||||
UpdateSprite();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
// 如果暂停并且没有设置静态精灵,则不更新
|
|
||||||
if (isPaused && staticSpriteIndex == -1) return;
|
|
||||||
|
|
||||||
// 如果暂停并设置了静态精灵,则直接显示静态精灵
|
|
||||||
if (isPaused && staticSpriteIndex >= 0)
|
|
||||||
{
|
|
||||||
ShowStaticSprite(staticSpriteIndex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新计时器
|
|
||||||
timer += Time.deltaTime;
|
|
||||||
|
|
||||||
// 如果达到下一帧的时间间隔
|
|
||||||
if (timer >= frameInterval)
|
|
||||||
{
|
|
||||||
timer -= frameInterval; // 重置计时器
|
|
||||||
UpdateSprite(); // 更新精灵
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新当前显示的精灵
|
|
||||||
/// </summary>
|
|
||||||
private void UpdateSprite()
|
|
||||||
{
|
|
||||||
if (sprites.Length == 0) return; // 如果没有精灵,则退出
|
|
||||||
|
|
||||||
// 设置当前帧的精灵
|
|
||||||
spriteRenderer.sprite = sprites[currentFrameIndex];
|
|
||||||
|
|
||||||
// 循环播放:更新到下一帧
|
|
||||||
currentFrameIndex = (currentFrameIndex + 1) % sprites.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 显示静态精灵
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="index">静态精灵的索引</param>
|
|
||||||
private void ShowStaticSprite(int index)
|
|
||||||
{
|
|
||||||
if (index < 0 || index >= sprites.Length)
|
|
||||||
{
|
|
||||||
Debug.LogWarning("静态精灵索引超出范围!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示指定的静态精灵
|
|
||||||
spriteRenderer.sprite = sprites[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 开始播放动画
|
|
||||||
/// </summary>
|
|
||||||
public void PlayAnimation()
|
|
||||||
{
|
|
||||||
isPaused = false; // 取消暂停
|
|
||||||
staticSpriteIndex = -1; // 清除静态精灵索引
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 暂停动画并显示静态精灵
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="index">静态精灵的索引</param>
|
|
||||||
public void PauseAnimationWithStaticSprite(int index)
|
|
||||||
{
|
|
||||||
if (index < 0 || index >= sprites.Length)
|
|
||||||
{
|
|
||||||
Debug.LogWarning("静态精灵索引超出范围!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isPaused = true; // 暂停动画
|
|
||||||
staticSpriteIndex = index; // 设置静态精灵索引
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 暂停动画但不显示静态精灵
|
|
||||||
/// </summary>
|
|
||||||
public void PauseAnimation()
|
|
||||||
{
|
|
||||||
isPaused = true; // 暂停动画
|
|
||||||
staticSpriteIndex = -1; // 不显示静态精灵
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设置帧率
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="newFps">新的帧率</param>
|
|
||||||
public void SetFPS(float newFps)
|
|
||||||
{
|
|
||||||
if (newFps <= 0)
|
|
||||||
{
|
|
||||||
Debug.LogWarning("帧率必须大于 0!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fps = newFps;
|
|
||||||
frameInterval = 1f / fps; // 更新帧间隔时间
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
144
Client/Assets/Scripts/Prefab/ImagePrefab.cs
Normal file
144
Client/Assets/Scripts/Prefab/ImagePrefab.cs
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
using Base;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Prefab
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(SpriteRenderer))]
|
||||||
|
public class ImagePrefab : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("Display Settings")] [SerializeField]
|
||||||
|
private Sprite _defaultSprite;
|
||||||
|
|
||||||
|
[SerializeField] private Color _tintColor = Color.white;
|
||||||
|
[SerializeField, Range(0, 1)] private float _alpha = 1f;
|
||||||
|
[SerializeField] private bool _preserveAspect = true;
|
||||||
|
|
||||||
|
private SpriteRenderer _renderer;
|
||||||
|
private Vector2 _originalSize;
|
||||||
|
private bool _isInitialized;
|
||||||
|
|
||||||
|
public Sprite DisplayedSprite => _renderer.sprite;
|
||||||
|
public Color CurrentColor => _renderer.color;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
InitializeRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeRenderer()
|
||||||
|
{
|
||||||
|
if (_isInitialized) return;
|
||||||
|
|
||||||
|
_renderer = GetComponent<SpriteRenderer>();
|
||||||
|
|
||||||
|
// 初始尺寸记录
|
||||||
|
if (_defaultSprite != null)
|
||||||
|
{
|
||||||
|
_originalSize = new Vector2(
|
||||||
|
_defaultSprite.rect.width / _defaultSprite.pixelsPerUnit,
|
||||||
|
_defaultSprite.rect.height / _defaultSprite.pixelsPerUnit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置初始状态
|
||||||
|
ApplyVisualSettings();
|
||||||
|
_isInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyVisualSettings()
|
||||||
|
{
|
||||||
|
if (!_isInitialized) InitializeRenderer();
|
||||||
|
|
||||||
|
// 设置精灵和颜色
|
||||||
|
_renderer.sprite = _defaultSprite;
|
||||||
|
_renderer.color = new Color(_tintColor.r, _tintColor.g, _tintColor.b, _alpha);
|
||||||
|
|
||||||
|
// 保持原始纵横比
|
||||||
|
if (_preserveAspect && _defaultSprite != null)
|
||||||
|
{
|
||||||
|
MaintainAspectRatio();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MaintainAspectRatio()
|
||||||
|
{
|
||||||
|
Vector2 currentSize = transform.lossyScale;
|
||||||
|
float aspectRatio = _originalSize.x / _originalSize.y;
|
||||||
|
|
||||||
|
if (currentSize.x == 0 || currentSize.y == 0) return;
|
||||||
|
|
||||||
|
float currentAspect = currentSize.x / currentSize.y;
|
||||||
|
|
||||||
|
if (Mathf.Abs(currentAspect - aspectRatio) > 0.01f)
|
||||||
|
{
|
||||||
|
Vector2 newScale = currentSize;
|
||||||
|
if (currentAspect > aspectRatio)
|
||||||
|
{
|
||||||
|
newScale.x = currentSize.y * aspectRatio;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newScale.y = currentSize.x / aspectRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
transform.localScale = newScale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 公共控制方法
|
||||||
|
public void SetSprite(Sprite newSprite)
|
||||||
|
{
|
||||||
|
_defaultSprite = newSprite;
|
||||||
|
if (_defaultSprite != null)
|
||||||
|
{
|
||||||
|
_originalSize = new Vector2(
|
||||||
|
_defaultSprite.rect.width / _defaultSprite.pixelsPerUnit,
|
||||||
|
_defaultSprite.rect.height / _defaultSprite.pixelsPerUnit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyVisualSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetColor(Color newColor)
|
||||||
|
{
|
||||||
|
_tintColor = newColor;
|
||||||
|
ApplyVisualSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetAlpha(float newAlpha)
|
||||||
|
{
|
||||||
|
_alpha = Mathf.Clamp01(newAlpha);
|
||||||
|
ApplyVisualSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToggleVisibility(bool isVisible)
|
||||||
|
{
|
||||||
|
if (!_isInitialized) InitializeRenderer();
|
||||||
|
_renderer.enabled = isVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetSortingLayer(string layerName, int order)
|
||||||
|
{
|
||||||
|
if (!_isInitialized) InitializeRenderer();
|
||||||
|
_renderer.sortingLayerName = layerName;
|
||||||
|
_renderer.sortingOrder = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
private void OnValidate()
|
||||||
|
{
|
||||||
|
// 编辑器模式下实时预览变化
|
||||||
|
if (UnityEditor.EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
ApplyVisualSettings();
|
||||||
|
}
|
||||||
|
else if (GetComponent<SpriteRenderer>() != null)
|
||||||
|
{
|
||||||
|
GetComponent<SpriteRenderer>().sprite = _defaultSprite;
|
||||||
|
GetComponent<SpriteRenderer>().color = new Color(_tintColor.r, _tintColor.g, _tintColor.b, _alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
3
Client/Assets/Scripts/Prefab/ImagePrefab.cs.meta
Normal file
3
Client/Assets/Scripts/Prefab/ImagePrefab.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0c360a9f1baf4eaf9afa85617c395b0d
|
||||||
|
timeCreated: 1753331527
|
90
Client/Assets/Scripts/Prefab/SpriteAnimator.cs
Normal file
90
Client/Assets/Scripts/Prefab/SpriteAnimator.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using Base;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Prefab
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(SpriteRenderer))]
|
||||||
|
public class SpriteAnimator : MonoBehaviour, ITick
|
||||||
|
{
|
||||||
|
// 公开字段(可在编辑器中设置)
|
||||||
|
[SerializeField] private Sprite[] _sprites; // 动画精灵序列
|
||||||
|
[SerializeField] private float _fps = 2; // 每秒帧数
|
||||||
|
[SerializeField] private Sprite _staticSprite; // 暂停时的静态精灵
|
||||||
|
|
||||||
|
private SpriteRenderer _renderer; // 渲染器组件
|
||||||
|
private bool _isPaused; // 暂停状态
|
||||||
|
private float _frameTimer; // 帧计时器
|
||||||
|
private int _currentFrameIndex; // 当前帧索引
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
_renderer = GetComponent<SpriteRenderer>();
|
||||||
|
ValidateStartFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITick接口实现
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
var deltaTime=Time.deltaTime;
|
||||||
|
if (_isPaused)
|
||||||
|
{
|
||||||
|
HandlePausedState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayAnimation(deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ValidateStartFrame()
|
||||||
|
{
|
||||||
|
// 确保有精灵时可显示有效帧
|
||||||
|
if (_sprites != null && _sprites.Length > 0)
|
||||||
|
{
|
||||||
|
_currentFrameIndex = Mathf.Clamp(_currentFrameIndex, 0, _sprites.Length - 1);
|
||||||
|
_renderer.sprite = _sprites[_currentFrameIndex];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_renderer.sprite = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandlePausedState()
|
||||||
|
{
|
||||||
|
// 优先使用静态精灵,否则保持当前帧
|
||||||
|
if (_staticSprite)
|
||||||
|
{
|
||||||
|
_renderer.sprite = _staticSprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayAnimation(float deltaTime)
|
||||||
|
{
|
||||||
|
if (_sprites == null || _sprites.Length == 0) return;
|
||||||
|
|
||||||
|
// 更新帧计时器
|
||||||
|
_frameTimer += deltaTime;
|
||||||
|
float frameDuration = 1f / _fps;
|
||||||
|
|
||||||
|
// 检查帧切换条件
|
||||||
|
while (_frameTimer >= frameDuration)
|
||||||
|
{
|
||||||
|
_frameTimer -= frameDuration;
|
||||||
|
NextFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NextFrame()
|
||||||
|
{
|
||||||
|
// 循环播放动画
|
||||||
|
_currentFrameIndex = (_currentFrameIndex + 1) % _sprites.Length;
|
||||||
|
_renderer.sprite = _sprites[_currentFrameIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 外部控制方法
|
||||||
|
public void SetPaused(bool paused) => _isPaused = paused;
|
||||||
|
public void SetSprites(Sprite[] newSprites) => _sprites = newSprites;
|
||||||
|
public void SetFPS(float newFPS) => _fps = Mathf.Max(0.1f, newFPS);
|
||||||
|
public void SetStaticSprite(Sprite sprite) => _staticSprite = sprite;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user