Refactor and reorganize scripts for improved structure and functionality

- Removed obsolete scripts: Chest, BreakableWall, Door, DoorInteract, and UiManager.
- Moved Chest and BreakableWall scripts to EnvironmentObjects folder.
- Introduced HammerThrower class to manage hammer throwing mechanics.
- Updated PlayerController to utilize new InputManager and HammerThrower.
- Refactored PlayerState to manage player state and item collection.
- Enhanced UI management in UiManager to reflect player item collection.
- Updated EnemyAI to remove unused movement logic.
- Adjusted KeyChest to interact with PlayerState instead of Player.
- Cleaned up code and improved event handling for item collection.
This commit is contained in:
2026-06-05 14:33:20 +03:00
parent 39294ec527
commit 7579175d24
33 changed files with 458 additions and 278 deletions
+30 -11
View File
@@ -1,24 +1,43 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
private InputActions _inputActions;
private InputActions _actions;
public event EventHandler<Vector2> OnMovementInput;
public event EventHandler OnFireButtonPressed;
public Vector2 Movement { get; private set; }
public event Action OnFire;
private void Awake()
{
_inputActions = new InputActions();
_inputActions.Player.Movement.performed += ctx => OnMovementInput?.Invoke(ctx.ReadValue<Vector2>());
_inputActions.Player.Fire.performed += ctx => OnFireButtonPressed?.Invoke();
_actions = new InputActions();
// Movement
_actions.Player.Movement.performed += OnMovementPerformed;
_actions.Player.Movement.canceled += OnMovementCanceled;
// Fire
_actions.Player.Fire.performed += ctx => OnFire?.Invoke();
}
private void OnEnable()
public void OnEnable()
{
_inputActions.Enable();
_actions.Enable();
}
private void OnDisable()
public void OnDisable()
{
_inputActions.Disable();
_actions.Disable();
}
}
private void OnMovementPerformed(InputAction.CallbackContext ctx)
{
Movement = ctx.ReadValue<Vector2>();
}
private void OnMovementCanceled(InputAction.CallbackContext ctx)
{
Movement = Vector2.zero;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 45d7bd38990996d4488582b07cbe7e40
+44
View File
@@ -0,0 +1,44 @@
using TMPro;
using UnityEngine;
public class UiManager : MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI _totalCoins;
[SerializeField]
private GameObject _keyIcon;
private PlayerState _playerState;
// Start is called before the first frame update
void Start()
{
_playerState = GetComponent<PlayerState>();
if (_playerState != null)
{
_playerState.OnPlayerTakeItem += UpdateUi;
}
}
private void UpdateUi(object sender, TreasureType e)
{
switch (e)
{
case TreasureType.Coin:
_totalCoins.text = _playerState.TotalCoins.ToString();
break;
case TreasureType.Key:
_keyIcon.SetActive(true);
break;
}
}
void OnDestroy()
{
if (_playerState != null)
{
_playerState.OnPlayerTakeItem -= UpdateUi;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ae8d1d59de450ae4e8be540c1a9d37ff