feat(TimePause):时间暂停管理器
This commit is contained in:
47
Assets/Prefab/Core/TimePauseManager.prefab
Normal file
47
Assets/Prefab/Core/TimePauseManager.prefab
Normal file
@@ -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
|
7
Assets/Prefab/Core/TimePauseManager.prefab.meta
Normal file
7
Assets/Prefab/Core/TimePauseManager.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 781c629235eee4f4eb34f1e763aa7f67
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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}
|
||||
|
3
Assets/Script/Gameplay/Global.meta
Normal file
3
Assets/Script/Gameplay/Global.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9bc159ddf0a48aba6e9338d92c5e724
|
||||
timeCreated: 1760749356
|
53
Assets/Script/Gameplay/Global/TimePauseManager.cs
Normal file
53
Assets/Script/Gameplay/Global/TimePauseManager.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using Core;
|
||||
|
||||
namespace Script.Gameplay.Global
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局时间暂停管理器。
|
||||
/// 单例,挂载到场景里任意常驻 GameObject(如 Managers)。
|
||||
/// </summary>
|
||||
public class TimePauseManager : MonoSingleton<TimePauseManager>
|
||||
{
|
||||
|
||||
/// <summary> 当前是否处于暂停状态 </summary>
|
||||
public bool IsPaused { get; private set; }
|
||||
|
||||
/// <summary> 暂停/恢复时触发,参数 true=暂停,false=恢复 </summary>
|
||||
public event Action<bool> OnPauseStateChanged;
|
||||
|
||||
[Header("调试按钮")]
|
||||
[SerializeField] private bool _pauseToggle;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
// Inspector 里打钩立即生效(仅 Editor)
|
||||
if (Application.isPlaying && Instance == this)
|
||||
SetPaused(_pauseToggle);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 外部调用:设置暂停状态
|
||||
/// </summary>
|
||||
public void SetPaused(bool pause)
|
||||
{
|
||||
if (IsPaused == pause) return;
|
||||
|
||||
IsPaused = pause;
|
||||
Time.timeScale = pause ? 0f : 1f;
|
||||
OnPauseStateChanged?.Invoke(pause);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 快捷暂停
|
||||
/// </summary>
|
||||
public static void Pause() => Instance.SetPaused(true);
|
||||
|
||||
/// <summary>
|
||||
/// 快捷恢复
|
||||
/// </summary>
|
||||
public static void Resume() => Instance.SetPaused(false);
|
||||
}
|
||||
}
|
3
Assets/Script/Gameplay/Global/TimePauseManager.cs.meta
Normal file
3
Assets/Script/Gameplay/Global/TimePauseManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0328f8bde4442bd8b7e093b40c1306e
|
||||
timeCreated: 1760749366
|
Reference in New Issue
Block a user