[개발일지] 나폴리탄스파게티 20230607
2023. 6. 9. 22:25ㆍ2학년 1학기 프로젝트
이벤트 매니저 구현
이벤트를 랜덤으로 진행하게 하고 총괄하는 스크립트 작성
진행할 이벤트가 기존에 이미 진행중이라면 재추첨 필요
(수정) 창문 이벤트는 랜덤이으로 진행되는 것이 아니라 게임 상 시간으로 05:00~06:00에 일어나므로 따로 구현
다른 스크립트와 연결하여 랜덤으로 추첨 후 진행을 결정하는 변수를 통해 이벤트 랜덤 진행 구현
public class EventManager : MonoBehaviour
{
// 외부 스크립트 및 오브젝트
public GameObject[] events;
TimeController timeCtrl; // 0
// 1
PaintBloodEventController bloodPaintEventCtrl; // 2
PaintEvent paintEventCtrl; // 3
// 4
CCTVcontroller cctvCtrl; // 5
WaterSoundEvent waterSoundEvent; // 6
// 7
LightController lightController;// 8
WindowEventController windowEventCtrl; // 9
TruthEvent truthEvent; // 10
// 랜덤 시스템 관련 변수
public int nowEvent; // 현재 진행중인 이벤트 개수를 담을 변수
public int typeEventNum; // 진행 확정된 이벤트 종류 정보를 담을 변수
int randomEventNum; // 확정되지 않은 이벤트 종류를 랜덤으로 담을 변수
int isEvent; // 이벤트를 진행할지 하지않을지 결정하는 값을 담을 변수
int indexCompleteEvent; // 리스트 내에서 인덱스 값을 확인할 변수
int maxEvent = 1;
bool isThere; // 중복값 확인할 변수
int phase;
List<int> TypeEventList = new List<int>(); // 현재 진행중인 이벤트 정보를 담을 리스트
void Start()
{
RandomEvent();
timeCtrl = events[0].GetComponent<TimeController>(); // 0
bloodPaintEventCtrl = events[2].GetComponent<PaintBloodEventController>(); // 2
paintEventCtrl = events[3].GetComponent<PaintEvent>(); // 3
cctvCtrl = events[5].GetComponent<CCTVcontroller>(); // 5
//6
//8
windowEventCtrl = events[9].GetComponent<WindowEventController>(); // 9
// 10
}
void Update()
{
if(Input.GetKeyDown("o"))
{
CompleteEvent(1);
}
// 게임상 시각이 05:00일 경우 windowEvent를 진행할지 랜덤하게 결정
if(timeCtrl.timeHour > 5)
{
Debug.Log("창문 이벤트 진행 시작");
Invoke("RandomEventWindow", 10);
}
// 02:00 ~ 04:00 이벤트가 6개 이하로 진행
if(timeCtrl.timeHour > 2)
{
maxEvent = 6;
}
// 04:00 ~ 05:00 이벤트 8개 이하로 진행
if(timeCtrl.timeHour > 4)
{
maxEvent = 8;
}
}
// Event를 진행할지 랜덤하게 결정하는 메서드
void RandomEvent()
{
isEvent = Random.Range(0, 2); // 0, 1 (0: 진행X / 1: 진행O)
// 이벤트 종류 추첨
if(isEvent == 1)
{
Debug.Log("진행할 이벤트 종류 추첨");
randomEventNum = Random.Range(1, 8); // 1~7번 이벤트 결정
isThere = TypeEventList.Contains(randomEventNum);
// 기존에 진행중인 이벤트 중 중복된 값이 없을 때 진행
if(isThere == false)
{
typeEventNum = randomEventNum; // 이벤트 진행 확정
goEvent(randomEventNum);
nowEvent++; // 현재 진행중인 이벤트 개수 추가
TypeEventList.Add(typeEventNum); // 진행 이벤트 정보 저장
}
// 진행중인 이벤트 Debug.Log
foreach(int a in TypeEventList)
{
Debug.Log(a);
}
}
// 확인을 위한 Debug.Log (테스트 끝나면 지울 것)
else
{
Debug.Log("이벤트 진행하지 않음");
}
if(nowEvent < maxEvent)
{
Invoke("RandomEvent", 20);
}
}
void RandomEventWindow()
{
// 이벤트 진행 될 확률 낮게
int random = Random.Range(0, 4);
if(random == 1)
{
Debug.Log(random);
windowEventCtrl.event9 = true;
}
else
{
Invoke("RandomEventWindow", 10);
}
}
// 이벤트가 완료될 경우 list에 담긴 이벤트 정보 삭제
void CompleteEvent(int completeEvent)
{
// List에 저장된 이벤트 종류가 몇번에 저장되어있는지 찾아줌
indexCompleteEvent = TypeEventList.IndexOf(completeEvent);
// 완료된 이벤트 정보 제거
TypeEventList.RemoveAt(indexCompleteEvent);
// 진행중인 이벤트 확인 (임시) Debug.Log
foreach(int a in TypeEventList)
{
Debug.Log(a);
}
}
// 이벤트를 진행하게 함
void goEvent(int eventNum)
{
switch(eventNum)
{
case 1:
Debug.Log("test1");
break;
case 2:
bloodPaintEventCtrl.event2 = true;
break;
case 3:
paintEventCtrl.event3 = true;
break;
case 4:
Debug.Log("test4");
break;
case 5:
cctvCtrl.event5 = true;
break;
case 6:
waterSoundEvent.event6 = true;
break;
case 7:
Debug.Log("test7");
break;
case 8:
Debug.Log("test7");
break;
case 9:
windowEventCtrl.event9 = true;
break;
case 10:
Debug.Log("test7");
break;
}
}
}
게임상의 시간 구현
실제 3초가 게임상 시간으로는 1분
이를 UI통해 나타냄
(수정) 페이즈에 따라 시간이 다르게 흘러감
public class TimeController : MonoBehaviour
{
float gameTime; //게임상의 시간을 계산
float updateTime; //게임상 시간을 계산하기 위해 실제 시간 데이터를 담은 변수
public int timeHour; //시
public int timeMinute; //분
public Text timeText; //시간을 나타내는 Text UI변수
public int phase;
/*
<PHASE 0>
1) 00:00 ~ 02:00
2) 02:00 ~ 04:00
- - - - - - - - -
<PHASE 1>
3) 04:00 ~ 06:00
4) 05:00 ~ 06:00
*/
void Start()
{
// 시작시 시각 00:00
timeText.text = (timeHour.ToString("00") +" : "+ timeMinute.ToString("00"));
}
void Update()
{
if(phase == 0)
{
gameTime = 5.0f;
}
else
{
gameTime = 2.5f;
}
// 시간 계산 및 Text UI로 띄우기
if(updateTime > gameTime)
{
updateTime = 0.0f;
timeMinute ++;
if(timeMinute > 59)
{
timeHour ++;
timeMinute = 0;
}
// 00:00형태로 시간을 나타냄
timeText.text = (timeHour.ToString("00") +" : "+ timeMinute.ToString("00"));
}
else
{
updateTime += Time.deltaTime;
}
if(timeHour == 4)
{
phase = 1;
}
}
}
기타
스크립트에 이벤트 진행 변수를 추가하여 이벤트 매니저에서 추첨한 숫자를 통해 이벤트가 진행될 수 있도록 수정
'2학년 1학기 프로젝트' 카테고리의 다른 글
[개발일지] 나폴리탄스파게티 20230610 (2) | 2023.06.10 |
---|---|
[개발일지] 나폴리탄스파게티 20230608 (0) | 2023.06.10 |
[개발일지] 나폴리탄스파게티 20230602 (0) | 2023.06.09 |
[개발일지] 나폴리탄스파게티 20230601 (0) | 2023.06.09 |
[개발일지] 나폴리탄스파게티 20230531 (0) | 2023.06.09 |