From c8c1978aed166d38b9035888718101eeb0825ae1 Mon Sep 17 00:00:00 2001 From: Sehyeon Date: Thu, 17 Apr 2025 11:28:08 +0900 Subject: [PATCH] =?UTF-8?q?DEG-15=20[Feat]=20=EC=8A=A4=ED=83=AF=20?= =?UTF-8?q?=EC=A1=B0=EC=A0=95=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Editor.meta | 8 ++ Assets/Editor/ReadOnlyDrawer.cs | 24 +++++ Assets/Editor/ReadOnlyDrawer.cs.meta | 11 +++ Assets/KSH/GameConstants.cs | 37 ++++++- Assets/KSH/GameManager.cs | 49 +++++++++- Assets/KSH/PlayerStats.cs | 86 ++++++++++++++++ Assets/KSH/TestCode.meta | 8 ++ Assets/KSH/TestCode/PlayerStatsTest.cs | 103 ++++++++++++++++++++ Assets/KSH/TestCode/PlayerStatsTest.cs.meta | 11 +++ Assets/KSH/TestCode/Test.prefab | 3 + Assets/KSH/TestCode/Test.prefab.meta | 7 ++ Assets/KSH/ValueByAction.cs | 61 ++++++++++++ Assets/KSH/ValueByAction.cs.meta | 11 +++ 13 files changed, 413 insertions(+), 6 deletions(-) create mode 100644 Assets/Editor.meta create mode 100644 Assets/Editor/ReadOnlyDrawer.cs create mode 100644 Assets/Editor/ReadOnlyDrawer.cs.meta create mode 100644 Assets/KSH/TestCode.meta create mode 100644 Assets/KSH/TestCode/PlayerStatsTest.cs create mode 100644 Assets/KSH/TestCode/PlayerStatsTest.cs.meta create mode 100644 Assets/KSH/TestCode/Test.prefab create mode 100644 Assets/KSH/TestCode/Test.prefab.meta create mode 100644 Assets/KSH/ValueByAction.cs create mode 100644 Assets/KSH/ValueByAction.cs.meta 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/GameConstants.cs b/Assets/KSH/GameConstants.cs index 66c4bf53..61771aa4 100644 --- a/Assets/KSH/GameConstants.cs +++ b/Assets/KSH/GameConstants.cs @@ -2,9 +2,38 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; - - -public class GameConstants : MonoBehaviour +// 행동 타입 +public enum ActionType { - + NotSleep, // 5시간 미만 취침 + LessSleep, // 5시간 취침 + SleepWell, // 8시간 취침 + ForcedSleep, // 강제 수면(10시간) + Eat, + Work, + Dungeon, + // 보너스 스테이지 제외 + Housework, // 집안일 + OvertimeWork, // 야근 + TeamDinner, // 회식 + Absence // 결근 +} + +public class GameConstants +{ + // 기본 스탯 값 + public float baseHealth = 8f; + public float baseTime = 8f; + public float baseReputation = 5f; + + // 스탯 한계 값 + public float maxHealth = 10f; + public float maxTime = 24f; + public float maxReputation = 10f; + + // 강제 값 + public float forcedValue = 999f; + + // 날짜 한계 값 + public static int maxDays = 7; } diff --git a/Assets/KSH/GameManager.cs b/Assets/KSH/GameManager.cs index 73945d41..9be64878 100644 --- a/Assets/KSH/GameManager.cs +++ b/Assets/KSH/GameManager.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -5,8 +6,52 @@ 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; + + // 날짜 변경 이벤트 + public event Action OnDayChanged; + + private void Start() + { + // PlayerStats의 하루 종료 이벤트 구독 + if (playerStats == null) + { + playerStats = FindObjectOfType(); + if (playerStats == null) + { + Debug.LogError("PlayerStats 컴포넌트를 찾을 수 없습니다. 함께 추가해주세요."); + } + } + 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 @@ -17,11 +62,11 @@ public class GameManager : Singleton SceneManager.LoadScene("Housing"); // Home Scene } - // ToDo: Open Setting Panel 등 Panel 처리 + // TODO: Open Setting Panel 등 Panel 처리 protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode) { - // ToDo: 씬 로드 시 동작 구현. ex: BGM 변경 + // TODO: 씬 로드 시 동작 구현. ex: BGM 변경 // UI용 Canvas 찾기 // _canvas = GameObject.FindObjectOfType(); diff --git a/Assets/KSH/PlayerStats.cs b/Assets/KSH/PlayerStats.cs index e0ba559f..0dd56cfe 100644 --- a/Assets/KSH/PlayerStats.cs +++ b/Assets/KSH/PlayerStats.cs @@ -1,8 +1,94 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerStats : MonoBehaviour { + private GameConstants _gameConstants; + private ValueByAction _valueByAction; + public float Time { get; private set; } + public float Health { get; private set; } + public float Reputation { get; private set; } + + public event Action OnDayEnded; + + private void Start() + { + _gameConstants = new GameConstants(); + _valueByAction = new ValueByAction(); + _valueByAction.Initialize(); // 값 초기화 + + Health = _gameConstants.baseHealth; + Time = _gameConstants.baseTime; + Reputation = _gameConstants.baseReputation; + } + + // 행동 처리 메서드 + public void PerformAction(ActionType actionType) + { + // 액션에 따른 스탯 소모 값 가져오기 + ActionEffect effect = _valueByAction.GetActionEffect(actionType); + + // 스탯 변경 적용 + ModifyTime(effect.timeChange); + ModifyHealth(effect.healthChange); + ModifyReputation(effect.reputationChange); + } + + // 하루 종료 처리 + private void EndDay(bool isForced) //bool isForced? 해서 true면 강제 수면이라 8시에 깨는 + { + // 하루 종료 이벤트 발생 + OnDayEnded?.Invoke(); + + // 시간 리셋 + if (isForced) + { + Time = _gameConstants.baseTime; // 강제 수면일 시 아침 8시 기상 고정 + } + else + { + Time -= _gameConstants.maxTime; + } + } + + // 행동에 따른 내부 스탯 변경 메서드 + public void ModifyTime(float time) + { + Time += time; + + if (Time >= _gameConstants.maxTime) + { + if (time == _gameConstants.forcedValue) + { + EndDay(true); + } + else + { + EndDay(false); + } + } + } + + public void ModifyHealth(float health) + { + Health += health; + + if (Health > _gameConstants.maxHealth) + { + Health = _gameConstants.maxHealth; + } + } + + public void ModifyReputation(float reputation) + { + Reputation += reputation; + + if (Reputation > _gameConstants.maxReputation) + { + Reputation = _gameConstants.maxReputation; + } + } } 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..c16f496a --- /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.Time; + currentHealth = playerStats.Health; + currentReputation = playerStats.Reputation; + + // 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..03df3f7e --- /dev/null +++ b/Assets/KSH/ValueByAction.cs @@ -0,0 +1,61 @@ +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.NotSleep, new ActionEffect(_gameConstants.forcedValue, 0, 0) }, // 8시 강제 기상 + { ActionType.LessSleep, new ActionEffect(+5.0f, +6.0f, 0) }, + { ActionType.SleepWell, new ActionEffect(+8.0f, +8.0f, 0) }, + { ActionType.ForcedSleep, new ActionEffect(+10.0f, +4.0f, 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: