Refactor player and enemy scripts; remove unused classes and improve initialization

- Added base initialization call in PlayerController.
- Changed player reference in EnemyAI to be serialized for better inspector visibility.
- Ensured characters are initialized upon spawning in EnemySpawner.
- Removed obsolete EnemyAI and Chest scripts to streamline codebase.
- Added KeyChest script for key collection functionality.
- Introduced new meta files for better organization and tracking.
- Created launch configuration for Unity debugging.
This commit is contained in:
2026-06-20 18:39:30 +03:00
parent 39e4e51866
commit ad6388f330
41 changed files with 200 additions and 786 deletions
-52
View File
@@ -1,52 +0,0 @@
using UnityEngine;
public class Chest : MonoBehaviour
{
[SerializeField]
private Animator animator;
[SerializeField]
private TreasureSO _treasureSO;
private Transform _treasureObject;
private bool _isOpen = false;
private void Awake()
{
_treasureObject = transform.GetChild(1);
var spriteRenderer = _treasureObject.GetComponent<SpriteRenderer>();
spriteRenderer.sprite = _treasureSO.Image;
}
private void OnTriggerEnter2D(Collider2D collider)
{
var playerState = collider.GetComponent<PlayerState>();
if (playerState != null && !_isOpen)
{
_isOpen = true;
animator.SetTrigger("OpenChest");
switch (_treasureSO.Treasure)
{
case TreasureType.Coin:
playerState.AddCoin();
if (GameManager.Instance != null)
{
GameManager.Instance.AddTreasure(1);
}
break;
case TreasureType.Key:
playerState.SetKey();
if (GameManager.Instance != null)
{
GameManager.Instance.SetKeyState(true);
}
if (LevelManager.Instance != null)
{
LevelManager.Instance.NotifyKeyCollected();
}
break;
}
}
}
}
-2
View File
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: ded23e667cffbfd46b2633ae22204797
-63
View File
@@ -1,63 +0,0 @@
using Assets.Scripts;
using System;
using UnityEngine;
public class Door : MonoBehaviour, IDoor
{
[SerializeField]
private Sprite _openDoor;
[SerializeField]
private bool _debugMode = false;
private SpriteRenderer _spriteRenderer;
private BoxCollider2D _boxCollider;
private bool _isLocked = true;
public bool IsLocked => _isLocked;
public event EventHandler OnDoorOpened;
private void Awake()
{
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
_boxCollider = gameObject.GetComponent<BoxCollider2D>();
}
public void OpenDoor()
{
if (!_isLocked)
return;
_isLocked = false;
// Update visuals
if (_spriteRenderer != null && _openDoor != null)
{
_spriteRenderer.sprite = _openDoor;
}
// Disable collision
if (_boxCollider != null)
{
_boxCollider.enabled = false;
}
if (_debugMode)
Debug.Log("[Door] Door opened!");
OnDoorOpened?.Invoke(this, EventArgs.Empty);
}
public void LockDoor()
{
_isLocked = true;
if (_boxCollider != null)
{
_boxCollider.enabled = true;
}
if (_debugMode)
Debug.Log("[Door] Door locked!");
}
}
-2
View File
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: af69aa896ad8a3947947ed21a9b9cacd
@@ -1,45 +0,0 @@
using Assets.Scripts;
using UnityEngine;
public class DoorInteract : MonoBehaviour
{
[SerializeField] private GameObject _doorGameObject;
[SerializeField] private bool _debugMode = false;
private IDoor _door;
private bool _hasTriggered = false;
private void Awake()
{
_door = _doorGameObject.GetComponent<IDoor>();
}
private void OnTriggerEnter2D(Collider2D collider)
{
if (_hasTriggered)
return;
var playerState = collider.GetComponent<PlayerState>();
if (playerState != null)
{
// Check if player has key through GameManager
if (GameManager.Instance != null && GameManager.Instance.HasKey)
{
_hasTriggered = true;
if (_debugMode)
Debug.Log("[DoorInteract] Player exiting with key!");
// Notify LevelManager that level is complete
if (LevelManager.Instance != null)
{
LevelManager.Instance.NotifyLevelComplete();
}
}
else if (_debugMode)
{
Debug.Log("[DoorInteract] Player reached door but does not have key!");
}
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 73fd9f6c116c2de4ab3d773fbb908df4
-37
View File
@@ -1,37 +0,0 @@
using UnityEngine;
public class KeyChest : MonoBehaviour
{
private bool _isOpened = false;
private void OnTriggerEnter2D(Collider2D collider)
{
if (_isOpened)
return;
var playerState = collider.GetComponent<PlayerState>();
if (playerState != null)
{
_isOpened = true;
// Update player state
playerState.SetKey();
// Notify GameManager of key collection
if (GameManager.Instance != null)
{
GameManager.Instance.SetKeyState(true);
}
// Notify LevelManager of key collection
if (LevelManager.Instance != null)
{
LevelManager.Instance.NotifyKeyCollected();
}
// Destroy the chest
Destroy(gameObject);
}
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: cf81d521c74041643b3e8f0569c55a0f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 87152ae05a4335f4cbf3907d245027eb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: