/// <summary> /// Helper function that creates a decision block with the name key at the given path. /// </summary> /// <param name="in_key"></param> /// <param name="in_path"></param> public static DecisionBlock CreateDecisionBlock(string in_key, string in_path) { DecisionBlock db = ScriptableObjectUtility.CreateAsset <DecisionBlock>(in_path, in_key); db.SetKey(in_key); return(db); }
/// <summary> /// Helper function that sets a decision block given some line data. /// </summary> /// <param name="lineData"></param> static void SetDecisionBlock(string[] lineData) { //Extract the data we need. string key = lineData[0]; string text = lineData[2]; string flagSetListText = lineData[3]; string decisionInfoListText = lineData[4]; //Use helper function to parse flag set list. List <FlagSet> flagSetList = ParseFlagSetList(flagSetListText); //Use helper function to parse next block list. List <DecisionInfo> decisionInfoList = ParseDecisioninfoList(decisionInfoListText); DecisionBlock block = (DecisionBlock)SceneBlockDictionary[key]; block.SetDecisionBlock(text, flagSetList, decisionInfoList); }
/// <summary> /// Populates our dictionary with all the blocks we need and makes the objects in the folders. /// </summary> /// <param name="lines"></param> static void PopulateDictionaryAndFolders(string[] lines, string path, string sceneName) { //Clear the directory ClearFolder(path); //Refresh the dictionary. SceneBlockDictionary = new Dictionary <string, TextBlock>(); //This ignore bool is for the first line, which are just headers. bool ignore = true; foreach (string line in lines) { //Ignore first line. if (ignore) { ignore = false; } else if (!ignore) { //Separate by commas. (CSV) string[] lineData = (line.Trim()).Split(","[0]); //This is the type of block this is. string key = lineData[0]; string type = lineData[1]; if (type.Equals("DialogueBlock")) { DialogueBlock db = DialogueBlock.CreateDialogueBlock(key, path); SceneBlockDictionary.Add(key, (TextBlock)db); } else if (type.Equals("DecisionBlock")) { DecisionBlock db = DecisionBlock.CreateDecisionBlock(key, path); SceneBlockDictionary.Add(key, (TextBlock)db); } } } //Store this scenes block dictionary into the scene. AllSceneBlockDictionary.Add(sceneName, SceneBlockDictionary); }
/// <summary> /// Helper function that populates the decision bar given a decision block /// </summary> void PopulateDecisionBar(DecisionBlock decisionBlock) { //Enable the decision bar, which is by default not there when there are no decisions. decisionBar.gameObject.SetActive(true); //Load the decision button prefab GameObject decisionButton = Resources.Load("DialogueSystem/Prefab/DecisionButton") as GameObject; //For every decision in our decisionInfo list on this block foreach (DecisionInfo info in decisionBlock.GetDecisionInfo()) { //Create a decision button GameObject cur_db = Instantiate(decisionButton, decisionBar); //Add the right function call to the button cur_db.GetComponent <Button>().onClick.AddListener(() => ChooseDecision(info)); //Populate the text on the button cur_db.GetComponentInChildren <Text>().text = info.GetDecisionText(); //Enable the object so it shows up in the bar. cur_db.gameObject.SetActive(true); } }
/// <summary> /// Populates the flag dictinoary with all the flags found in our excel sheet. /// </summary> static void InitFlagFile(List <string> fileNameList) { //Get the flag dict List <string> flagList = new List <string>(); foreach (string FileName in fileNameList) { //Read in all text from the given file (csv) and split by line. string fileData = System.IO.File.ReadAllText(path + FileName + ".csv"); string[] lines = fileData.Split("\n"[0]); //This ignore bool is for the first line, which are just headers. bool ignore = true; foreach (string line in lines) { //Ignore first line. if (ignore) { ignore = false; } else if (!ignore) { //Separate by commas. (CSV) string[] lineData = (line.Trim()).Split(","[0]); //This is the type of block this is. string key = lineData[0]; string type = lineData[1]; if (SceneBlockDictionary.ContainsKey(key)) { //First process the flag set list. List <FlagSet> flagSetList = SceneBlockDictionary[key].GetFlagSetList(); //Loop through all flags in flag set list. foreach (FlagSet fs in flagSetList) { if (!flagList.Contains(fs.flag_key)) { flagList.Add(fs.flag_key); } } //Then check for further flags found in the specific block type. if (type.Equals("DialogueBlock")) { DialogueBlock db = (DialogueBlock)SceneBlockDictionary[key]; foreach (string flag in db.GetDependentFlags()) { //If we don't have this flag in the list yet, add it. if (!flagList.Contains(flag)) { flagList.Add(flag); } } } else if (type.Equals("DecisionBlock")) { DecisionBlock db = (DecisionBlock)SceneBlockDictionary[key]; } } else { throw new System.Exception("Error, given key: " + key + " from file: + " + FileName + " isn't in our dictionary. Reload the csv to populate it."); } } } } //Path that we are going to write to. string file_path = "Assets/Data/FlagData.txt"; //Write some text to the test.txt StreamWriter writer = new StreamWriter(file_path, false); foreach (string flag in flagList) { writer.WriteLine(flag + ", false"); } writer.Close(); Debug.Log("Finished. Flag file initialized at: " + file_path); }