Merge pull request #18 from Degulleo/DEG-27-돌발이벤트-시스템
Deg 27 돌발이벤트 시스템 그리고 상호작용 리팩토링
This commit is contained in:
commit
167c1475dd
@ -13,6 +13,13 @@ public class InteractionController : MonoBehaviour
|
|||||||
[Header("UI 연동")]
|
[Header("UI 연동")]
|
||||||
[SerializeField] HousingCanvasController housingCanvasController;
|
[SerializeField] HousingCanvasController housingCanvasController;
|
||||||
|
|
||||||
|
private SuddenEventController _suddenEventController = new SuddenEventController();
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
playerStats.OnWorked += SuddenAfterWorkEventHappen;
|
||||||
|
}
|
||||||
|
|
||||||
// 상호작용 가능한 사물 범위에 들어올 때
|
// 상호작용 가능한 사물 범위에 들어올 때
|
||||||
private void OnTriggerEnter(Collider other)
|
private void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
@ -37,64 +44,47 @@ public class InteractionController : MonoBehaviour
|
|||||||
// ActionType 별로 화면에 상호작용 내용 표시, 상호작용 버튼에 이벤트 작성
|
// ActionType 별로 화면에 상호작용 내용 표시, 상호작용 버튼에 이벤트 작성
|
||||||
private void PopActionOnScreen(ActionType interactionType)
|
private void PopActionOnScreen(ActionType interactionType)
|
||||||
{
|
{
|
||||||
switch (interactionType)
|
HousingConstants.interactions.TryGetValue(interactionType, out var interactionTexts);
|
||||||
|
|
||||||
|
housingCanvasController.ShowInteractionButton(interactionTexts.ActionText,interactionTexts.DescriptionText,()=>
|
||||||
{
|
{
|
||||||
case ActionType.Sleep:
|
if (playerStats.CanPerformByHealth(interactionType))
|
||||||
housingCanvasController.ShowInteractionButton("침대에서 잘까?","숙면으로 시간 당 체력 1을 회복한다.", () =>
|
{
|
||||||
|
playerStats.PerformAction(interactionType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
housingCanvasController.SetActionText(interactionTexts.LackOfHealth);
|
||||||
|
housingCanvasController.SetDescriptionText();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action SuddenEventHappen()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SuddenAfterWorkEventHappen()
|
||||||
|
{
|
||||||
|
AfterWorkEvent afterWorkEvent = _suddenEventController.SuddenEventCalculator();
|
||||||
|
if (afterWorkEvent == AfterWorkEvent.None)
|
||||||
|
return;
|
||||||
|
switch (afterWorkEvent)
|
||||||
|
{
|
||||||
|
case AfterWorkEvent.OvertimeWork:
|
||||||
|
housingCanvasController.ShowSuddenEventPanel("부장님이 퇴근을 안하셔.. 야근할까?", () =>
|
||||||
{
|
{
|
||||||
playerStats.PerformAction(ActionType.Sleep);
|
//Todo: 컷씬과 스테이터스 변경
|
||||||
housingCanvasController.HideInteractionButton();
|
housingCanvasController.HideSuddenEventPanel();
|
||||||
//TODO: 화면 전환 효과와 UI 업데이트 작업
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case ActionType.Housework:
|
case AfterWorkEvent.TeamGathering:
|
||||||
housingCanvasController.ShowInteractionButton("밀린 집안일을 처리할까?","체력 1을 사용하고 좋은일이 일어날지도 모른다", () =>
|
housingCanvasController.ShowSuddenEventPanel("갑자기 팀 회식이 잡혔다. 참석 하러 가자", () =>
|
||||||
{
|
{
|
||||||
if (playerStats.CanPerformByHealth(ActionType.Housework))
|
housingCanvasController.HideSuddenEventPanel();
|
||||||
{
|
|
||||||
playerStats.PerformAction(ActionType.Housework);
|
|
||||||
housingCanvasController.HideInteractionButton();
|
|
||||||
//TODO: 집안일 후 랜덤 강화 효과 적용
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
housingCanvasController.SetActionText("힘들어서 못해..");
|
|
||||||
housingCanvasController.SetDescriptionText();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
Assets/LIN/Housing Copy.unity
(Stored with Git LFS)
BIN
Assets/LIN/Housing Copy.unity
(Stored with Git LFS)
Binary file not shown.
@ -6,19 +6,26 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class HousingCanvasController : MonoBehaviour
|
public class HousingCanvasController : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[Header("일상행동 상호작용")]
|
||||||
[SerializeField] GameObject interactionButton;
|
[SerializeField] GameObject interactionButton;
|
||||||
[SerializeField] TMP_Text actionText;
|
[SerializeField] TMP_Text actionText;
|
||||||
[SerializeField] TMP_Text descriptionText;
|
[SerializeField] TMP_Text descriptionText;
|
||||||
|
|
||||||
public Action OnInteractionButtonPressed;
|
|
||||||
|
|
||||||
|
[Header("돌발 이벤트")]
|
||||||
|
[SerializeField] private GameObject suddenPanel;
|
||||||
|
[SerializeField] private TMP_Text suddenText;
|
||||||
|
|
||||||
|
public Action OnInteractionButtonPressed;
|
||||||
|
public Action OnSuddenButtonPressed;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
InitTexts();
|
InitInteractionTexts();
|
||||||
interactionButton.SetActive(false);
|
interactionButton.SetActive(false);
|
||||||
|
suddenPanel.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 상호작용 일상 행동
|
||||||
//사물 이름 세팅
|
//사물 이름 세팅
|
||||||
public void SetActionText(string text = "")
|
public void SetActionText(string text = "")
|
||||||
{
|
{
|
||||||
@ -30,7 +37,7 @@ public class HousingCanvasController : MonoBehaviour
|
|||||||
descriptionText.text = text;
|
descriptionText.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitTexts()
|
private void InitInteractionTexts()
|
||||||
{
|
{
|
||||||
SetActionText();
|
SetActionText();
|
||||||
SetDescriptionText();
|
SetDescriptionText();
|
||||||
@ -46,7 +53,6 @@ public class HousingCanvasController : MonoBehaviour
|
|||||||
//각 행동 별로 실행되어야 할 이벤트 구독
|
//각 행동 별로 실행되어야 할 이벤트 구독
|
||||||
OnInteractionButtonPressed = onInteractionButtonPressed;
|
OnInteractionButtonPressed = onInteractionButtonPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
//범위에서 벗어나면 상호작용 버튼 off
|
//범위에서 벗어나면 상호작용 버튼 off
|
||||||
public void HideInteractionButton()
|
public void HideInteractionButton()
|
||||||
{
|
{
|
||||||
@ -62,5 +68,27 @@ public class HousingCanvasController : MonoBehaviour
|
|||||||
public void OnClickInteractionButton()
|
public void OnClickInteractionButton()
|
||||||
{
|
{
|
||||||
OnInteractionButtonPressed?.Invoke();
|
OnInteractionButtonPressed?.Invoke();
|
||||||
|
HideInteractionButton();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 돌발 이벤트
|
||||||
|
public void ShowSuddenEventPanel(string actText, Action onSuddenButtonPressed)
|
||||||
|
{
|
||||||
|
suddenPanel.SetActive(true);
|
||||||
|
suddenText.text = actText;
|
||||||
|
OnSuddenButtonPressed += onSuddenButtonPressed;
|
||||||
|
}
|
||||||
|
public void HideSuddenEventPanel()
|
||||||
|
{
|
||||||
|
suddenPanel.SetActive(false);
|
||||||
|
suddenText.text = "";
|
||||||
|
OnSuddenButtonPressed = null;
|
||||||
|
}
|
||||||
|
public void OnSuddenConfirmButton()
|
||||||
|
{
|
||||||
|
OnSuddenButtonPressed?.Invoke();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
43
Assets/LIN/HousingConstants.cs
Normal file
43
Assets/LIN/HousingConstants.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//퇴근 후 발생할 수 있는 돌발 이벤트
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public enum AfterWorkEvent
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
TeamGathering,
|
||||||
|
OvertimeWork
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HousingConstants
|
||||||
|
{
|
||||||
|
//돌발 이벤트 확률 계산
|
||||||
|
public static int AFTER_WORK_DENOMINATOR = 4;
|
||||||
|
|
||||||
|
|
||||||
|
#region 상호작용 멘트
|
||||||
|
|
||||||
|
public static readonly Dictionary<ActionType, InteractionTexts> interactions =
|
||||||
|
new Dictionary<ActionType, InteractionTexts>
|
||||||
|
{
|
||||||
|
{ ActionType.Sleep, new InteractionTexts("침대에서 잘까?","숙면으로 시간 당 체력 1을 회복한다.", ".")},
|
||||||
|
{ ActionType.Housework, new InteractionTexts("밀린 집안일을 처리할까?","체력 1을 사용하고 좋은일이 일어날지도 모른다","힘들어서 못해..")},
|
||||||
|
{ ActionType.Dungeon, new InteractionTexts("던전에 입장할까?","체력 3을 사용하고 3시간이 흐른다.","던전에 갈 체력이 되지 않아..")},
|
||||||
|
{ ActionType.Work, new InteractionTexts("출근한다.","체력 3을 사용하고 저녁 6시에나 돌아오겠지..", "도저히 출근할 체력이 안되는걸..?")}
|
||||||
|
};
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public struct InteractionTexts
|
||||||
|
{
|
||||||
|
public string ActionText { get; private set; }
|
||||||
|
public string DescriptionText { get; private set; }
|
||||||
|
public string LackOfHealth { get; private set; }
|
||||||
|
|
||||||
|
public InteractionTexts(string actionText, string descriptionText, string lackOfHealth)
|
||||||
|
{
|
||||||
|
ActionText = actionText;
|
||||||
|
DescriptionText = descriptionText;
|
||||||
|
LackOfHealth = lackOfHealth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Assets/LIN/HousingConstants.cs.meta
Normal file
3
Assets/LIN/HousingConstants.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b0ce52df52334b1eaf37479fdda66f7a
|
||||||
|
timeCreated: 1745303266
|
24
Assets/LIN/SuddenEventController.cs
Normal file
24
Assets/LIN/SuddenEventController.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
public class SuddenEventController
|
||||||
|
{
|
||||||
|
// 랜덤 값에 일치하는 함수를 리턴하기 위한 딕셔너리
|
||||||
|
// AFTER_WORK_DENOMINATOR 값 확정 후에 키 값 수정
|
||||||
|
private Dictionary<int, AfterWorkEvent> afterWorkEvents = new Dictionary<int, AfterWorkEvent>();
|
||||||
|
public SuddenEventController()
|
||||||
|
{
|
||||||
|
afterWorkEvents.Add(0, AfterWorkEvent.OvertimeWork);
|
||||||
|
afterWorkEvents.Add(1, AfterWorkEvent.TeamGathering);
|
||||||
|
}
|
||||||
|
|
||||||
|
//퇴근 후 돌발 이벤트
|
||||||
|
public AfterWorkEvent SuddenEventCalculator()
|
||||||
|
{
|
||||||
|
var index = Random.Range(0,HousingConstants.AFTER_WORK_DENOMINATOR);
|
||||||
|
return afterWorkEvents.GetValueOrDefault(index, AfterWorkEvent.None);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
Assets/LIN/SuddenEventController.cs.meta
Normal file
3
Assets/LIN/SuddenEventController.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 26ce8577425c4630903173b182839514
|
||||||
|
timeCreated: 1745306651
|
Loading…
x
Reference in New Issue
Block a user