protected override void Awake()
{
base.Awake();
// 인스펙터 상에서 IsFirst를 체크하면 NPC가 나오도록 테스트가 할 수 있습니다.
if(isFirstShop)
PlayerPrefs.SetInt("ShopTutorial", 0);
if(isFirstPlay)
PlayerPrefs.SetInt("StartTutorial", 0);
if (!PlayerPrefs.HasKey("StartTutorial") && PlayerPrefs.GetInt("StartTutorial") == 0)
PlayerPrefs.SetInt("StartTutorial", 0);
if (!PlayerPrefs.HasKey("ShopTutorial") && PlayerPrefs.GetInt("ShopTutorial") == 0)
PlayerPrefs.SetInt("ShopTutorial", 0);
npcPortrait = GetComponentInChildren<UINPCPortrait>();
}
PlayerPrefs로 처음인지 아닌지를 구분했다. 0이면 처음, 1이면 이미 한번 경험한 것이다.
테스트를 위해 IsPlay 변수를 사용하여 초기화조치를 했다.
아직 Key값이 없고, 값이 0 일때는 처음 접하는 경우이니 0값으로 초기화 한다.
private void Start()
{
_scriptsIndex.Add("StartTutorial", new string[] { "안녕하세요 용사님! 처음 뵙겠습니다",
"저는 안내를 맡은 접수원 에리나 입니다",
"이제 전투를 하러 나갈 예정인데요",
"몬스터와 보스를 사냥한 <color=yellow>골드</color>로 능력치를 강화하고",
"<color=red>스킬과 동료를 수집</color>해 더욱 강해지세요!"});
_scriptsIndex.Add("ShopTutorial", new string[] { "이곳은 장비와 동료, 스킬을 구매할 수 있는 공간입니다",
"다이아로 구매 하거나, 무료로 받을 수도 있습니다",
"무료 상품은 받을 때마다 1개씩 더 받을 수 있어요",
"최대 <color=red>35</color>개 까지 늘어습니다",
"많이 구매 할수록 상품 레벨이 높아집니다",
"등급이 높아질 수록 좋은 아이템을 얻을 수 있답니다",
"그럼 즐거운 시간 되세요!"});
}
텍스트는 Dictionary형태로 만들었다. Key값은 어느 구간에서 등장할 것인지 지정해준다.
String은 배열로 텍스트들을 넣어둔다. 대화를 넘길 때 마다 배열의 한 칸씩 넘긴다.
public void ActiveNPC(string scritsIndex)
{
_pivot.SetActive(true);
_currentScript = _scriptsIndex[scritsIndex];
index = 0;
_comment.text = _currentScript[index];
}
튜토리얼을 호출하면 SetActive한다
Index를 초기화 하고 처음 대사 스크립트를 먼저 출력한다.
이는 이후 클릭할 때부터 Index가 상승하면서 스크립트가 넘어가기 때문이다.
public void TalkAction()
{
index++;
//index 초과하면 대화 종료
if (index >= _currentScript.Length)
{
UnactiveNPC();
return;
}
_comment.text = _currentScript[index];
}
대화 클릭은 DIM 스크린에 OnClick 리스너로 등록해두었다.
클릭할 때 마다 index가 증가하고 스크립트를 초과하면 종료한다.
이후 스플릿을 통해 이미지 스프라이트를 지정하여 변경할 예정이다.