private Queue <SentenceUnit> sentenceQueue; //对话的队列 // Use this for initialization void Start() { sentenceQueue = new Queue <SentenceUnit>(); box.SetActive(false); count = 0; sentenceUnit = null; StartCoroutine(showSentence()); }
// Update is called once per frame void Update() { if (Input.anyKeyDown) { if (Input.GetKeyDown(KeyCode.Space)) { if (sentenceUnit.sentence.Length != count) { text.text = sentenceUnit.sentence; } if (sentenceQueue.Count != 0) { sentenceUnit = sentenceQueue.Dequeue(); } if (sentenceQueue.Count == 0) { if (sentenceUnit != null) { if (count == sentenceUnit.sentence.Length) { hideDialogBox(); } else { text.text = sentenceUnit.sentence; } } } count = 0; } //调用示范 if (Input.GetKeyDown(KeyCode.A)) { pushSentence("233333"); pushSentence("拜托你很弱欸"); pushSentence("你现在知道谁是老大了吗"); showDialogBox(); } if (Input.GetKeyDown(KeyCode.X)) { GameControll.SaveData(); } } }
public void DoUpdate() { if (ScreenplayReader.instance == null) { return; } if (ScreenplayReader.instance.GetCurrentLineValue() != lastValue) { //Check to see if it has evaluated this line yet. If it hasn't it will read it this frame, but ignore it next frame. //It does this so it doesn't have to do extra work evaluating the commands. lastValue = ScreenplayReader.instance.GetCurrentLineValue(); } else { //already evaluated this line, so don't do it again. return; } SentenceUnit sentenceUnit = ScreenplayReader.instance.GetCurrentSentenceUnitData(); if (sentenceUnit == null) { return; } curPrescriptActions = sentenceUnit.prescriptActions.ToArray(); if (curPrescriptActions != null) { foreach (PrescriptAction s in curPrescriptActions) { //Pause....................................................................... if (s.dataPack[0].ToLower() == "system") { if (s.dataPack[1].ToLower() == "pause") { ScreenplayReader.instance.PausePrompt(float.Parse(s.dataPack[2])); } } //Pause....................................................................... //Memory...................................................................... if (s.dataPack[0].ToLower() == "memory") { EventManagerBPA.instance.EvalString(s.dataPack[1]); } //Memory...................................................................... //IF statements............................................................... if (s.dataPack[0].ToLower() == "if") { //for now, if can only link to a goto. it cannot write data. //DoIfEvaluation(s.dataPack[1]); StartCoroutine(WaitForDialogueToEndAndThenEvalIfStatement(s.dataPack[1])); } //IF statements............................................................... //TODO: A goto with a goto line option. } } //don't repeat these actions next frame. if (curPrescriptActions != null) { lastAction = curPrescriptActions; } curPrescriptActions = null; }
public void showDialogBox()//显示对话框,*使用完pushSentence后再调用! { box.SetActive(true); count = 0; sentenceUnit = sentenceQueue.Dequeue(); }
public IEnumerator ReadGroup(string groupToRead) { yield return(true); BREAK_LOOP = false; sentenceVal = ObtainSentenceGroupValue(groupToRead); if (sentenceVal == -1) { yield break; } //When a group must a new number is selected, and the foreach is evaluated again. //Bite me. This is a great use for goto ...you snob. READ_FROM_GROUP: curSentenceValue = -1; //Use this to set the starting sentences. fro save/load system if you save in the middle of dialogue. int intialLine = 0; if (startReadingFromLine > -1) { intialLine = startReadingFromLine; //reset the start of line reading to -1 so that goto' don't break. startReadingFromLine = -1; } if (autoSaveData) { IniGameMemory.instance.WriteData(group, key, groupToRead); //this gets updated during goto's IniGameMemory.instance.WriteData(group, lineKey, 0); //if you ever add a way of specifying a line, then save it here. } //--------------------------------------------------------------------------------------------------- for (int i = intialLine; i < Sentences[sentenceVal].sentences.Count; i++) { SentenceUnit s = Sentences[sentenceVal].sentences[i]; curSentenceUnit = s; curSentenceValue++; next = false; if (autoSaveData) { IniGameMemory.instance.WriteData(group, lineKey, i); } while (pauseTime > 0) { HideDialogueBox(); pauseTime -= Time.deltaTime; yield return(null); } ShowDialogueBox(); Write(s.dialogue); SetNameToWrite(s.speakerName); yield return(true); while (IsPrinting()) { if (BREAK_LOOP) { BREAK_LOOP = false; isReading = false; yield break; } if (PlayerInput.instance != null) { next = PlayerInput.instance.GetFire1_B(); } if (next) { //Make text typeout all at once. SentenceDisplay.EndTypewriterEffect(); next = false; } if (GetFastforwardButton()) { // Time.timeScale = 50f; SentenceDisplay.EndTypewriterEffect(); } yield return(true); } //...now look for skip button input. yield return(true); while (!next && GetFastforwardButton() == false) { if (BREAK_LOOP) { BREAK_LOOP = false; isReading = false; yield break; } if (PlayerInput.instance != null) { next = PlayerInput.instance.GetFire1_B(); } if (autoNextAtEndIfPromptIsRequested) { if (SentenceDisplay.IsPrinting() == false) { if (s.dealWithSpecialCommands == SentenceUnit.DealWithSpecailCommands.UseInPromptMenu) { yield return(new WaitForSeconds(0.5f)); next = true; } } } yield return(true); } next = false; //The multichoice prompt is evaluated before each specail command is requested. //all special commands become a choice in the prompt if (s.dealWithSpecialCommands == SentenceUnit.DealWithSpecailCommands.UseInPromptMenu) { menuPrompt.ClearChoicesList(); List <SpecialCommand> modifiedChoiceList = new List <SpecialCommand>(); int checkCommandNumber = 0; foreach (SpecialCommand command in s.specialCommands) { //Remove choice if memory says to remove it. if (IniGameMemory.instance.GetDataValue(menuGroupName, choiceKeyRootName + checkCommandNumber, -1) == 1) { //skip this command choice. this works, but I need to find a way to have menu choice link to new index number... checkCommandNumber++; continue; } menuPrompt.AddChoice(command.requestName); //The choice list can be modfied, so make a copy of it and build it up from valid options. modifiedChoiceList.Add(command); checkCommandNumber++; } yield return(true); menuPrompt.OpenPrompt(); while (menuPrompt.isPromptOpen()) { if (BREAK_LOOP) { BREAK_LOOP = false; isReading = false; menuPrompt.ClearChoicesList(); menuPrompt.HidePromptDisplay(); yield break; } yield return(true); } sentenceVal = ObtainSentenceGroupValue(modifiedChoiceList[menuPrompt.GetChoice()].commandLine); if (autoSaveData) { groupToRead = s.specialCommands[menuPrompt.GetChoice()].commandLine; } if (sentenceVal == -1) { Debug.LogError("ScreenplayReader Error 01: Group '" + s.specialCommands[menuPrompt.GetChoice()].commandLine + "' does not exist!"); } goto READ_FROM_GROUP; //Bite me. This is a great use for goto ...you snob. } //Parse special commands..................... foreach (SpecialCommand command in s.specialCommands) { switch (s.dealWithSpecialCommands) { case SentenceUnit.DealWithSpecailCommands.Ignore: break; case SentenceUnit.DealWithSpecailCommands.NotifySystem: break; case SentenceUnit.DealWithSpecailCommands.UseInPromptMenu: //... not evaluated here... was delt with by the if statement above. on line starting @ if(s.dealWithSpecialCommands==SentenceUnit.DealWithSpecailCommands.UseInPromptMenu) break; case SentenceUnit.DealWithSpecailCommands.AutoGoto: print("GOTO:" + command.commandLine); //pick a new sentence group and goto that group... sentenceVal = ObtainSentenceGroupValue(command.commandLine); if (autoSaveData) { groupToRead = command.commandLine; } if (sentenceVal == -1) { Debug.LogError("ScreenplayReader Error 01: Group '" + command.commandLine + "' does not exist!"); } goto READ_FROM_GROUP; //Bite me. This is a great use for goto ...you snob. #pragma warning disable CS0162 // Unreachable code detected break; #pragma warning restore CS0162 // Unreachable code detected } } //......................................................................................... } sentenceVal = -1; print("End of conversation"); HideDialogueBox(); yield break; }