using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "GameManager", menuName = "Managers/GameManager")]
public class GameManagerSO : ScriptableObject
{
// 게임 일시 정지 상태
[HideInInspector] public bool isGamePaused;
// 플레이어 점수
[HideInInspector] public int score;
// 점수 추가
public void AddScore(int value)
{
score += value;
}
// 게임 일시 정지
public void PauseGame()
{
isGamePaused = true;
Time.timeScale = 0f;
}
// 게임 재개
public void ResumeGame()
{
isGamePaused = false;
Time.timeScale = 1f;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManagerRunner : MonoBehaviour
{
public GameManagerSO gameManager;
void Start()
{
// 시작 시 게임 재개 상태로 초기화
gameManager.ResumeGame();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "AudioManager", menuName = "Managers/AudioManager")]
public class AudioManagerSO : ScriptableObject
{
// 런타임에서 주입받는 AudioSource들
[HideInInspector] public AudioSource bgmSource;
[HideInInspector] public AudioSource sfxSource;
public void Init(AudioSource bgm, AudioSource sfx) // AudioSource를 외부에서 주입
{
bgmSource = bgm;
sfxSource = sfx;
}
// 배경음악 재생
public void PlayBGM(AudioClip clip)
{
if (bgmSource == null || clip == null) return;
bgmSource.clip = clip;
bgmSource.Play();
}
// 효과음 재생
public void PlaySFX(AudioClip clip)
{
if (sfxSource == null || clip == null) return;
sfxSource.PlayOneShot(clip);
}
// 배경음악 정지
public void StopBGM()
{
bgmSource?.Stop();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManagerRunner : MonoBehaviour // // AudioSource를 ScriptableObject에 연결하는 러너
{
public AudioManagerSO audioManager;
public AudioSource bgmSource;
public AudioSource sfxSource;
void Awake()
{
audioManager.Init(bgmSource, sfxSource); // 런타임 AudioSource 주입
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
[CreateAssetMenu(fileName = "SceneManager", menuName = "Managers/SceneManager")]
public class SceneTransitionManagerSO : ScriptableObject
{
// 이름으로 씬 로딩
public void LoadScene(string name)
{
SceneManager.LoadScene(name);
}
// 현재 씬 리로드
public void ReloadCurrentScene()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "InputManager", menuName = "Managers/InputManager")]
public class InputManagerSO : ScriptableObject
{
public KeyCode pauseKey = KeyCode.Escape;
// 일시 정지 키 입력 확인
public bool IsPausePressed()
{
return Input.GetKeyDown(pauseKey);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputManagerRunner : MonoBehaviour
{
public InputManagerSO inputManager;
public GameManagerSO gameManager;
public UIManagerSO uiManager;
void Update()
{
if (inputManager.IsPausePressed())
{
if (gameManager.isGamePaused)
{
gameManager.ResumeGame();
uiManager.ShowPauseUI(false);
}
else
{
gameManager.PauseGame();
uiManager.ShowPauseUI(true);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "UIManager", menuName = "Managers/UIManager")]
public class UIManagerSO : ScriptableObject
{
[HideInInspector] public GameObject pauseUI;
// UI 패널 객체 연결
public void Init(GameObject pausePanel)
{
pauseUI = pausePanel;
}
// 일시 정지 UI On/Off
public void ShowPauseUI(bool show)
{
if (pauseUI != null)
pauseUI.SetActive(show);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIManagerRunner : MonoBehaviour
{
public UIManagerSO uiManager;
public GameObject pausePanel;
void Awake()
{
uiManager.Init(pausePanel);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "ObjectPoolManager", menuName = "Managers/ObjectPoolManager")]
public class ObjectPoolManagerSO : ScriptableObject
{
// 풀 저장소 (key: 프리팹 이름)
private Dictionary<string, Queue<GameObject>> pool = new();
// 오브젝트 풀 생성
public void CreatePool(string key, GameObject prefab, int count)
{
if (!pool.ContainsKey(key))
pool[key] = new Queue<GameObject>();
for (int i = 0; i < count; i++)
{
GameObject obj = Instantiate(prefab);
obj.SetActive(false);
pool[key].Enqueue(obj);
}
}
// 풀에서 꺼내기
public GameObject Spawn(string key, Vector3 pos, Quaternion rot)
{
if (!pool.ContainsKey(key) || pool[key].Count == 0) return null;
GameObject obj = pool[key].Dequeue();
obj.transform.SetPositionAndRotation(pos, rot);
obj.SetActive(true);
return obj;
}
// 풀에 반환
public void Despawn(string key, GameObject obj)
{
obj.SetActive(false);
pool[key].Enqueue(obj);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPoolRunner : MonoBehaviour // 오브젝트 풀 매니저에 초기 풀 생성
{
public ObjectPoolManagerSO poolManager;
public GameObject prefab;
public string key = "Bullet";
void Awake()
{
poolManager.CreatePool(key, prefab, 20);
}
}
이후 필요 기술 R&D