코드 리팩토링
재사용성 및 확장성을 고려하여 코드 전반을 리팩토링함
This commit is contained in:
@@ -1,19 +1,42 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement; // 씬 재시작용
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Manages game state and responds to core destruction.
|
||||
/// </summary>
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
private bool _isGameOver = false;
|
||||
[SerializeField] private Core coreReference;
|
||||
|
||||
private void OnEnable()
|
||||
private bool _isGameOver = false;
|
||||
private HealthComponent _coreHealth;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Core의 파괴 이벤트를 구독
|
||||
Core.OnCoreDestroyed += GameOver;
|
||||
// Find Core if not assigned
|
||||
if (coreReference == null)
|
||||
{
|
||||
coreReference = FindFirstObjectByType<Core>();
|
||||
}
|
||||
|
||||
// Subscribe to core's health component
|
||||
if (coreReference != null)
|
||||
{
|
||||
_coreHealth = coreReference.Health;
|
||||
if (_coreHealth != null)
|
||||
{
|
||||
_coreHealth.OnDeath += GameOver;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
private void OnDestroy()
|
||||
{
|
||||
Core.OnCoreDestroyed -= GameOver;
|
||||
// Unsubscribe to prevent memory leaks
|
||||
if (_coreHealth != null)
|
||||
{
|
||||
_coreHealth.OnDeath -= GameOver;
|
||||
}
|
||||
}
|
||||
|
||||
private void GameOver()
|
||||
@@ -23,14 +46,13 @@ public class GameManager : MonoBehaviour
|
||||
_isGameOver = true;
|
||||
Debug.Log("Game Over! Core has been destroyed.");
|
||||
|
||||
// 여기에 패배 UI 표시 로직 등을 넣습니다.
|
||||
// 예: 3초 후 게임 재시작
|
||||
// Show defeat UI here
|
||||
// Example: restart game after 3 seconds
|
||||
Invoke(nameof(RestartGame), 3f);
|
||||
}
|
||||
|
||||
private void RestartGame()
|
||||
{
|
||||
// 현재 활성화된 씬을 다시 로드
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user