diff --git a/.idea/.idea.Degulleo3D/.idea/inspectionProfiles/Project_Default.xml b/.idea/.idea.Degulleo3D/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..dfb35ffb --- /dev/null +++ b/.idea/.idea.Degulleo3D/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Assets/Editor.meta b/Assets/Editor.meta new file mode 100644 index 00000000..d3e3b472 --- /dev/null +++ b/Assets/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fb977eee32cc2024181234437bfb8480 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/ReadOnlyDrawer.cs b/Assets/Editor/ReadOnlyDrawer.cs new file mode 100644 index 00000000..f28e0596 --- /dev/null +++ b/Assets/Editor/ReadOnlyDrawer.cs @@ -0,0 +1,24 @@ +#if UNITY_EDITOR +using UnityEngine; +using UnityEditor; + +// PlayerStatsTest.ReadOnlyAttribute를 위한 에디터 속성 드로어 +[CustomPropertyDrawer(typeof(PlayerStatsTest.ReadOnlyAttribute))] +public class ReadOnlyDrawer : PropertyDrawer +{ + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + // 이전 GUI 활성화 상태 저장 + bool wasEnabled = GUI.enabled; + + // 필드 비활성화 (읽기 전용) + GUI.enabled = false; + + // 속성 그리기 + EditorGUI.PropertyField(position, property, label, true); + + // GUI 활성화 상태 복원 + GUI.enabled = wasEnabled; + } +} +#endif \ No newline at end of file diff --git a/Assets/Editor/ReadOnlyDrawer.cs.meta b/Assets/Editor/ReadOnlyDrawer.cs.meta new file mode 100644 index 00000000..3f22dabf --- /dev/null +++ b/Assets/Editor/ReadOnlyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb5079b7064e2324890f78e18dfe7a6e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH.meta b/Assets/KSH.meta new file mode 100644 index 00000000..32286553 --- /dev/null +++ b/Assets/KSH.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8899b70334c78204fb97b6da706ac4c6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/GameConstants.cs b/Assets/KSH/GameConstants.cs new file mode 100644 index 00000000..2bd483bb --- /dev/null +++ b/Assets/KSH/GameConstants.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 행동 타입 +public enum ActionType +{ + Sleep, // 8시 기상 + OverSlept, // 결근-늦잠 + ForcedSleep, // 탈진(체력 0) + Eat, + Work, + Dungeon, + Housework, // 집안일 + OvertimeWork, // 야근 + TeamDinner, // 회식 + Absence // 결근 +} + +public class GameConstants +{ + // 기본 스탯 값 + public float baseHealth = 8f; + public float baseTime = 8f; + public float baseReputation = 2f; + + // 스탯 한계 값 + public float maxHealth = 10f; + public float maxTime = 24f; + public float maxReputation = 10f; + + // 체력 회복 한계 값 + public float limitRecover = 8.0f; + + // 기상 시간 + public float wakeUpTime = 8.0f; + + // 수면 이벤트 강제 값 + public float forcedValue = 999f; + + // 날짜 한계 값 + public static int maxDays = 7; +} diff --git a/Assets/KSH/GameConstants.cs.meta b/Assets/KSH/GameConstants.cs.meta new file mode 100644 index 00000000..7fb223ac --- /dev/null +++ b/Assets/KSH/GameConstants.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1e1682026c3858a4f8974675387aaf5a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/GameManager.cs b/Assets/KSH/GameManager.cs new file mode 100644 index 00000000..80b0725b --- /dev/null +++ b/Assets/KSH/GameManager.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class GameManager : Singleton +{ + [SerializeField] private PlayerStats playerStats; + + private Canvas _canvas; + + // 게임 진행 상태 + private int currentDay = 1; + public int CurrentDay => currentDay; + private int maxDays = GameConstants.maxDays; + + // 날짜 변경 이벤트, 추후에 UI 상의 날짜를 변경할 때 사용 + public event Action OnDayChanged; + + private void Start() + { + // PlayerStats의 하루 종료 이벤트 구독 + if (playerStats == null) + { + playerStats = FindObjectOfType(); + } + + if (playerStats == null) + { + Debug.LogError("PlayerStats 컴포넌트를 찾을 수 없습니다."); + return; + } + playerStats.OnDayEnded += AdvanceDay; + } + + // 날짜 진행 + public void AdvanceDay() + { + currentDay++; + OnDayChanged?.Invoke(currentDay); + + // 최대 일수 도달 체크 + if (currentDay > maxDays) + { + TriggerTimeEnding(); + } + } + + // 엔딩 트리거 + private void TriggerTimeEnding() + { + // TODO: 엔딩 처리 로직 + Debug.Log("7일이 지나 게임이 종료됩니다."); + } + + public void ChangeToGameScene() + { + SceneManager.LoadScene("Game"); // 던전 Scene + } + + public void ChangeToMainScene() + { + SceneManager.LoadScene("Housing"); // Home Scene + } + + // TODO: Open Setting Panel 등 Panel 처리 + + protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode) + { + // TODO: 씬 로드 시 동작 구현. ex: BGM 변경 + + // UI용 Canvas 찾기 + // _canvas = GameObject.FindObjectOfType(); + } + + private void OnDestroy() + { + if (playerStats != null) + { + playerStats.OnDayEnded -= AdvanceDay; // 이벤트 구독 해제 + } + } + + private void OnApplicationQuit() + { + // TODO: 게임 종료 시 로직 추가 + } +} diff --git a/Assets/KSH/GameManager.cs.meta b/Assets/KSH/GameManager.cs.meta new file mode 100644 index 00000000..7f546e24 --- /dev/null +++ b/Assets/KSH/GameManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 450038edae05f9b4d94ff56c62444048 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/PlayerStats.cs b/Assets/KSH/PlayerStats.cs new file mode 100644 index 00000000..703c3a1f --- /dev/null +++ b/Assets/KSH/PlayerStats.cs @@ -0,0 +1,196 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Random = UnityEngine.Random; + +public class PlayerStats : MonoBehaviour +{ + private GameConstants _gameConstants; + private ValueByAction _valueByAction; + + public float TimeStat { get; private set; } + public float HealthStat { get; private set; } + public float ReputationStat { get; private set; } + + public event Action OnDayEnded; + public event Action Exhaustion; // 탈진 + public event Action Overslept; // 결근(늦잠) + public event Action ZeroReputation; // 평판 0 이벤트 + + private float previousAddHealth = 0f; + + private void Start() + { + _gameConstants = new GameConstants(); + _valueByAction = new ValueByAction(); + _valueByAction.Initialize(); // 값 초기화 + + HealthStat = _gameConstants.baseHealth; + TimeStat = _gameConstants.baseTime; + ReputationStat = _gameConstants.baseReputation; + } + + // 현재 체력으로 해당 행동이 가능한 지 확인 + public bool CanPerformByHealth(ActionType actionType) + { + ActionEffect effect = _valueByAction.GetActionEffect(actionType); + + if (HealthStat >= effect.healthChange) + { + return true; + } + else + { + return false; + } + } + + // 행동 처리 메서드 + public void PerformAction(ActionType actionType) + { + // 액션에 따른 스탯 소모 값 가져오기 + ActionEffect effect = _valueByAction.GetActionEffect(actionType); + + // 스탯 변경 적용 + ModifyTime(effect.timeChange, actionType); + ModifyHealth(effect.healthChange); + ModifyReputation(effect.reputationChange); + } + + // 출근 가능 여부 확인 메서드 + public bool CanWork() + { + bool isTimeToWork = TimeStat is >= 8.0f and < 9.0f; // 8시에서 9시 사이만 true + bool isCanPerformWork = CanPerformByHealth(ActionType.Work); // 체력상 가능한지 확인 + + return isTimeToWork && isCanPerformWork; + } + + // 하루 종료 처리 + private void EndDay(float time, ActionType actionType) //bool isForced? 해서 true면 강제 수면이라 8시에 깨는 + { + bool isDayEnded = false; + + // 수면 행동 처리 + if (actionType == ActionType.Sleep || actionType == ActionType.TeamDinner) // 다음 날 오전 8시 기상 + { + // 다음 날 오전 8시 - 현재 시간 값 + float nowTime = TimeStat - time; + float remainTime = CalculateTimeToWakeUp(nowTime); + + TimeStat = _gameConstants.baseTime; // 아침 8시 기상 + + // 체력 회복 + ModifyHealth(remainTime); + + // 일반 수면의 경우, 시간이 8시 이후일 때만 하루가 종료된 것으로 판단 + isDayEnded = nowTime >= 8.0f; + + // 회복량이 8 이하면 늦잠 이벤트 발동 + if (remainTime < _gameConstants.limitRecover) + { + Debug.Log($"수면이 8시간 미만입니다. 수면 시간: {remainTime}"); + Overslept?.Invoke(); // 늦잠 이벤트 + } + } + else if (actionType == ActionType.OverSlept) // 늦잠, 오전 8시에 행동을 결정하기에 하루 지남 X + { + // 다음 날 오후 3~6시 사이 기상, 추가 체력 회복 + float randomWakeUpTime = Random.Range(15, 19); + TimeStat = randomWakeUpTime; + + // 추가 체력 회복 + float remainHealth = _gameConstants.limitRecover - previousAddHealth; // 체력 회복 총량 8 - 이전 회복 값 = 총 8회복 + ModifyHealth(remainHealth); + } + else if (actionType == ActionType.ForcedSleep) // 탈진 + { + // 오전 0~8시 사이에 잠들면 하루가 지나지 않은 것으로 처리 + float nowTime = TimeStat - time; + bool isEarlyMorning = nowTime >= 0 && nowTime < 8; + isDayEnded = !isEarlyMorning; + + // 다음 날 오후 3~6시 사이 기상 + float randomWakeUpTime = Random.Range(15, 19); + TimeStat = randomWakeUpTime; + } + else // 수면 이외의 행동 + { + isDayEnded = true; + TimeStat -= _gameConstants.maxTime; + } + + // 하루가 실제로 종료된 경우에만 이벤트 발생 + if (isDayEnded) + { + OnDayEnded?.Invoke(); + } + } + + public float CalculateTimeToWakeUp(float timeStat) + { + float wakeUpTime = _gameConstants.wakeUpTime; + if (timeStat < wakeUpTime) // 현재 시간이 0~7시 사이인 경우 + { + // 당일 오전 8시까지 남은 시간 + return wakeUpTime - timeStat; + } + else + { + return ( wakeUpTime + 24f ) - timeStat; // 다음 날 오전 8시까지 남은 시간 + } + } + + // 행동에 따른 내부 스탯 변경 메서드 + public void ModifyTime(float time, ActionType actionType) + { + TimeStat += time; + + if (TimeStat >= _gameConstants.maxTime) + { + EndDay(time, actionType); + } + } + + public void ModifyHealth(float health) + { + previousAddHealth = health; // 이전 회복량 저장 + HealthStat += health; + + // 혹시 모를 음수 값 처리 + if (HealthStat <= 0) + { + HealthStat = 0.0f; + // 현재는 0 되자마자 발생하도록 처리하였는데 다른 방식으로의 처리가 필요하다면 말씀해주십시오. + // 동작 이후에 스탯을 깎는다는 기준하에 작성하였습니다. (동작 전에는 CanPerformByHealth()를 통해 행동 가능 여부 판단) + + // 탈진 이벤트 발생 + Debug.Log("탈진! 체력 0"); + Exhaustion?.Invoke(); + } + + if (HealthStat > _gameConstants.maxHealth) + { + HealthStat = _gameConstants.maxHealth; + } + } + + public void ModifyReputation(float reputation) + { + // float 연산 시 계산 오차가 발생할 수도 있기에 소수점 두 번째에서 반올림하도록 처리 + ReputationStat = Mathf.Round((ReputationStat + reputation) * 100f) / 100f; + + if (ReputationStat <= 0) + { + Debug.Log("당신의 평판은 0입니다..;"); + ZeroReputation?.Invoke(); + ReputationStat = 0.0f; + } + + if (ReputationStat > _gameConstants.maxReputation) + { + ReputationStat = _gameConstants.maxReputation; + } + } +} diff --git a/Assets/KSH/PlayerStats.cs.meta b/Assets/KSH/PlayerStats.cs.meta new file mode 100644 index 00000000..448b945c --- /dev/null +++ b/Assets/KSH/PlayerStats.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8bccfaf46267e2544aa4bae52756f182 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/Singleton.cs b/Assets/KSH/Singleton.cs new file mode 100644 index 00000000..9cc4927b --- /dev/null +++ b/Assets/KSH/Singleton.cs @@ -0,0 +1,45 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public abstract class Singleton : MonoBehaviour where T : Component +{ + private static T _instance; + + public static T Instance + { + get + { + if (_instance == null) + { + _instance = FindObjectOfType(); + if (_instance == null) + { + GameObject obj = new GameObject(); + obj.name = typeof(T).Name; + _instance = obj.AddComponent(); + } + } + return _instance; + } + } + + void Awake() + { + if (_instance == null) + { + _instance = this as T; + DontDestroyOnLoad(gameObject); // obj가 destory 안되도록 설정 + + // 씬 전환시 호출되는 액션 메서드 할당 + SceneManager.sceneLoaded += OnSceneLoaded; + } + else + { + Destroy(gameObject); + } + } + + protected abstract void OnSceneLoaded(Scene scene, LoadSceneMode mode); +} diff --git a/Assets/KSH/Singleton.cs.meta b/Assets/KSH/Singleton.cs.meta new file mode 100644 index 00000000..477ec449 --- /dev/null +++ b/Assets/KSH/Singleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 014fe0082bc24a041a78cce62ba16b5d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/TestCode.meta b/Assets/KSH/TestCode.meta new file mode 100644 index 00000000..bc9a631b --- /dev/null +++ b/Assets/KSH/TestCode.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 533241c82a79dcc46932391bf865ce21 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/TestCode/PlayerStatsTest.cs b/Assets/KSH/TestCode/PlayerStatsTest.cs new file mode 100644 index 00000000..445d3f8b --- /dev/null +++ b/Assets/KSH/TestCode/PlayerStatsTest.cs @@ -0,0 +1,103 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerStatsTest : MonoBehaviour +{ + [Header("현재 스탯")] + [SerializeField, ReadOnly] private float currentTime; + [SerializeField, ReadOnly] private float currentHealth; + [SerializeField, ReadOnly] private float currentReputation; + [SerializeField, ReadOnly] private int currentDay; + + [Header("테스트 액션")] + [Tooltip("액션을 선택하고 체크박스를 체크하여 실행")] + [SerializeField] private ActionType actionToTest; + [SerializeField] private bool executeAction; + + // 컴포넌트 참조 + [Header("필수 참조")] + [SerializeField] private PlayerStats playerStats; + [SerializeField] private GameManager gameManager; + + // ReadOnly 속성 (인스펙터에서 수정 불가능하게 만듦) + public class ReadOnlyAttribute : PropertyAttribute { } + + private void Start() + { + // 참조 찾기 (없을 경우) + if (playerStats == null) + { + playerStats = FindObjectOfType(); + Debug.Log("PlayerStats를 찾아 참조했습니다."); + } + + if (gameManager == null) + { + gameManager = FindObjectOfType(); + Debug.Log("GameManager를 찾아 참조했습니다."); + } + + // 초기 스탯 표시 업데이트 + UpdateStatsDisplay(); + } + + private void Update() + { + if (Application.isPlaying) + { + // 매 프레임마다 스탯 업데이트 + UpdateStatsDisplay(); + + // 체크박스가 체크되면 선택된 액션 실행 + if (executeAction) + { + ExecuteSelectedAction(); + executeAction = false; // 체크박스 초기화 + } + } + } + + private void UpdateStatsDisplay() + { + // 참조 확인 후 스탯 업데이트 + if (playerStats != null) + { + currentTime = playerStats.TimeStat; + currentHealth = playerStats.HealthStat; + currentReputation = playerStats.ReputationStat; + + // GameManager에서 날짜 정보 가져오기 + if (gameManager != null) + { + currentDay = gameManager.CurrentDay; + } + else + { + Debug.LogWarning("GameManager 참조가 없습니다."); + } + } + else + { + Debug.LogWarning("PlayerStats 참조가 없습니다."); + } + } + + private void ExecuteSelectedAction() + { + if (playerStats != null) + { + // 선택한 액션 실행 + playerStats.PerformAction(actionToTest); + UpdateStatsDisplay(); + Debug.Log($"액션 실행: {actionToTest}"); + + // 콘솔에 현재 스탯 정보 출력 + Debug.Log($"현재 스탯 - 시간: {currentTime}, 체력: {currentHealth}, 평판: {currentReputation}, 날짜: {currentDay}"); + } + else + { + Debug.LogError("PlayerStats 참조가 없어 액션을 실행할 수 없습니다."); + } + } +} \ No newline at end of file diff --git a/Assets/KSH/TestCode/PlayerStatsTest.cs.meta b/Assets/KSH/TestCode/PlayerStatsTest.cs.meta new file mode 100644 index 00000000..6b74a38e --- /dev/null +++ b/Assets/KSH/TestCode/PlayerStatsTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ae7f2b39529d58a4fa75cf1d30dae9be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/TestCode/Test.prefab b/Assets/KSH/TestCode/Test.prefab new file mode 100644 index 00000000..b1d3b885 --- /dev/null +++ b/Assets/KSH/TestCode/Test.prefab @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a65e9dd60a7532ae1c4c43fda477ac0940c18c5c60f8a164b6fd52b9f1f4a42 +size 5196 diff --git a/Assets/KSH/TestCode/Test.prefab.meta b/Assets/KSH/TestCode/Test.prefab.meta new file mode 100644 index 00000000..0bbcf71a --- /dev/null +++ b/Assets/KSH/TestCode/Test.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 90448f678f8c503408de14c38cd7c653 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/KSH/ValueByAction.cs b/Assets/KSH/ValueByAction.cs new file mode 100644 index 00000000..594f0b7f --- /dev/null +++ b/Assets/KSH/ValueByAction.cs @@ -0,0 +1,60 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// 각 액션이 스탯에 미치는 영향을 담는 간단한 구조체 +public struct ActionEffect +{ + public float timeChange; + public float healthChange; + public float reputationChange; + + public ActionEffect(float time, float health, float reputation) + { + timeChange = time; + healthChange = health; + reputationChange = reputation; + } +} + +public class ValueByAction +{ + private GameConstants _gameConstants; + private Dictionary actionEffects; + + public void Initialize() + { + _gameConstants = new GameConstants(); + InitializeActionEffects(); + } + + private void InitializeActionEffects() + { + actionEffects = new Dictionary + { + // 기본 액션들, 효과(시간, 체력, 평판 순) + { ActionType.Sleep, new ActionEffect(_gameConstants.forcedValue, 0, 0) }, // 8시 강제 기상 + { ActionType.OverSlept, new ActionEffect(_gameConstants.forcedValue, 0, 0) }, // 결근 (오후 3~6시 기상) + { ActionType.ForcedSleep, new ActionEffect(_gameConstants.forcedValue, 4, 0) }, // 탈진 + { ActionType.Eat, new ActionEffect(+1.0f, +1.0f, 0) }, + { ActionType.Work, new ActionEffect(+10.0f, -3.0f, +0.2f) }, // 8to6: 10시간 + { ActionType.Dungeon, new ActionEffect(+3.0f, -3.0f, 0) }, + { ActionType.Housework, new ActionEffect(+1.0f, -1.0f, +0.2f) }, + { ActionType.OvertimeWork, new ActionEffect(+4.0f, -5.0f, +1.0f) }, + { ActionType.TeamDinner, new ActionEffect(_gameConstants.forcedValue, _gameConstants.forcedValue, 0) }, // 수면 강제(8시 기상) 후 최대 체력 + { ActionType.Absence, new ActionEffect(0, 0, -3.0f) } + }; + } + + // 액션에 따른 효과(스탯 가감) + public ActionEffect GetActionEffect(ActionType actionType) + { + if (actionEffects.TryGetValue(actionType, out ActionEffect effect)) + { + return effect; + } + + // 없으면 기본값 반환 + return new ActionEffect(0, 0, 0); + } +} diff --git a/Assets/KSH/ValueByAction.cs.meta b/Assets/KSH/ValueByAction.cs.meta new file mode 100644 index 00000000..4efa939c --- /dev/null +++ b/Assets/KSH/ValueByAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2aa1af61c6712fc45bf458c18cd2c874 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: