Merge remote-tracking branch 'origin/main' into main_ZYT

# Conflicts:
#	ProjectSettings/ProjectSettings.asset
This commit is contained in:
ZYT
2026-02-10 09:44:05 +08:00
5 changed files with 239 additions and 474 deletions

View File

@ -16927,71 +16927,6 @@ MonoBehaviour:
soundPlayedCustomEvent:
willCleanUpDelegatesAfterStop: 1
frames: 292
--- !u!1001 &60959280
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalPosition.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 110059260574252553, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 778228819167634611, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_Name
value: "\u4E00\u697C\u5927\u5385"
objectReference: {fileID: 0}
- target: {fileID: 778228819167634611, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9164575369691329967, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c27653af6b58d0f41b55c1c27aa97e8b, type: 3}
--- !u!1 &62262602
GameObject:
m_ObjectHideFlags: 0
@ -236040,4 +235975,3 @@ SceneRoots:
- {fileID: 1675573370}
- {fileID: 2076119386}
- {fileID: 882540217}
- {fileID: 60959280}

View File

@ -18222,39 +18222,6 @@ MonoBehaviour:
soundPlayedCustomEvent:
willCleanUpDelegatesAfterStop: 1
frames: 186
--- !u!1 &124580971
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 3718273381255731441, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 124580972}
m_Layer: 0
m_Name: "\u9655\u897F\u7701\u6986\u6797\u5E02\u795E\u6728\u5E02\u5927\u67F3\u5854\u9547\u67F3\u5174\u8857\u6109\u60A6\u57CE"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &124580972
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 124580971}
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:
- {fileID: 2035460422}
- {fileID: 2006520881}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &125567243
GameObject:
m_ObjectHideFlags: 0
@ -43081,7 +43048,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &385435103
Transform:
m_ObjectHideFlags: 0
@ -52178,6 +52145,7 @@ MonoBehaviour:
- {fileID: 6467094678931024558, guid: d21aeb4e16d2e8242809366ef3e398ed, type: 3}
- {fileID: 1190993079086344213, guid: 353ef808e5786c841a7dfec0a5f33815, type: 3}
- {fileID: 1190993079086344213, guid: 4ff253a5e7ebe8b4892b91f923b8f5cb, type: 3}
- {fileID: 3138103488680208938, guid: fd270e281173bf348a948a0a3a30594b, type: 3}
snapshotSettings:
bufferTimeMultiplier: 2
bufferLimit: 32
@ -83848,7 +83816,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &850007097
Transform:
m_ObjectHideFlags: 0
@ -123790,71 +123758,6 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1001 &1202835533
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 244553855343538860, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3718273381255731441, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_Name
value: "\u9655\u897F\u7701\u6986\u6797\u5E02\u795E\u6728\u5E02\u5927\u67F3\u5854\u9547\u67F3\u5174\u8857\u6109\u60A6\u57CE"
objectReference: {fileID: 0}
- target: {fileID: 3718273381255731441, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalPosition.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4094376089260491339, guid: d661600bff203f6478e421555f1c303b, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d661600bff203f6478e421555f1c303b, type: 3}
--- !u!1 &1203735222
GameObject:
m_ObjectHideFlags: 0
@ -128332,7 +128235,9 @@ MonoBehaviour:
winLightBgm: {fileID: 39165854}
goEffect: {fileID: 327597843}
place: 74
gameId: 0
gameId: 4
vistAllTime: 900
curGameTime: 0
--- !u!1 &1289206090
GameObject:
m_ObjectHideFlags: 0
@ -172150,89 +172055,6 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &2006520880
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 244553855343538860, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2006520881}
- component: {fileID: 2006520883}
- component: {fileID: 2006520882}
m_Layer: 0
m_Name: pPlane3
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &2006520881
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 2369737949588143504, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2006520880}
serializedVersion: 2
m_LocalRotation: {x: 0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0, y: 3.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 124580972}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &2006520882
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 3356245353950294368, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2006520880}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: fb8c6fc9a9a57a04aa81ead6f0796e95, 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: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &2006520883
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 5801310569238886532, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2006520880}
m_Mesh: {fileID: 3680687292192122401, guid: 76bc59a0ca6620d418c50e8131241685, type: 3}
--- !u!1 &2018898328
GameObject:
m_ObjectHideFlags: 0
@ -177670,89 +177492,6 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &2035460421
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 5078437167118830061, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2035460422}
- component: {fileID: 2035460424}
- component: {fileID: 2035460423}
m_Layer: 0
m_Name: pPlane2
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2035460422
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 7837393657706267004, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2035460421}
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: 124580972}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &2035460423
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 88514881801334066, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2035460421}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 2bb3eed0404231447a5670edef51ff1c, 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: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &2035460424
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 7977877648573520425, guid: d661600bff203f6478e421555f1c303b, type: 3}
m_PrefabInstance: {fileID: 1202835533}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2035460421}
m_Mesh: {fileID: 8342159127421523248, guid: 76bc59a0ca6620d418c50e8131241685, type: 3}
--- !u!1 &2035697192
GameObject:
m_ObjectHideFlags: 0
@ -186605,14 +186344,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!33 &557225772086009833
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8161851965909330540}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!95 &574245103758081559
Animator:
serializedVersion: 5
@ -186676,48 +186407,6 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!23 &662076648898845615
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8161851965909330540}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, 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: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &746642175336100363
GameObject:
m_ObjectHideFlags: 0
@ -202974,27 +202663,6 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8493800451832981579}
m_Mesh: {fileID: 2212009239438826721, guid: 7823e96608587e34dbbbe92f76716904, type: 3}
--- !u!65 &3279445844415349771
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8161851965909330540}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 2, y: 2, z: 2}
m_Center: {x: 0, y: 0, z: 0}
--- !u!111 &3312274170234899894
Animation:
m_ObjectHideFlags: 0
@ -208849,21 +208517,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4504842964232407134
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8161851965909330540}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.03, 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!4 &4531572566274289683
Transform:
m_ObjectHideFlags: 0
@ -230634,25 +230287,6 @@ ParticleSystemRenderer:
m_MeshWeighting2: 1
m_MeshWeighting3: 1
m_MaskInteraction: 0
--- !u!1 &8161851965909330540
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4504842964232407134}
- component: {fileID: 557225772086009833}
- component: {fileID: 662076648898845615}
- component: {fileID: 3279445844415349771}
m_Layer: 0
m_Name: Cube (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!1 &8210320216821701306
GameObject:
m_ObjectHideFlags: 0
@ -236315,7 +235949,6 @@ SceneRoots:
- {fileID: 1486842996}
- {fileID: 1723061463}
- {fileID: 1511208667}
- {fileID: 4504842964232407134}
- {fileID: 514640002}
- {fileID: 1028619366}
- {fileID: 327597842}
@ -236326,5 +235959,4 @@ SceneRoots:
- {fileID: 1675573370}
- {fileID: 2076119386}
- {fileID: 471303171}
- {fileID: 1202835533}
- {fileID: 873795326}

View File

@ -171,6 +171,11 @@ namespace Valheim
// 版本号
public GameKey gameId;
// 总游玩时长
public int vistAllTime = (int)(60 * 15F);
public float curGameTime = 0;
private NavMeshDataInstance currentInstance;
public void Close()
{
@ -267,5 +272,10 @@ namespace Valheim
// 加载新的NavMesh
currentInstance = NavMesh.AddNavMeshData(data);
}
public int GetNowTime()
{
return Mathf.RoundToInt(curGameTime);
}
}
}

