/* Creator: Yan * find the npc in the scene and save the quest status and dialog status before change to another scene */ public void FindNPCSaveBool() { if (Content.instance == null) { return; } questList = Content.instance.contentStrings; foreach (var item in questList) { Debug.Log("q " + item); } List <string> npcList = AllNPCList.returnList(sceneNum); if (npcList == null) { return; } foreach (var item in npcList) { //Debug.Log (sceneNum + item); QuestStatus qs = new QuestStatus(item, new List <QuestStatus.QuestBool>(), new List <bool>()); GameObject ve = GameObject.FindGameObjectWithTag(item); if (ve == null) { return; } NPC veNPC = ve.GetComponent <NPC> (); if (veNPC != null) { foreach (var conCollection in veNPC.conditionCollections) { qs.questBool.Add(new QuestStatus.QuestBool(conCollection.description, conCollection.obtained, conCollection.available, conCollection.complete)); } } DialogArray veDialogArray = ve.GetComponent <DialogArray> (); if (veDialogArray != null) { foreach (var dialog in veDialogArray.conversations) { qs.dialogBool.Add(dialog.active); } } // foreach (var it in qs.questBool) { // Debug.Log (it.description + it.available + it.obtained + it.complete); // } if (saveQuest.ContainsKey(sceneNum)) { saveQuest [sceneNum].Add(qs); } else { saveQuest.Add(sceneNum, new List <QuestStatus>()); saveQuest [sceneNum].Add(qs); } } }
private static void CreateAllNPCListAsset() { if (AllNPCList.Instance) { return; } //set up the instance always equal to the same one AllNPCList instance = CreateInstance <AllNPCList>(); AssetDatabase.CreateAsset(instance, creationPath); AllNPCList.Instance = instance; instance.npcLists = new List <NPCList>(); }
/*creator: Yan Zhang * find the npc in the scene and set the bool status from the global control to the npc */ public void FindNPCSetBool(int snum) { //find the quest list object in the scene if (GameObject.FindWithTag("QuestContent") == null) { return; } Content content = GameObject.FindWithTag("QuestContent").GetComponent <Content>(); content.contentStrings.Clear(); //add each quest the player current have to the quest list on gui foreach (var item in questList) { content.contentStrings.Add(item); //Debug.Log ("q " + item); } //get the list of npc that the current loading scene have List <string> npcList = AllNPCList.returnList(snum); if (npcList == null) { return; } //go throught the npc list in the cuurent scene and set the quest state and dialog state foreach (var item in npcList) { //Debug.Log (snum + item); //find the npc with teh tag GameObject ve = GameObject.FindGameObjectWithTag(item); if (ve == null) { //Debug.Log (item + " null when set"); return; } QuestStatus qs = null; if (!saveQuest.ContainsKey(snum)) { return; } foreach (var qstatus in saveQuest[snum]) { if (qstatus.npcName == item) { qs = qstatus; } } //get npc and set bool NPC veNPC = ve.GetComponent <NPC> (); foreach (var b in qs.questBool) { foreach (var conditionCollection in veNPC.conditionCollections) { if (b.description == conditionCollection.description) { conditionCollection.available = b.available; conditionCollection.obtained = b.obtained; conditionCollection.complete = b.complete; } } } //get the dialog and set the dialog array DialogArray veDialogArray = ve.GetComponent <DialogArray> (); if (veDialogArray != null) { for (int i = 0; i < veDialogArray.conversations.Length; i++) { veDialogArray.conversations [i].active = qs.dialogBool [i]; } } } }