public class Event {
public IEnumerator[] events;
}
์ฐ์ ์ด๋ฐ ์์ผ๋ก ์ด๋ฒคํธ๋ฅผ IEnumerator Array๋ก ๋ง๋ค๊ณ ย
public Event nowEvent;
private int _eventNum;
private IEnumerator nowCor;
public int eventNum
{
get { return _eventNum; }
set
{
_eventNum = value;
if (_eventNum < nowEvent.events.Length)
{
if (nowCor != null) { StopCoroutine(nowCor); }
nowCor = nowEvent.events[_eventNum];
StartCoroutine(nowCor);
}
else { EndEvent(); }
}
}
์ด๋ฒคํธ ๋งค๋์ ์์๋ ์ง๊ธ ๋์์ค์ธ ์ด๋ฒคํธ๋ฅผ ๋ฐ๊ณ
์๋ฒ ๋ฐ๋ ๋๋ง๋ค ๊ทธ ์ด๋ฒคํธ์ n๋ฒ์งธ ์ฝ๋ฃจํด์ ํธ์ถํ๊ฒ ๋ง๋ค์์
public IEnumerator DailyTalk(Dialogue newDialogue, Color? textColor = null) {
if (string.Equals(newDialogue.name, "-")) {
nameObject.SetActive(false);
}
else {
nameObject.SetActive(true);
nameText.text = newDialogue.name;
}
dailyText.color = textColor.HasValue ? textColor.Value : Color.white;
contextCache = "";
for (int j = 0; j < newDialogue.contexts.Length; j++) {
changeCache = newDialogue.contexts[j].Replace("`", ",");
contextCache += changeCache;
contextCache += "\n";
}
newTalk = contextCache;
yield return new WaitUntil(() => isType && Input.GetMouseButtonDown(0));
GameManager.instance.eventManager.eventNum += 1;
}
๊ทธ๋ฆฌ๊ณ ์ด๋ฒคํธ์ ์ฐ์ด๋ ์ฝ๋ฃจํด์ ๋ค ๋๋๋ฉด ์ ์๋ฒ 1 ์ฆ๊ฐ์์ผ์ฃผ๊ฒ ๋ง๋ค์๊ณ
Event makeEvent = new Event();
List<IEnumerator> makeEventList = new List<IEnumerator>();
for (int i = 0; i < callCSV.Length; i++) {
makeEventList.Add(GameManager.instance.playerManager2.DailyTalk(callCSV[i]));
}
makeEvent.events = makeEventList.ToArray();
์ด๋ฒคํธ๋ฅผ ๋ง๋ค ๋ ์ ๋ ๊ฒ IEnumerator๋ก ๋ฆฌ์คํธ๋ฅผ ํ๋ ๋ง๋ค์ด์คฌ๊ณ
public void StartEvent(Event newEvent, int saveNum = 0) {
this.nowEvent = newEvent;
this.eventNum = saveNum;
}
GameManager.instance.eventManager.StartEvent(makeEvent);
์ด๋ฒคํธ๋ฅผ ํธ์ถํ ๋ ์ด๋ฐ ํจ์๋ฅผ ์จ์ ์ ์ด๋ฒคํธ ๊ฐฑ์ ํ๊ฒ ๋ง๋ค์ด์คฌ์
๊ทผ๋ฐ ์ด๊ฒ ๋๊ฐ์ ์ด๋ฒคํธ๋ฅผ ์ฒ์์ ํธ์ถํ ๋๋ ์๋์ ์ ํ๋๋ฐ
๋ ๋ฒ์งธ๋ก ํธ์ถํ ๋๋ ์ด๋ฒคํธ ํธ์ถ๊น์ง ๋๋๋ฐ ์ฝ๋ฃจํด์ดย ์์์ ์ํจ
์ด๊ฒ์ ๊ฒ ๋ฐ๊ฟ๋ ๋ณด๊ณ ๊ฒ์๋ ํด๋ดค๋๋ฐ ๋น์ทํ ์ํฉ์ด ์ ๋์์ ๊ณ ๋ฏผํ๋ค๊ฐ ์ฌ๊ธฐ์ ๊ธ ์ฌ๋ ค๋ณด๋๋ฐ ํน์ ๋์๋ฐ์ ์ ์์๊น
https://docs.microsoft.com/ko-kr/dotnet/api/system.collections.ienumerator.reset?view=net-6.0
ํด๊ฒฐํ๋ค ๊ทธ๋ฅ ์ฝ๋ฃจํด ์ ์ฒด์ while(true) ๊ฑธ๊ณ ๋์ yield return null ๊ฑฐ๋๊น ์ ๋๋ค