View File

@ -100,10 +100,9 @@ namespace Valheim
#endif
[SyncVar]
public long vistEnd = 0;
// 总游玩时长
public int vistAllTime = (int)(60 * 15F);
public float curGameTime = 0;
// 游戏是否结束
[NonSerialized]
[SyncVar]
@ -284,10 +283,7 @@ namespace Valheim
battleArea.SetActive(false);
}
public int GetNowTime()
{
return Mathf.RoundToInt(curGameTime);
}
/// <summary>
/// 创建复活点
@ -547,7 +543,7 @@ namespace Valheim
{
obj.SetActive(false);
}
vistEnd = (long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + vistAllTime;
vistEnd = (long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + GameInit.Ins.vistAllTime;
CreateHUD();
GameInit.Ins.Close();
GameOver = false;
@ -1902,7 +1898,7 @@ namespace Valheim
if (isPlayGame)
{
curGameTime += Time.deltaTime;
GameInit.Ins.curGameTime += Time.deltaTime;
}
}
@ -2268,7 +2264,7 @@ namespace Valheim
string res = "";
if (GameOver)
{
res = FormatTime2((int)(((long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds) - (vistEnd - vistAllTime)));
res = FormatTime2((int)(((long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds) - (vistEnd - GameInit.Ins.vistAllTime)));
}
return res;
}

View File

@ -4,18 +4,43 @@ using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using UnityEngine;
using Valheim;
[Serializable]
public class IntentMessage
{
public string intent;
}
[Serializable]
public class PlayingStatusResponse
{
public int code;
public ServerData data;
public string message;
}
[Serializable]
public class ServerData
{
public string gameName;
public int gameTotalTime;
public int currentPlayTime;
}
public class HttpServer : MonoBehaviour
{
private HttpListener listener;
private Thread listenThread;
private Thread serverThread;
private volatile bool isRunning;
// ❗不要用 +
private const string SERVER_URL = "http://127.0.0.1:12345/";
private const string SERVER_URL = "http://+:12345/";
// 子线程 → 主线程
private static ConcurrentQueue<NetMessage> messageQueue = new ConcurrentQueue<NetMessage>();
void Awake()
{
@ -30,9 +55,10 @@ public class HttpServer : MonoBehaviour
// ✅ 后台启动
Task.Run(StartServer);
Debug.Log("Http,开始请求");
}
#region HTTP Server
private void StartServer()
{
try
@ -42,12 +68,11 @@ public class HttpServer : MonoBehaviour
listener.Start();
isRunning = true;
listenThread = new Thread(ListenLoop)
serverThread = new Thread(ListenLoop)
{
IsBackground = true
};
listenThread.Start();
serverThread.Start();
Debug.Log($"✅ HTTP Server 启动成功:{SERVER_URL}");
}
@ -59,37 +84,96 @@ public class HttpServer : MonoBehaviour
private void ListenLoop()
{
while (isRunning)
while (isRunning && listener.IsListening)
{
try
{
var context = listener.GetContext();
ProcessRequest(context);
ThreadPool.QueueUserWorkItem(ProcessRequest, context);
}
catch
catch (HttpListenerException)
{
break;
}
catch (Exception e)
{
Debug.LogError(e);
}
}
}
private void ProcessRequest(HttpListenerContext context)
private void ProcessRequest(object state)
{
var context = (HttpListenerContext)state;
var request = context.Request;
var response = context.Response;
response.AddHeader("Access-Control-Allow-Origin", "*");
response.AddHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
response.AddHeader("Access-Control-Allow-Headers", "Content-Type");
response.ContentType = "application/json; charset=utf-8";
try
{
string json =
$"{{\"code\":200,\"data\":{{\"gameName\":\"{GetGameName()}\"," +
$"\"gameTotalTime\":{GetTotalTime()},\"currentPlayTime\":{GetPlayTime()}}}}}";
if (request.HttpMethod == "POST")
{
string raw;
using (var reader = new StreamReader(
request.InputStream,
request.ContentEncoding ?? Encoding.UTF8))
{
raw = reader.ReadToEnd();
}
byte[] data = Encoding.UTF8.GetBytes(json);
response.OutputStream.Write(data, 0, data.Length);
Debug.Log($"📩 收到原始 JSON{raw}");
// 解析 intent
IntentMessage intentMsg = null;
try
{
intentMsg = JsonUtility.FromJson<IntentMessage>(raw);
}
catch (Exception e)
{
Debug.LogError("JSON 解析失败:" + e);
}
// 只处理 is_playing
if (intentMsg != null && intentMsg.intent == "is_playing")
{
var resp = new PlayingStatusResponse
{
code = 200,
data = new ServerData()
{
gameName = GetCurrentGameName(),
gameTotalTime = GetGameTotalTime(),
currentPlayTime = GetCurrentPlayTime()
},
message = "请求成功"
};
string json = JsonUtility.ToJson(resp);
Debug.LogError("数据:"+json);
byte[] data = Encoding.UTF8.GetBytes(json);
response.OutputStream.Write(data, 0, data.Length);
}
else
{
// 未知 intent
string err = "{\"code\":400,\"msg\":\"unknown intent\"}";
byte[] data = Encoding.UTF8.GetBytes(err);
response.OutputStream.Write(data, 0, data.Length);
}
response.Close();
return;
}
}
catch (Exception e)
{
Debug.LogError(e);
WriteResponse(response, 500, "error");
}
finally
{
@ -97,24 +181,133 @@ public class HttpServer : MonoBehaviour
}
}
private string GetGameName()
private void WriteResponse(HttpListenerResponse response, int code, string msg)
{
return GameInit.Ins != null ? GameInit.Ins.gameId.ToString() : "unknown";
string json = $"{{\"code\":{code},\"msg\":\"{msg}\"}}";
byte[] data = Encoding.UTF8.GetBytes(json);
response.OutputStream.Write(data, 0, data.Length);
}
private int GetTotalTime()
#endregion
#region Unity Main Thread
void Update()
{
return GameInit.Ins != null ? Mathf.FloorToInt(GameManager .Ins.vistAllTime) : 0;
while (messageQueue.TryDequeue(out var msg))
{
Debug.Log($"📩 来自 [{msg.sender}] 指令 [{msg.command}]");
HandleMessage(msg);
}
}
private int GetPlayTime()
#endregion
#region Message Logic
[Serializable]
public class NetMessage
{
return GameInit.Ins != null ? GameManager.Ins.GetNowTime() : 0;
public string sender;
public string command;
}
private NetMessage ParseMessage(string raw)
{
if (string.IsNullOrEmpty(raw))
return null;
try
{
raw = raw.Replace("\"", "").Trim();
var parts = raw.Split(':');
if (parts.Length != 2)
{
Debug.LogWarning($"消息格式错误:{raw}");
return null;
}
return new NetMessage
{
sender = parts[0].Trim(),
command = parts[1].Trim()
};
}
catch (Exception e)
{
Debug.LogError($"解析失败:{raw}\n{e}");
return null;
}
}
private void HandleMessage(NetMessage msg)
{
switch (msg.command)
{
case "isStart":
OnStartCommand(msg.sender);
break;
default:
Debug.LogWarning($"未知指令:{msg.command}");
break;
}
}
private void OnStartCommand(string sender)
{
Debug.Log($"🚀 Start 指令来自:{sender}");
// ✅ 在这里安全调用 Unity API
// GameManager.Ins.QuitGame();
}
private string GetCurrentGameName()
{
return GameInit.Ins.gameId.ToString(); // 或你自己的 GameManager
}
private int GetGameTotalTime()
{
return Mathf.FloorToInt(GameInit.Ins.vistAllTime); // 举例1 小时(秒)
}
private int GetCurrentPlayTime()
{
return GameInit.Ins.GetNowTime();
}
#endregion
#region Shutdown
void OnDestroy()
{
isRunning = false;
listener?.Close();
StopServer();
}
private void StopServer()
{
isRunning = false;
try
{
listener?.Stop();
listener?.Close();
}
catch { }
try
{
if (serverThread != null && serverThread.IsAlive)
serverThread.Join(300);
}
catch { }
Debug.Log("🛑 HTTP Server 已关闭");
}
#endregion
}