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
+17 -27
View File
@@ -3,18 +3,11 @@ using UnityEngine;
public class PlayerController : Character
{
[SerializeField]
private Transform _hammerSpawnPoint;
[SerializeField]
private GameObject _hammerPrefab;
[SerializeField]
private Sprite _regularSprite;
[SerializeField]
private Sprite _noHammerSprite;
public static Player Instance { get; private set; }
private GameObject _hammer;
private bool _isHoldingHammer = true;
@@ -23,32 +16,25 @@ public class PlayerController : Character
private InputManager _inputManager;
private PlayerState _playerState;
private HammerThrower _hammerThrower;
private void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
Debug.Log("There's more than one player instance");
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
_inputManager = new InputManager();
_inputManager = GetComponent<InputManager>();
_playerState = GetComponent<PlayerState>();
_hammerThrower = GetComponent<HammerThrower>();
_inputManager.OnMovementInput += OnMovementInput;
_inputManager.OnFireButtonPressed += OnFireButtonPressed;
_inputManager.OnFire += OnFireButtonPressed;
}
private void OnEnable()
{
_inputManager.Enable();
_inputManager.OnEnable();
}
private void OnDisable()
{
_inputManager.Disable();
_inputManager.OnDisable();
}
private void Update()
@@ -59,8 +45,8 @@ public class PlayerController : Character
_isHoldingHammer = true;
}
var move = _inputManager.OnMovementInput.ReadValue<Vector2>();
base.MoveTo(move.x, isAllowVertical ? move.y : 0);
Vector2 move = _inputManager.Movement;
MoveTo(move.x, isAllowVertical ? move.y : 0);
}
private void OnFireButtonPressed()
@@ -71,15 +57,19 @@ public class PlayerController : Character
}
}
// Animation event
public void ThrowHammerObject()
{
_isHoldingHammer = false;
_spriteRenderer.sprite = _noHammerSprite;
_hammer = Instantiate(_hammerPrefab, _hammerSpawnPoint.position, _hammerSpawnPoint.rotation);
_hammer.transform.localScale = new Vector2(_hammer.transform.localScale.x * (_facingRight ? 1 : -1), _hammer.transform.localScale.y);
_hammer.GetComponent<Rigidbody2D>().linearVelocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed, 0);
_hammerThrower.ThrowHammer();
UpdatePlayerSprite();
}
private void UpdatePlayerSprite()
{
_spriteRenderer.sprite = _hammerThrower.HasHammer
? _regularSprite
: _noHammerSprite;
}
protected override void SetWalkingAnimation(bool isWalking)
{
_bonesBack.SetActive(false);