Compare commits

...

2 Commits

17 changed files with 714 additions and 74 deletions

View File

@@ -0,0 +1,54 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3918776012077598679
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4952453861214115371}
- component: {fileID: 593212677835339430}
m_Layer: 0
m_Name: GameCountDownManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4952453861214115371
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3918776012077598679}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 829.4015, y: 383.09033, z: 3.2512481}
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!114 &593212677835339430
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3918776012077598679}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bdaad0392e5549f0ac761238b649cc70, type: 3}
m_Name:
m_EditorClassIdentifier:
defaultDuration: 60
useUnscaledTime: 0
OnTick:
m_PersistentCalls:
m_Calls: []
OnFinish:
m_PersistentCalls:
m_Calls: []

View File

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

View File

@@ -0,0 +1,46 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2130934091406547798
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8520498794796434433}
- component: {fileID: 3291481944912255915}
m_Layer: 0
m_Name: GameFlowManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8520498794796434433
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2130934091406547798}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 829.4015, y: 383.09033, z: 3.2512481}
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!114 &3291481944912255915
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2130934091406547798}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8ff98d4d16514d27a14dc271bbbd19e7, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

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

View File

@@ -258,78 +258,9 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 03010dd3d718e374098805a9faf408ba, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 03010dd3d718e374098805a9faf408ba, type: 3}
--- !u!1001 &9054644576683853387
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5532734616494925005, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_Name
value: TimePauseManager
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalPosition.x
value: 0.29564962
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalPosition.y
value: 4.269477
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalPosition.z
value: -1.7842796
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 781c629235eee4f4eb34f1e763aa7f67, type: 3}
--- !u!1660057539 &9223372036854775807 --- !u!1660057539 &9223372036854775807
SceneRoots: SceneRoots:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_Roots: m_Roots:
- {fileID: 6429745761262824323} - {fileID: 6429745761262824323}
- {fileID: 6277645971226662819} - {fileID: 6277645971226662819}
- {fileID: 9054644576683853387}

View File

@@ -367,6 +367,74 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Interactable: 1 Interactable: 1
lockLevel: 0 lockLevel: 0
--- !u!1001 &769057572
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3918776012077598679, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_Name
value: GameCountDownManager
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalPosition.x
value: 829.4015
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalPosition.y
value: 383.09033
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalPosition.z
value: 3.2512481
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4952453861214115371, guid: 9e2e93bf07726014bac5a458c32e697f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 9e2e93bf07726014bac5a458c32e697f, type: 3}
--- !u!1 &856668955 --- !u!1 &856668955
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -683,6 +751,74 @@ 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 &1279118200
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2130934091406547798, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_Name
value: GameFlowManager
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalPosition.x
value: 829.4015
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalPosition.y
value: 383.09033
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalPosition.z
value: 3.2512481
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8520498794796434433, guid: f480e7d630901ad48a69a5df6d2132f2,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f480e7d630901ad48a69a5df6d2132f2, type: 3}
--- !u!1 &1304919964 --- !u!1 &1304919964
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -788,6 +924,74 @@ MeshFilter:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1304919964} m_GameObject: {fileID: 1304919964}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &1532480746
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5532734616494925005, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_Name
value: TimePauseManager
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalPosition.x
value: 0.29564962
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalPosition.y
value: 4.269477
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalPosition.z
value: -1.7842796
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6144181697203329678, guid: 781c629235eee4f4eb34f1e763aa7f67,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 781c629235eee4f4eb34f1e763aa7f67, type: 3}
--- !u!1 &1553269948 --- !u!1 &1553269948
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1190,6 +1394,9 @@ PrefabInstance:
SceneRoots: SceneRoots:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_Roots: m_Roots:
- {fileID: 1532480746}
- {fileID: 1279118200}
- {fileID: 769057572}
- {fileID: 410087041} - {fileID: 410087041}
- {fileID: 1274249804} - {fileID: 1274249804}
- {fileID: 7020889523296792185} - {fileID: 7020889523296792185}

View File

@@ -598,6 +598,99 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1200522801} m_GameObject: {fileID: 1200522801}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!1 &1349586404
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1349586405}
- component: {fileID: 1349586408}
- component: {fileID: 1349586407}
- component: {fileID: 1349586409}
m_Layer: 5
m_Name: CounDown
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1349586405
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1349586404}
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: 1780593834}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 1}
m_AnchorMax: {x: 0.5, y: 1}
m_AnchoredPosition: {x: 9.5458, y: -66}
m_SizeDelta: {x: 595.9615, y: 81.3619}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1349586407
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1349586404}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 50
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 5
m_MaxSize: 50
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: "\u5012\u8BA1\u65F6\uFF1A"
--- !u!222 &1349586408
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1349586404}
m_CullTransparentMesh: 1
--- !u!114 &1349586409
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1349586404}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1aa400ea9061498897f3c03b0336cfda, type: 3}
m_Name:
m_EditorClassIdentifier:
countdownText: {fileID: 1349586407}
--- !u!1 &1780593830 --- !u!1 &1780593830
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -695,6 +788,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1200522802} - {fileID: 1200522802}
- {fileID: 257151345} - {fileID: 257151345}
- {fileID: 1349586405}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}

View File

@@ -2,7 +2,8 @@
"name": "Core", "name": "Core",
"rootNamespace": "", "rootNamespace": "",
"references": [ "references": [
"GUID:75469ad4d38634e559750d17036d5f7c" "GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
], ],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],

View File

