//다음 대사를 불러오는 함수 private void LoadNextText(bool playSound) { if (isLoadingStr) { if (str != "") //초기화 { dialogText.text = str; idx = 0; curWordDelay = 0f; isLoadingStr = false; } return; } if (dialog.Count <= 0) //큐에 남은 대사가 없으면 다음 씬으로 넘어간다. { GoToNextScene(); return; } if (playSound) { AudioManager.instance.PlayTouchSFX(); } //큐에서 문장과 말하는이 정보를 불러온다. DialogStruct dialogStruct = dialog.Dequeue(); isFriendTalking = dialogStruct.isFriendTalking; dialogText.text = ""; str = dialogStruct.dialogText; isLoadingStr = true; }
// Use this for initialization void Awake() { dia = new List<DialogStruct>(); if (Application.isEditor==true) { file_path = "Assets/Resources/Dialogs/" + file_name + ".txt"; } else { file_path =Application.dataPath+"/"+file_name+".txt"; } st_r = new StreamReader(file_path); while(st_r.Peek()>-1) { DialogStruct ds=new DialogStruct(); tempStr =st_r.ReadLine(); tempStr.Trim(); if (tempStr.Contains(":")) { string[] sp=tempStr.Split(':'); ds.name = sp[0].Trim(); ds.dialog = sp[1].Trim(); } else { ds.name = ""; ds.dialog = tempStr; } dia.Add(ds); } st_r.Close(); }
public static DialogStruct ParseDialogue(string content) { DialogStruct d = new DialogStruct(); StringReader sr = new StringReader(content); d.Content = sr.ReadLine(); d.Exits = new List <DialogExit>(); string input; while ((input = sr.ReadLine()) != null) { DialogExit e = new DialogExit(); string[] line = input.Split('§'); e.Prompt = line[0].Trim(); if (e.Prompt.Length > 0) { switch (e.Prompt[0]) { case '~': d.Target = e.Prompt.Substring(1); continue; case '*': e.Points = 1; e.Prompt = e.Prompt.Substring(1); break; default: break; } } if (d.Target != null && d.Target.Length > 0) { e.Target = d.Target; } else if (line.Length > 1) { e.Target = line[1].Trim(); } else { e.Target = "EXIT"; } d.Exits.Add(e); } sr.Close(); return(d); }
public static void SendDialog(ulong steamId, string title, string subtitle, string message, string button = "close") { var msg = new DialogStruct { Title = title, Subtitle = subtitle, Message = message, ButtonText = button }; string serialized = MyAPIGateway.Utilities.SerializeToXML(msg); byte[] data = Encoding.ASCII.GetBytes(serialized); SendMessageTo(MessageTypeEnum.ServerDialog, data, steamId); }
public override void OnInspectorGUI() { DirectoryInfo info = new DirectoryInfo("Assets/Resources/Dialogues"); FileInfo[] files = info.GetFiles("*.txt"); if (_dialogues == null) { _dialogues = new string[files.Length + 1]; _dialogues[0] = "Custom"; for (int i = 0; i < files.Length; i++) { _dialogues[i + 1] = files[i].Name; } } _prevSelected = _selected; _selected = EditorGUILayout.Popup(_prevSelected, _dialogues); if (_prevSelected != _selected) { if (_selected == 0) { _content = ""; } else { _selectedDialog = ParseDialogue(files[_selected - 1].FullName); ((Dialogue)target).Content = _selectedDialog.Content; ((Dialogue)target).Exits = _selectedDialog.Exits.ToArray(); if (_selectedDialog.Target.Length > 0) { ((Dialogue)target).Target = _selectedDialog.Target; } ((Dialogue)target).CurrentDialog = _selectedDialog; } } GUILayout.TextArea(_selectedDialog.Content); if (_selectedDialog.Exits != null) { for (int i = 0; i < _selectedDialog.Exits.Count; i++) { GUILayout.TextField(_selectedDialog.Exits[i].Target); } } base.OnInspectorGUI(); }
IEnumerator ShowDialogue() { Movable.MovementEnabled = false; _displayed = true; DialogPanel.gameObject.SetActive(true); bool exiting = false; while ((NextIndex >= 0 && NextIndex < Assets.Length) && !exiting) { DialogTextBox.text = ""; for (int i = 0; i < OptionText.Length; i++) { OptionText[i].text = ""; } CurrentIndex = NextIndex; NextIndex = Assets[CurrentIndex].TargetIndex; DialogStruct current = DialogTools.ParseDialogue(Assets[CurrentIndex].Content); for (int i = 0; i < current.Content.Length; i++) { float delay = 0.06f; DialogTextBox.text += current.Content[i]; if (current.Content[i] == '.') { delay = 0.5f; } if (GamepadControls.State.Buttons.A == XInputDotNetPure.ButtonState.Pressed) { delay = 0.0f; } yield return(new WaitForSeconds(delay)); } //Debug.Log(current.Content); for (int i = 0; i < current.Exits.Count; i++) { OptionText[i].text = current.Exits[i].Prompt; if (current.Exits[i].Points > 0) { _correctIndex = i; } } while (GamepadControls.State.Buttons.A != XInputDotNetPure.ButtonState.Released) { yield return(null); } if (current.Exits.Count == 0) { while (GamepadControls.State.Buttons.A != XInputDotNetPure.ButtonState.Pressed) { yield return(null); } } else { bool up = false; bool right = false; bool down = false; do { up = GamepadControls.State.DPad.Up == XInputDotNetPure.ButtonState.Pressed; right = GamepadControls.State.DPad.Right == XInputDotNetPure.ButtonState.Pressed; down = GamepadControls.State.DPad.Down == XInputDotNetPure.ButtonState.Pressed; yield return(null); } while (!up && !right && !down); switch (_correctIndex) { case 0: if (up) { Score++; } else { exiting = true; } break; case 1: if (right) { Score++; } else { exiting = true; } break; case 2: if (down) { Score++; } else { exiting = true; } break; } Debug.Log(Score); if (NextIndex == -1) { StartCoroutine(GoToCredits()); } } } DialogPanel.gameObject.SetActive(false); Movable.MovementEnabled = true; _displayed = false; CurrentIndex = 0; NextIndex = 0; yield return(null); }
// Update is called once per frame void Update() { if (bubble && curSpeakingTransform) { //float yOffset = curSpeakingTransform.gameObject.GetComponent<Renderer>().bounds.size.y; bubble.transform.position = Camera.main.WorldToScreenPoint(curSpeakingTransform.position + new Vector3(0, 0, 0)); } if (canInput && (Input.GetKey(KeyCode.F5) || Input.GetMouseButtonDown(0))) { nextDialog = true; } if (nextDialog) { string playerPath = CharactersConfigManager.GetCharacterGameObjectPath(CharactersConfigManager.k_PlayerID); // if (!canMoveHere) // { // List<int> blockstate = new List<int>(); // blockstate.Add(0); // GameObject.Find(playerPath).GetComponent<PlayerTestController>().BlockPlayerInput(blockstate); // } nextDialog = false; if (index == dialogList.Count) { Debug.Log("dialog ends"); canInput = false; if (bubble) { Destroy(bubble); } if (!canMoveHere) { Debug.Log("%%%%%%%%%%%%%%%restore"); List <int> blockstate = new List <int>(); blockstate.Add(0); GameObject.Find(playerPath).GetComponent <PlayerTestController>().UnblockPlayerInput(blockstate); } landBreak.cs.doShake = true; landBreak.startTime = Time.time; return; } DialogStruct dialog = dialogList[index]; if (dialog.speakerID != curSpeakerId) // new speaker { if (bubble) { Destroy(bubble); } Debug.Log(dialog.speakerID); curSpeakerId = dialog.speakerID; bubble = Instantiate(Resources.Load("Prefabs/DialogBubble")) as GameObject; Debug.Log(bubble); bubble.transform.SetParent(GameObject.Find("Canvas").transform); //curBubbleTransform = bubble.transform; string objectName = CharactersConfigManager.GetCharacterGameObjectPath(dialog.speakerID); curSpeakingTransform = GameObject.Find(objectName).transform; bubble.GetComponent <BubbleEffectController>().setSaySomething(dialog.content); string speakerName = CharactersConfigManager.GetCharacterName(dialog.speakerID); bubble.GetComponent <BubbleEffectController>().setName(speakerName); string spritePath = CharactersConfigManager.GetCharacterSpritePath(dialog.speakerID); bubble.GetComponent <BubbleEffectController>().setHead(spritePath); canInput = false; Invoke("EnableInput", 0.5f); curSpeakerId = dialog.speakerID; } else { bubble.GetComponent <BubbleEffectController>().setSaySomething(dialog.content); canInput = false; Invoke("EnableInput", 0.5f); } index++; } }