From da7ba7269802d64d5268b99f3e1f8a6f06acfd0d Mon Sep 17 00:00:00 2001 From: GanX <2423855310@qq.com> Date: Sat, 18 Oct 2025 09:13:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(TimePause):=E6=97=B6=E9=97=B4=E6=9A=82?= =?UTF-8?q?=E5=81=9C=E7=AE=A1=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Prefab/Core/TimePauseManager.prefab | 47 +++++++++++++ .../Prefab/Core/TimePauseManager.prefab.meta | 7 ++ Assets/Scenes/Core.unity | 69 +++++++++++++++++++ Assets/Script/Gameplay/Global.meta | 3 + .../Gameplay/Global/TimePauseManager.cs | 53 ++++++++++++++ .../Gameplay/Global/TimePauseManager.cs.meta | 3 + 6 files changed, 182 insertions(+) create mode 100644 Assets/Prefab/Core/TimePauseManager.prefab create mode 100644 Assets/Prefab/Core/TimePauseManager.prefab.meta create mode 100644 Assets/Script/Gameplay/Global.meta create mode 100644 Assets/Script/Gameplay/Global/TimePauseManager.cs create mode 100644 Assets/Script/Gameplay/Global/TimePauseManager.cs.meta diff --git a/Assets/Prefab/Core/TimePauseManager.prefab b/Assets/Prefab/Core/TimePauseManager.prefab new file mode 100644 index 0000000..0e8cbf7 --- /dev/null +++ b/Assets/Prefab/Core/TimePauseManager.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5532734616494925005 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6144181697203329678} + - component: {fileID: 4918332973144301582} + m_Layer: 0 + m_Name: TimePauseManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6144181697203329678 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5532734616494925005} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.29564962, y: 4.269477, z: -1.7842796} + 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 &4918332973144301582 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5532734616494925005} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e0328f8bde4442bd8b7e093b40c1306e, type: 3} + m_Name: + m_EditorClassIdentifier: + _pauseToggle: 0 diff --git a/Assets/Prefab/Core/TimePauseManager.prefab.meta b/Assets/Prefab/Core/TimePauseManager.prefab.meta new file mode 100644 index 0000000..b387b5c --- /dev/null +++ b/Assets/Prefab/Core/TimePauseManager.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 781c629235eee4f4eb34f1e763aa7f67 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Core.unity b/Assets/Scenes/Core.unity index c7a5ba4..fd2610f 100644 --- a/Assets/Scenes/Core.unity +++ b/Assets/Scenes/Core.unity @@ -258,9 +258,78 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] 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 SceneRoots: m_ObjectHideFlags: 0 m_Roots: - {fileID: 6429745761262824323} - {fileID: 6277645971226662819} + - {fileID: 9054644576683853387} diff --git a/Assets/Script/Gameplay/Global.meta b/Assets/Script/Gameplay/Global.meta new file mode 100644 index 0000000..c845a51 --- /dev/null +++ b/Assets/Script/Gameplay/Global.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e9bc159ddf0a48aba6e9338d92c5e724 +timeCreated: 1760749356 \ No newline at end of file diff --git a/Assets/Script/Gameplay/Global/TimePauseManager.cs b/Assets/Script/Gameplay/Global/TimePauseManager.cs new file mode 100644 index 0000000..255ff48 --- /dev/null +++ b/Assets/Script/Gameplay/Global/TimePauseManager.cs @@ -0,0 +1,53 @@ +using UnityEngine; +using System; +using Core; + +namespace Script.Gameplay.Global +{ + /// + /// 全局时间暂停管理器。 + /// 单例,挂载到场景里任意常驻 GameObject(如 Managers)。 + /// + public class TimePauseManager : MonoSingleton + { + + /// 当前是否处于暂停状态 + public bool IsPaused { get; private set; } + + /// 暂停/恢复时触发,参数 true=暂停,false=恢复 + public event Action OnPauseStateChanged; + + [Header("调试按钮")] + [SerializeField] private bool _pauseToggle; + + private void OnValidate() + { + // Inspector 里打钩立即生效(仅 Editor) + if (Application.isPlaying && Instance == this) + SetPaused(_pauseToggle); + } + + + /// + /// 外部调用:设置暂停状态 + /// + public void SetPaused(bool pause) + { + if (IsPaused == pause) return; + + IsPaused = pause; + Time.timeScale = pause ? 0f : 1f; + OnPauseStateChanged?.Invoke(pause); + } + + /// + /// 快捷暂停 + /// + public static void Pause() => Instance.SetPaused(true); + + /// + /// 快捷恢复 + /// + public static void Resume() => Instance.SetPaused(false); + } +} \ No newline at end of file diff --git a/Assets/Script/Gameplay/Global/TimePauseManager.cs.meta b/Assets/Script/Gameplay/Global/TimePauseManager.cs.meta new file mode 100644 index 0000000..083a1dc --- /dev/null +++ b/Assets/Script/Gameplay/Global/TimePauseManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e0328f8bde4442bd8b7e093b40c1306e +timeCreated: 1760749366 \ No newline at end of file