DEG-15 [Feat] 스탯 조정 스크립트 추가

This commit is contained in:
Sehyeon 2025-04-17 11:28:08 +09:00
parent 9a241056a0
commit c8c1978aed
13 changed files with 413 additions and 6 deletions

8
Assets/Editor.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fb977eee32cc2024181234437bfb8480
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb5079b7064e2324890f78e18dfe7a6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}

View File

@ -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<GameManager>
{
[SerializeField] private PlayerStats playerStats;
private Canvas _canvas;
// 게임 진행 상태
private int currentDay = 1;
public int CurrentDay => currentDay;
private int maxDays = GameConstants.maxDays;
// 날짜 변경 이벤트
public event Action<int> OnDayChanged;
private void Start()
{
// PlayerStats의 하루 종료 이벤트 구독
if (playerStats == null)
{
playerStats = FindObjectOfType<PlayerStats>();
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<GameManager>
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<Canvas>();

View File

@ -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;
}
}
}

8
Assets/KSH/TestCode.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 533241c82a79dcc46932391bf865ce21
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<PlayerStats>();
Debug.Log("PlayerStats를 찾아 참조했습니다.");
}
if (gameManager == null)
{
gameManager = FindObjectOfType<GameManager>();
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 참조가 없어 액션을 실행할 수 없습니다.");
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae7f2b39529d58a4fa75cf1d30dae9be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5a65e9dd60a7532ae1c4c43fda477ac0940c18c5c60f8a164b6fd52b9f1f4a42
size 5196

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 90448f678f8c503408de14c38cd7c653
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<ActionType, ActionEffect> actionEffects;
public void Initialize()
{
_gameConstants = new GameConstants();
InitializeActionEffects();
}
private void InitializeActionEffects()
{
actionEffects = new Dictionary<ActionType, ActionEffect>
{
// 기본 액션들, 효과(시간, 체력, 평판 순)
{ 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);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2aa1af61c6712fc45bf458c18cd2c874
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: