diff --git a/Assets/Prefab/Gameplay/Manager.meta b/Assets/Prefab/Gameplay/Manager.meta new file mode 100644 index 0000000..8f89a24 --- /dev/null +++ b/Assets/Prefab/Gameplay/Manager.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 49ee637d3cf0ce241a071cfa66b2ad6c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefab/Core/GameCountDownManager.prefab b/Assets/Prefab/Gameplay/Manager/GameCountDownManager.prefab similarity index 100% rename from Assets/Prefab/Core/GameCountDownManager.prefab rename to Assets/Prefab/Gameplay/Manager/GameCountDownManager.prefab diff --git a/Assets/Prefab/Core/GameCountDownManager.prefab.meta b/Assets/Prefab/Gameplay/Manager/GameCountDownManager.prefab.meta similarity index 100% rename from Assets/Prefab/Core/GameCountDownManager.prefab.meta rename to Assets/Prefab/Gameplay/Manager/GameCountDownManager.prefab.meta diff --git a/Assets/Prefab/Core/GameFlowManager.prefab b/Assets/Prefab/Gameplay/Manager/GameFlowManager.prefab similarity index 100% rename from Assets/Prefab/Core/GameFlowManager.prefab rename to Assets/Prefab/Gameplay/Manager/GameFlowManager.prefab diff --git a/Assets/Prefab/Core/GameFlowManager.prefab.meta b/Assets/Prefab/Gameplay/Manager/GameFlowManager.prefab.meta similarity index 100% rename from Assets/Prefab/Core/GameFlowManager.prefab.meta rename to Assets/Prefab/Gameplay/Manager/GameFlowManager.prefab.meta diff --git a/Assets/Prefab/Gameplay/Manager/InputManager.prefab b/Assets/Prefab/Gameplay/Manager/InputManager.prefab new file mode 100644 index 0000000..8c00321 --- /dev/null +++ b/Assets/Prefab/Gameplay/Manager/InputManager.prefab @@ -0,0 +1,46 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5223255733355640781 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1586746027131230676} + - component: {fileID: 7124990002325753382} + m_Layer: 0 + m_Name: InputManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1586746027131230676 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5223255733355640781} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.51336026, y: 0.37061486, z: 1.5721664} + 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 &7124990002325753382 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5223255733355640781} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c9d73a7b65ad4d43a9587b5060528a3c, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefab/Gameplay/Manager/InputManager.prefab.meta b/Assets/Prefab/Gameplay/Manager/InputManager.prefab.meta new file mode 100644 index 0000000..f122fce --- /dev/null +++ b/Assets/Prefab/Gameplay/Manager/InputManager.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2a2113dbf189fbd44bca90f4df91f338 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefab/Core/TimePauseManager.prefab b/Assets/Prefab/Gameplay/Manager/TimePauseManager.prefab similarity index 100% rename from Assets/Prefab/Core/TimePauseManager.prefab rename to Assets/Prefab/Gameplay/Manager/TimePauseManager.prefab diff --git a/Assets/Prefab/Core/TimePauseManager.prefab.meta b/Assets/Prefab/Gameplay/Manager/TimePauseManager.prefab.meta similarity index 100% rename from Assets/Prefab/Core/TimePauseManager.prefab.meta rename to Assets/Prefab/Gameplay/Manager/TimePauseManager.prefab.meta diff --git a/Assets/Scenes/Level1.unity b/Assets/Scenes/Level1.unity index 7442d3f..1fe0a99 100644 --- a/Assets/Scenes/Level1.unity +++ b/Assets/Scenes/Level1.unity @@ -124,6 +124,74 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1001 &31717449 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalPosition.x + value: 0.51336026 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalPosition.y + value: 0.37061486 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalPosition.z + value: 1.5721664 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1586746027131230676, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5223255733355640781, guid: 2a2113dbf189fbd44bca90f4df91f338, + type: 3} + propertyPath: m_Name + value: InputManager + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 2a2113dbf189fbd44bca90f4df91f338, type: 3} --- !u!1 &370096296 GameObject: m_ObjectHideFlags: 0 @@ -1362,6 +1430,7 @@ SceneRoots: - {fileID: 1532480746} - {fileID: 1279118200} - {fileID: 769057572} + - {fileID: 31717449} - {fileID: 410087041} - {fileID: 1274249804} - {fileID: 7020889523296792185} diff --git a/Assets/Script/Core/GameManager.cs b/Assets/Script/Core/GameManager.cs index 60fc3a5..bc00a82 100644 --- a/Assets/Script/Core/GameManager.cs +++ b/Assets/Script/Core/GameManager.cs @@ -9,5 +9,10 @@ namespace Core { ScenesManager.Instance.LoadMainMenu(); } + + public void ReStartGame() + { + ScenesManager.Instance.LoadGameplay("Level1"); + } } } \ No newline at end of file diff --git a/Assets/Script/Gameplay/Global/GameFlowManager.cs b/Assets/Script/Gameplay/Global/GameFlowManager.cs index cf8c79c..fa23bba 100644 --- a/Assets/Script/Gameplay/Global/GameFlowManager.cs +++ b/Assets/Script/Gameplay/Global/GameFlowManager.cs @@ -1,5 +1,6 @@ using System; using Core; +using Script.Gameplay.Input; using UnityEngine; namespace Script.Gameplay.Global @@ -19,6 +20,13 @@ namespace Script.Gameplay.Global private void Start() { GameCountdownManager.Instance.StartLevelTimer(); + GameCountdownManager.Instance.OnFinish.AddListener(RestartGame); } + + public void RestartGame() + { + GameManager.Instance.ReStartGame(); + } + } } \ No newline at end of file diff --git a/Assets/Script/Gameplay/Input/InputManager.cs b/Assets/Script/Gameplay/Input/InputManager.cs index be29b80..4edca65 100644 --- a/Assets/Script/Gameplay/Input/InputManager.cs +++ b/Assets/Script/Gameplay/Input/InputManager.cs @@ -19,15 +19,25 @@ namespace Script.Gameplay.Input private bool _hasFocus = true; - private void Awake() + protected override void Awake() { Input = new PlayerInputActions(); + base.Awake(); } private void OnEnable() { Input.Enable(); + } + private void OnDisable() + { + // 可选:取消注册以防止重复订阅(简单项目可不解除) + Input.Disable(); + } + + private void Start() + { // 注册事件 Input.Player.Move.performed += ctx => Move = ctx.ReadValue(); Input.Player.Move.canceled += ctx => Move = Vector2.zero; @@ -46,16 +56,11 @@ namespace Script.Gameplay.Input Input.Player.Edit.performed += ctx => EditPressed = true; Input.Player.Edit.canceled += ctx => EditPressed = false; - } - - private void OnDisable() - { - // 可选:取消注册以防止重复订阅(简单项目可不解除) - Input.Disable(); - } - - private void Start() - { + + SetCursorState(false, CursorLockMode.Locked); + SetInputForLook(true); + SetInputForMove(true); + UIManager.Instance.RegisterInputManager(this); } diff --git a/Assets/Script/Gameplay/Interface/IDamageable.cs b/Assets/Script/Gameplay/Interface/IDamageable.cs new file mode 100644 index 0000000..e5c134a --- /dev/null +++ b/Assets/Script/Gameplay/Interface/IDamageable.cs @@ -0,0 +1,8 @@ +namespace Interface +{ + public interface IDamageable + { + public void TakeDamage(int damage); + public void Heal(int heal); + } +} \ No newline at end of file diff --git a/Assets/Script/Gameplay/Interface/IDamageable.cs.meta b/Assets/Script/Gameplay/Interface/IDamageable.cs.meta new file mode 100644 index 0000000..8f1ca96 --- /dev/null +++ b/Assets/Script/Gameplay/Interface/IDamageable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86b0cd642bb840a49e1ff26b4da53132 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/Gameplay/Player/PlayerController.cs b/Assets/Script/Gameplay/Player/PlayerController.cs index 200a5d4..e2ff605 100644 --- a/Assets/Script/Gameplay/Player/PlayerController.cs +++ b/Assets/Script/Gameplay/Player/PlayerController.cs @@ -5,43 +5,54 @@ using Gameplay; using Interface; using UnityEngine; using Core; +using Script.Gameplay.Global; namespace Gameplay.Player { - public class PlayerController : MonoBehaviour + public class PlayerController : MonoBehaviour, IDamageable { - public int MaxHealth { get; set; } = 100; - public int CurrentHealth { get; private set; } - - private int currentCardIndex = 0; - - public bool IsFlight { get; private set; } - public bool IsDead { get; private set; } - + [SerializeField] private int MaxHealth = 100; + + private int currentHealth; + public int CurrentHealth + { + get => currentHealth; + private set + { + currentHealth = value; + OnHealthChanged?.Invoke(currentHealth); + } + } + + public event Action OnHealthChanged; + public event Action OnDeath; + private PlayerMoveController playerMoveController; private PlayerCameraController playerCameraController; - private void Awake() { playerMoveController = GetComponent(); playerCameraController = GetComponent(); - + CurrentHealth = MaxHealth; - ControllerLocator.Instance.Register(this); } private void Start() { - - + OnDeath += GameFlowManager.Instance.RestartGame; } public void TakeDamage(int damage) { CurrentHealth -= damage; + if (CurrentHealth <= 0) + { + CurrentHealth = 0; + OnDeath?.Invoke(); + } } public void Heal(int heal) diff --git a/Assets/Script/Gameplay/UI/PlayerHpViewer.cs b/Assets/Script/Gameplay/UI/PlayerHpViewer.cs index bf85773..1434fc2 100644 --- a/Assets/Script/Gameplay/UI/PlayerHpViewer.cs +++ b/Assets/Script/Gameplay/UI/PlayerHpViewer.cs @@ -16,17 +16,20 @@ namespace UI ControllerLocator.Instance.TryGetWait(OnGet); } - private void Update() - { - if (_playerController != null) - { - hpText.text = "HP: " + _playerController.CurrentHealth; - } - } - private void OnGet(PlayerController playerController) { _playerController = playerController; + _playerController.OnHealthChanged += UpdateHpText; + } + + private void UpdateHpText(int currentHealth) + { + hpText.text = "HP: " + currentHealth; + } + + private void OnDestroy() + { + _playerController.OnHealthChanged -= UpdateHpText; } } } \ No newline at end of file