chore():整理了一下文件夹和玩家的血量逻辑

This commit is contained in:
2025-10-18 15:41:43 +08:00
parent ab403fac4b
commit b709d1219f
17 changed files with 214 additions and 33 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 49ee637d3cf0ce241a071cfa66b2ad6c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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:

View File

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

View File

@@ -124,6 +124,74 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 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 --- !u!1 &370096296
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1362,6 +1430,7 @@ SceneRoots:
- {fileID: 1532480746} - {fileID: 1532480746}
- {fileID: 1279118200} - {fileID: 1279118200}
- {fileID: 769057572} - {fileID: 769057572}
- {fileID: 31717449}
- {fileID: 410087041} - {fileID: 410087041}
- {fileID: 1274249804} - {fileID: 1274249804}
- {fileID: 7020889523296792185} - {fileID: 7020889523296792185}

View File

@@ -9,5 +9,10 @@ namespace Core
{ {
ScenesManager.Instance.LoadMainMenu(); ScenesManager.Instance.LoadMainMenu();
} }
public void ReStartGame()
{
ScenesManager.Instance.LoadGameplay("Level1");
}
} }
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using Core; using Core;
using Script.Gameplay.Input;
using UnityEngine; using UnityEngine;
namespace Script.Gameplay.Global namespace Script.Gameplay.Global
@@ -19,6 +20,13 @@ namespace Script.Gameplay.Global
private void Start() private void Start()
{ {
GameCountdownManager.Instance.StartLevelTimer(); GameCountdownManager.Instance.StartLevelTimer();
GameCountdownManager.Instance.OnFinish.AddListener(RestartGame);
} }
public void RestartGame()
{
GameManager.Instance.ReStartGame();
}
} }
} }

View File

@@ -19,15 +19,25 @@ namespace Script.Gameplay.Input
private bool _hasFocus = true; private bool _hasFocus = true;
private void Awake() protected override void Awake()
{ {
Input = new PlayerInputActions(); Input = new PlayerInputActions();
base.Awake();
} }
private void OnEnable() private void OnEnable()
{ {
Input.Enable(); Input.Enable();
}
private void OnDisable()
{
// 可选:取消注册以防止重复订阅(简单项目可不解除)
Input.Disable();
}
private void Start()
{
// 注册事件 // 注册事件
Input.Player.Move.performed += ctx => Move = ctx.ReadValue<Vector2>(); Input.Player.Move.performed += ctx => Move = ctx.ReadValue<Vector2>();
Input.Player.Move.canceled += ctx => Move = Vector2.zero; 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.performed += ctx => EditPressed = true;
Input.Player.Edit.canceled += ctx => EditPressed = false; Input.Player.Edit.canceled += ctx => EditPressed = false;
}
SetCursorState(false, CursorLockMode.Locked);
private void OnDisable() SetInputForLook(true);
{ SetInputForMove(true);
// 可选:取消注册以防止重复订阅(简单项目可不解除)
Input.Disable();
}
private void Start()
{
UIManager.Instance.RegisterInputManager(this); UIManager.Instance.RegisterInputManager(this);
} }

View File

@@ -0,0 +1,8 @@
namespace Interface
{
public interface IDamageable
{
public void TakeDamage(int damage);
public void Heal(int heal);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 86b0cd642bb840a49e1ff26b4da53132
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -5,43 +5,54 @@ using Gameplay;
using Interface; using Interface;
using UnityEngine; using UnityEngine;
using Core; using Core;
using Script.Gameplay.Global;
namespace Gameplay.Player namespace Gameplay.Player
{ {
public class PlayerController : MonoBehaviour public class PlayerController : MonoBehaviour, IDamageable
{ {
public int MaxHealth { get; set; } = 100; [SerializeField] private int MaxHealth = 100;
public int CurrentHealth { get; private set; }
private int currentHealth;
private int currentCardIndex = 0; public int CurrentHealth
{
public bool IsFlight { get; private set; } get => currentHealth;
public bool IsDead { get; private set; } private set
{
currentHealth = value;
OnHealthChanged?.Invoke(currentHealth);
}
}
public event Action<int> OnHealthChanged;
public event Action OnDeath;
private PlayerMoveController playerMoveController; private PlayerMoveController playerMoveController;
private PlayerCameraController playerCameraController; private PlayerCameraController playerCameraController;
private void Awake() private void Awake()
{ {
playerMoveController = GetComponent<PlayerMoveController>(); playerMoveController = GetComponent<PlayerMoveController>();
playerCameraController = GetComponent<PlayerCameraController>(); playerCameraController = GetComponent<PlayerCameraController>();
CurrentHealth = MaxHealth; CurrentHealth = MaxHealth;
ControllerLocator.Instance.Register(this); ControllerLocator.Instance.Register(this);
} }
private void Start() private void Start()
{ {
OnDeath += GameFlowManager.Instance.RestartGame;
} }
public void TakeDamage(int damage) public void TakeDamage(int damage)
{ {
CurrentHealth -= damage; CurrentHealth -= damage;
if (CurrentHealth <= 0)
{
CurrentHealth = 0;
OnDeath?.Invoke();
}
} }
public void Heal(int heal) public void Heal(int heal)

View File

@@ -16,17 +16,20 @@ namespace UI
ControllerLocator.Instance.TryGetWait<PlayerController>(OnGet); ControllerLocator.Instance.TryGetWait<PlayerController>(OnGet);
} }
private void Update()
{
if (_playerController != null)
{
hpText.text = "HP: " + _playerController.CurrentHealth;
}
}
private void OnGet(PlayerController playerController) private void OnGet(PlayerController playerController)
{ {
_playerController = playerController; _playerController = playerController;
_playerController.OnHealthChanged += UpdateHpText;
}
private void UpdateHpText(int currentHealth)
{
hpText.text = "HP: " + currentHealth;
}
private void OnDestroy()
{
_playerController.OnHealthChanged -= UpdateHpText;
} }
} }
} }