@@ -0,0 +1,108 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Core
{
/// <summary>
/// 通用计时器(正计时 / 倒计时均可)
/// 全程 UniTask无 GC支持暂停、继续、提前终止
/// </summary>
public sealed class UniTimer
{
public float Duration { get; private set; }
public float Elapsed { get; private set; }
public float Remaining => Mathf.Max(0, Duration - Elapsed);
public bool IsRunning { get; private set; }
public bool IsPaused { get; private set; }
/// <summary> 每帧回调:参数为当前已走时间 </summary>
public event Action<float> OnTick;
/// <summary> 计时结束回调 </summary>
public event Action OnComplete;
private CancellationTokenSource _cts;
private UniTaskCompletionSource<bool> _taskSource;
/*------------------------------------------------------*/
/// <summary>
/// 开始计时
/// </summary>
/// <param name="duration">时长(秒)</param>
/// <param name="isCountDown">true=倒计时false=正计时</param>
/// <param name="onTick">可选:每帧刷新</param>
/// <param name="onComplete">可选:结束回调</param>
public UniTask StartAsync(float duration,
bool isCountDown = false,
Action<float> onTick = null,
Action onComplete = null)
{
Stop(); // 先清理旧任务
_taskSource = new UniTaskCompletionSource<bool>(); // 新建
Duration = duration;
Elapsed = isCountDown ? duration : 0f;
OnTick = onTick;
OnComplete = onComplete;
IsRunning = true;
IsPaused = false;
_cts = new CancellationTokenSource();
return RunAsync(_cts.Token, isCountDown);
}
/// <summary> 立即终止(不可恢复) </summary>
public void Stop()
{
if (!IsRunning) return;
_cts?.Cancel();
_cts?.Dispose();
_cts = null;
IsRunning = false;
_taskSource?.TrySetCanceled(); // 提前终止也通知
IsPaused = false;
}
/// <summary> 暂停 </summary>
public void Pause() => IsPaused = true;
/// <summary> 继续 </summary>
public void Resume() => IsPaused = false;
/*------------------------------------------------------*/
private async UniTask RunAsync(System.Threading.CancellationToken token, bool countDown)
{
while (!token.IsCancellationRequested)
{
if (!IsPaused)
{
float dt = Time.deltaTime;
Elapsed += countDown ? -dt : dt;
// 触发回调
OnTick?.Invoke(Elapsed);
// 结束条件
if (countDown ? Elapsed <= 0f : Elapsed >= Duration)
{
Elapsed = countDown ? 0f : Duration;
OnTick?.Invoke(Elapsed); // 最后再给一次精确值
break;
}
}
await UniTask.Yield(PlayerLoopTiming.Update, token);
}
IsRunning = false;
_taskSource?.TrySetResult(true); // 广播“结束”
if (!token.IsCancellationRequested)
OnComplete?.Invoke();
}
public UniTask WaitForFinishAsync() => _taskSource?.Task ?? UniTask.CompletedTask;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7ddb70eec4a545f29d26f24f8370baae
timeCreated: 1760751050

View File

@@ -0,0 +1,89 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Events;
using Core;
namespace Script.Gameplay.Global
{
/// <summary>
/// 全局关卡倒计时管理器UniTimer 版)
/// </summary>
public sealed class GameCountdownManager : MonoSingleton<GameCountdownManager>
{
[Header("默认关卡时长(秒)")] [SerializeField] private float defaultDuration = 60f;
[Header("是否受 Time.timeScale 影响")] [SerializeField]
private bool useUnscaledTime = false;
[Header("事件:每秒刷新(剩余秒数)")] public UnityEvent<float> OnTick;
[Header("事件:倒计时结束")] public UnityEvent OnFinish;
private UniTimer _timer = new UniTimer();
/*------------------------------------------------------*/
protected override void Awake()
{
base.Awake();
// 确保事件实例化,避免其他脚本订阅时报 NullReferenceException
OnTick ??= new UnityEvent<float>();
OnFinish ??= new UnityEvent();
}
/// <summary>
/// 启动关卡倒计时(默认时长)
/// </summary>
public UniTask StartLevelTimer() => StartLevelTimer(defaultDuration);
/// <summary>
/// 启动关卡倒计时(指定时长)
/// </summary>
/// <param name="duration">秒</param>
public UniTask StartLevelTimer(float duration)
{
StopTimer(); // 先清掉旧计时器
// 用 unscaledDeltaTime 就不受 Time.timeScale 影响
Time.timeScale = 1f; // 可根据需求保留或去掉
return _timer.StartAsync(
duration,
isCountDown: true,
onTick: left => { OnTick?.Invoke(left); },
onComplete: () =>
{
OnFinish?.Invoke();
// 这里可以统一处理“时间到”逻辑
TimeOutHandle();
});
}
/// <summary> 暂停 </summary>
public void Pause() => _timer.Pause();
/// <summary> 继续 </summary>
public void Resume() => _timer.Resume();
/// <summary> 立即结束并触发 OnFinish </summary>
public void StopTimer() => _timer.Stop();
/// <summary> 剩余时间(秒) </summary>
public float Remaining => _timer.Remaining;
/// <summary> 是否正在跑 </summary>
public bool IsRunning => _timer.IsRunning;
/*------------------------------------------------------*/
// 统一处理“时间到”
private void TimeOutHandle()
{
Debug.Log("[GameCountdown] 关卡时间到!");
// 可以在这里弹 UI、播放音效、加载结算场景等
}
/*------------------------------------------------------*/
// 方便外部 await 等待结束
public UniTask WaitForTimeOutAsync() => _timer.WaitForFinishAsync();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bdaad0392e5549f0ac761238b649cc70
timeCreated: 1760751427

View File

@@ -0,0 +1,24 @@
using System;
using Core;
using UnityEngine;
namespace Script.Gameplay.Global
{
public enum GameState
{
Boot, // 初始化
MainMenu, // 主菜单
Playing, // 游戏中
Paused, // 暂停
GameOver, // 游戏结束
Victory // 胜利
}
public class GameFlowManager : MonoSingleton<GameFlowManager>
{
private void Start()
{
GameCountdownManager.Instance.StartLevelTimer();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8ff98d4d16514d27a14dc271bbbd19e7
timeCreated: 1760752445

View File

@@ -2,6 +2,7 @@ using System;
using Script.Gameplay.Input; using Script.Gameplay.Input;
using UnityEngine; using UnityEngine;
using Core; using Core;
using Script.Gameplay.Global;
namespace Gameplay.Player namespace Gameplay.Player
{ {
@@ -11,13 +12,16 @@ namespace Gameplay.Player
Inside, Inside,
Outside Outside
} }
public class PlayerWatchModeController : MonoBehaviour public class PlayerWatchModeController : MonoBehaviour
{ {
[SerializeField] private Camera cam; [SerializeField] private Camera cam;
public event Action OnEnterInsideWatchMode; public event Action OnEnterInsideWatchMode;
public event Action OnExitInsideWatchMode; public event Action OnExitInsideWatchMode;
private InputManager inputManager; private InputManager inputManager;
private TimePauseManager timePauseManager;
private WatchMode currentMode = WatchMode.Normal; private WatchMode currentMode = WatchMode.Normal;
public WatchMode CurrentWatchMode public WatchMode CurrentWatchMode
{ {
get => currentMode; get => currentMode;
@@ -27,10 +31,12 @@ namespace Gameplay.Player
{ {
OnExitInsideWatchMode?.Invoke(); OnExitInsideWatchMode?.Invoke();
} }
if (value == WatchMode.Inside) if (value == WatchMode.Inside)
{ {
OnEnterInsideWatchMode?.Invoke(); OnEnterInsideWatchMode?.Invoke();
} }
currentMode = value; currentMode = value;
SwitchWatchMode(currentMode); SwitchWatchMode(currentMode);
} }
@@ -39,13 +45,15 @@ namespace Gameplay.Player
private void Start() private void Start()
{ {
inputManager = InputManager.Instance; inputManager = InputManager.Instance;
timePauseManager = TimePauseManager.Instance;
var input = inputManager.Input; var input = inputManager.Input;
input.Player.SwitchWatchMode.performed += ctx => input.Player.SwitchWatchMode.performed += ctx =>
{ {
var modeTemp = (WatchMode)(((int)CurrentWatchMode + 1) % 3); var modeTemp = (WatchMode)(((int)CurrentWatchMode + 1) % 3);
CurrentWatchMode = modeTemp; CurrentWatchMode = modeTemp;
};; };
;
ControllerLocator.Instance.Register(this); ControllerLocator.Instance.Register(this);
} }
@@ -60,18 +68,33 @@ namespace Gameplay.Player
inputManager.SetCursorState(false, CursorLockMode.Locked); inputManager.SetCursorState(false, CursorLockMode.Locked);
inputManager.SetInputForLook(true); inputManager.SetInputForLook(true);
inputManager.SetInputForMove(true); inputManager.SetInputForMove(true);
if (timePauseManager != null)
{
timePauseManager.SetPaused(false);
}
break; break;
case WatchMode.Inside: case WatchMode.Inside:
SetSeeLines(false); SetSeeLines(false);
inputManager.SetCursorState(true, CursorLockMode.Confined); inputManager.SetCursorState(true, CursorLockMode.Confined);
inputManager.SetInputForLook(false); inputManager.SetInputForLook(false);
inputManager.SetInputForMove(false); inputManager.SetInputForMove(false);
if (timePauseManager != null)
{
timePauseManager.SetPaused(true);
}
break; break;
case WatchMode.Outside: case WatchMode.Outside:
SetSeeLines(true); SetSeeLines(true);
inputManager.SetCursorState(false, CursorLockMode.Locked); inputManager.SetCursorState(false, CursorLockMode.Locked);
inputManager.SetInputForLook(true); inputManager.SetInputForLook(true);
inputManager.SetInputForMove(true); inputManager.SetInputForMove(true);
if (timePauseManager != null)
{
timePauseManager.SetPaused(false);
}
break; break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();

View File

@@ -0,0 +1,37 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using Script.Gameplay.Global;
namespace UI
{
public class GameCountDownViewer : MonoBehaviour
{
public Text countdownText;
private GameCountdownManager _countdownManager;
private void Start()
{
_countdownManager = GameCountdownManager.Instance;
if (_countdownManager != null)
{
_countdownManager.OnTick.AddListener(UpdateCountdown);
}
}
public void UpdateCountdown(float secondsLeft)
{
if (countdownText != null)
{
int seconds = Mathf.CeilToInt(secondsLeft);
countdownText.text = "倒计时: " + seconds.ToString();
}
}
private void OnDestroy()
{
if (_countdownManager != null)
{
_countdownManager.OnTick.RemoveListener(UpdateCountdown);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1aa400ea9061498897f3c03b0336cfda
timeCreated: 1760751782