Merge pull request #8 from Degulleo/DEG-75-일상-활동별-함수-작성

사물 상호작용 구현, 플레이어 스탯과 연동
This commit is contained in:
HaeinLEE117 2025-04-21 13:53:05 +09:00 committed by GitHub
commit 5582fa7ab4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 2603 additions and 109 deletions

View File

@ -36,14 +36,7 @@ public class PlayerStats : MonoBehaviour
{ {
ActionEffect effect = _valueByAction.GetActionEffect(actionType); ActionEffect effect = _valueByAction.GetActionEffect(actionType);
if (HealthStat >= effect.healthChange) return (HealthStat >= (effect.healthChange * -1));
{
return true;
}
else
{
return false;
}
} }
// 행동 처리 메서드 // 행동 처리 메서드

8
Assets/LIN.meta Normal file
View File

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

View File

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

View File

@ -0,0 +1,100 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
[RequireComponent(typeof(Rigidbody))]
public class InteractionController : MonoBehaviour
{
[SerializeField] PlayerStats playerStats;
[SerializeField] LayerMask interactionLayerMask;
[FormerlySerializedAs("housingCanvasManager")]
[Header("UI 연동")]
[SerializeField] HousingCanvasController housingCanvasController;
// 상호작용 가능한 사물 범위에 들어올 때
private void OnTriggerEnter(Collider other)
{
if (interactionLayerMask == (interactionLayerMask | (1 << other.gameObject.layer)))
{
ActionType interactionType = other.gameObject.GetComponent<InteractionProp>().RoutineEnter();
if( interactionType != null )
{
PopActionOnScreen(interactionType);
}
}
}
// 사물에서 벗어날 때 UI 정리
private void OnTriggerExit(Collider other)
{
if (interactionLayerMask == (interactionLayerMask | (1 << other.gameObject.layer)))
{
housingCanvasController.HideInteractionButton();
}
}
// ActionType 별로 화면에 상호작용 내용 표시, 상호작용 버튼에 이벤트 작성
private void PopActionOnScreen(ActionType interactionType)
{
switch (interactionType)
{
case ActionType.Sleep:
housingCanvasController.ShowInteractionButton("침대에서 잘까?","숙면으로 시간 당 체력 1을 회복한다.", () =>
{
playerStats.PerformAction(ActionType.Sleep);
housingCanvasController.HideInteractionButton();
//TODO: 화면 전환 효과와 UI 업데이트 작업
});
break;
case ActionType.Housework:
housingCanvasController.ShowInteractionButton("밀린 집안일을 처리할까?","체력 1을 사용하고 좋은일이 일어날지도 모른다", () =>
{
if (playerStats.CanPerformByHealth(ActionType.Housework))
{
playerStats.PerformAction(ActionType.Housework);
housingCanvasController.HideInteractionButton();
//TODO: 집안일 후 랜덤 강화 효과 적용
}
else
{
housingCanvasController.SetActionText("힘들어서 못해..");
housingCanvasController.SetDescriptionText();
}
});
break;
case ActionType.Dungeon:
housingCanvasController.ShowInteractionButton("던전에 입장할까?","체력 3을 사용하고 3시간이 흐른다.", () =>
{
if (playerStats.CanPerformByHealth(ActionType.Dungeon))
{
playerStats.PerformAction(ActionType.Dungeon);
housingCanvasController.HideInteractionButton();
}
else
{
housingCanvasController.SetActionText("던전에 갈 체력이 되지 않아..");
housingCanvasController.SetDescriptionText();
}
});
break;
case ActionType.Work:
housingCanvasController.ShowInteractionButton("출근한다.","체력 3을 사용하고 저녁 6시에나 돌아오겠지..", () =>
{
if (playerStats.CanPerformByHealth(ActionType.Work))
{
playerStats.PerformAction(ActionType.Work);
housingCanvasController.HideInteractionButton();
}
else
{
housingCanvasController.SetActionText("도저히 출근할 체력이 안되는걸..?");
housingCanvasController.SetDescriptionText();
}
});
break;
default:
break;
}
}
}

View File

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

View File

@ -0,0 +1,8 @@

using System;
using UnityEngine;
public abstract class InteractionProp: MonoBehaviour
{
public abstract ActionType RoutineEnter();
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eb3b1f8a97cd4befaf14a41276d31292
timeCreated: 1744822822

View File

@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InteractionPropBed : InteractionProp
{ public override ActionType RoutineEnter()
{
return ActionType.Sleep;
}
}

View File

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

View File

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InteractionPropFridge : InteractionProp
{
public override ActionType RoutineEnter()
{
return ActionType.Dungeon;
}
}

View File

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

View File

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InteractionPropSink : InteractionProp
{
public override ActionType RoutineEnter()
{
return ActionType.Housework;
}
}

View File

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

View File

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InteractionPropWork : InteractionProp
{
public override ActionType RoutineEnter()
{
return ActionType.Work;
}
}

View File

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

BIN
Assets/LIN/Housing Copy.unity (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 86c6ebc5f9b48c345bd9d6f402bdc848
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,66 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class HousingCanvasController : MonoBehaviour
{
[SerializeField] GameObject interactionButton;
[SerializeField] TMP_Text actionText;
[SerializeField] TMP_Text descriptionText;
public Action OnInteractionButtonPressed;
void Awake()
{
InitTexts();
interactionButton.SetActive(false);
}
//사물 이름 세팅
public void SetActionText(string text = "")
{
actionText.text = text;
}
//사물 상호작용 내용 설명
public void SetDescriptionText(string text = "")
{
descriptionText.text = text;
}
private void InitTexts()
{
SetActionText();
SetDescriptionText();
}
// 상호작용 가능한 사물에 가까이 갔을 때 화면에 텍스트, 버튼 표시
public void ShowInteractionButton(string actText, string descText,Action onInteractionButtonPressed)
{
SetActionText(actText);
SetDescriptionText(descText);
interactionButton.SetActive(true);
//각 행동 별로 실행되어야 할 이벤트 구독
OnInteractionButtonPressed = onInteractionButtonPressed;
}
//범위에서 벗어나면 상호작용 버튼 off
public void HideInteractionButton()
{
SetActionText();
SetDescriptionText();
interactionButton.SetActive(false);
//구독해놓은 이벤트 해제
OnInteractionButtonPressed = null;
}
//상호작용 버튼 눌렀을 때
public void OnClickInteractionButton()
{
OnInteractionButtonPressed?.Invoke();
}
}

View File

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

8
Assets/LIN/Prefabs.meta Normal file
View File

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

BIN
Assets/LIN/Prefabs/Canvas.prefab (Stored with Git LFS) Normal file

Binary file not shown.

View File

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

BIN
Assets/LIN/Prefabs/HousingMainUIPanel_Copy.prefab (Stored with Git LFS) Normal file

Binary file not shown.

View File

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,12 +3,13 @@
--- !u!78 &1 --- !u!78 &1
TagManager: TagManager:
serializedVersion: 2 serializedVersion: 2
tags: [] tags:
- FxTemporaire
layers: layers:
- Default - Default
- TransparentFX - TransparentFX
- Ignore Raycast - Ignore Raycast
- - Interaction
- Water - Water
- UI - UI
- -