public void RunDialog(DialogCharacter character) { this.currDialog = character; if (PlayerPrefs.GetString("language") == "pt-BR") { this._story = new Story(inkAssetPortuguese.text); } else if (PlayerPrefs.GetString("language") == "en") { this._story = new Story(inkAssetEnglish.text); } else { Debug.Break(); Debug.LogError("This should not be happening."); this._story = new Story(inkAssetPortuguese.text); } if (savedJson != "") { this._story.state.LoadJson(savedJson); } this._story.ChoosePathString(character.dialogID); Toggle(true); StartCoroutine(Text()); }
private Vector3 GetNamePositiion(DialogCharacter character) { var result = character.NamePositiion; result.y = _nameCharacterObject.transform.position.y; return(result); }
public DialogLabel(string id, List <object> block) { this.id = id; this.block = new List <object>(block); characters = new Dictionary <string, DialogCharacter>() { { "R", new DialogCharacter("R", "Rubus") }, { "H", new DialogCharacter("H", "Hedera") }, { "S", new DialogCharacter("S", "Sternella") }, { "A", new DialogCharacter("A", "Agelaius") }, { "O", new DialogCharacter("O", "Oxx") }, { "B", new DialogCharacter("B", "Bark") }, { "Z", new DialogCharacter("Z", "Riddance") }, }; labels = new Dictionary <string, DialogLabel>(); flags = new Dictionary <string, bool>(); // find all characters and labels // parse them to the characters list and labels list for (int i = 0; i < this.block.Count; i++) { // check for character statement if (CheckStatement(this.block[i], "character")) { DialogCharacter c = DialogCharacter.Load(this.block[i]); if (c == null) { throw new DialogError($"Invalid DialogCharacter.\nYAML: {Reserialize(this.block[i])}"); } if (characters.ContainsKey(c.id)) { throw new DialogError($"Duplicate DialogCharacter '{c.id}'.\nYAML: {Reserialize(this.block[i])}"); } characters[c.id] = c; // remove this.block.RemoveAt(i); i--; continue; } // check for label statement if (CheckStatement(this.block[i], "label")) { DialogLabel l = Load(this.block[i]); if (l == null) { throw new DialogError($"Invalid DialogLabel.\nYAML: {Reserialize(this.block[i])}"); } if (labels.ContainsKey(l.id)) { throw new DialogError($"Duplicate DialogLabel '{l.id}'.\nYAML: {Reserialize(this.block[i])}"); } labels[l.id] = l; l.parent = this; // remove this.block.RemoveAt(i); i--; continue; } } }
IEnumerator Text() { container.SetActive(true); if (animator) { animator.SetBool("active", true); } while (_story.canContinue) { string str = _story.Continue(); this.printCompleted = false; // start typing typer.TypeText(str, 0.02f); if (animator) { animator.SetBool("idle", false); } // typing ends when player tries to skip it, or if the print was completed naturally yield return(new WaitForEndOfFrame()); yield return(new WaitUntil(() => this.dialogKeyPressed || this.printCompleted)); this.dialogKeyPressed = false; typer.Skip(); if (animator) { animator.SetBool("idle", true); } // end this line after player confirmation yield return(new WaitForEndOfFrame()); yield return(new WaitUntil(() => this.dialogKeyPressed)); this.dialogKeyPressed = false; } if (animator) { animator.SetBool("active", false); } container.SetActive(false); savedJson = _story.state.ToJson(); this.printCompleted = false; this.currDialog = null; Toggle(false); }
// should probably change it for constructor public void Initialize(ActorToCreate actorToCreate) { character = actorToCreate.Character; currentState = actorToCreate.InitialState; transitions = actorToCreate.Transitions; Canvas parentCanvas = GetComponentInParent <Canvas>(); _parentCanvasRectTransform = parentCanvas.GetComponent <RectTransform>(); _rectTransform = gameObject.AddComponent <RectTransform>(); _stage = transform.GetComponent <StageForActors>(); _image = gameObject.AddComponent <Image>(); _image.sprite = character.BodySprite; _image.SetNativeSize(); SetImageScale(); gameObject.name = character.name + " Actor"; Move(currentState.relativePosition); }
public void Init(ConversationNode node) { _actualNode = node; DialogCharacter character = DialogController.GetCharacterWithId(node.CharacterId); Portrait.sprite = character.Portrait; DialogController.SetActiveBox(this); if (node.IsEndNode) { EndDialogue(); } if (node.Answers != null && node.Answers.Count > 0) { _isAnswerNode = true; InitAnswerButtons(node); } else { _isAnswerNode = false; InitSpeech(node); } }
private void ButtonAddClick(object sender, EventArgs e) { var text = _comboCharacters.Text; if (text != null) text = text.Trim(); if(!string.IsNullOrEmpty(text)) { if(!_listCharacters.Items.Cast<ListViewItem>().Any(c=>((DialogCharacter)c.Tag).Name==text)) { var ch = new DialogCharacter(_dialog) {Name = text}; AddCharacter(ch); if(_comboCharacters.SelectedIndex<0) _comboCharacters.Items.Add(text); } } }
private void AddCharacter(DialogCharacter ch) { var item = _listCharacters.Items.Add(new ListViewItem(ch.Name)); item.Tag = ch; item.Checked = ch.IsPlayer; }
public DialogCharacter AddCharacter(string name) { DialogCharacter baseCh; if (!ParentContainer.TryGetCharacter(name, out baseCh)) baseCh = ParentContainer.AddCharacter(name); var ch = new DialogCharacter(baseCh, this); DialogCharacters.Add(ch); return ch; }
internal void ReadXml(XElement xDialog, Func<int,DialogCharacter> characterSelector) { string name; if(xDialog.TryGetAttribute("name",out name)) Name = name; XElement characterProperties = xDialog.Element("characterProperties"), graph = xDialog.Element("graph"), chatactersNode = xDialog.Element("characters"); Dictionary<int, string> propertyMap; if (characterProperties != null) propertyMap = _attributeCollection.ReadXml(characterProperties, new List<string> { "IsPlayer" }); else propertyMap = new Dictionary<int, string>(); var tmpCharacters = new Dictionary<int, DialogCharacter>(); if(chatactersNode!=null) { foreach(var ch in chatactersNode.Elements("character")) { int id; if(!ch.TryGetAttribute("id",out id)) continue; var baseChar = characterSelector(id); var character = new DialogCharacter(baseChar, this); character.ReadProperties(ch, propId => propertyMap[propId]); tmpCharacters.Add(character.Id, character); DialogCharacters.Add(character); } } if (graph != null) { XElement xNodes = graph.Element("nodes"), xLinks = graph.Element("links"); var nodeDefaultLinks = new Dictionary<int, int>(); if (xNodes != null) { foreach (var xNode in xNodes.Elements()) { int id; if (!xNode.TryGetAttribute("id", out id)) continue; int defaultLink; if (xNode.TryGetAttribute("defaultLink", out defaultLink)) nodeDefaultLinks.Add(id, defaultLink); DialogGraphNodeBase node = null; switch (xNode.Name.LocalName) { case "node": var n = new PhraseDialogGraphNode(); int charId; if (xNode.TryGetAttribute("characterId", out charId)) n.Character = tmpCharacters[charId].Name; n.Phrase = xNode.Value; node = n; break; case "empty": node = new EmptyDialogGraphNode(); break; case "answer": node = new AnswerCollectionDialogGraphNode(); break; } if (node != null) { node.Id = id; _graph.ForceInsertNode(node); } } } if(xLinks!=null) { foreach(var xLink in xLinks.Elements("link")) { int from, to; if (!xLink.TryGetAttribute("from", out from) || !xLink.TryGetAttribute("to", out to)) continue; var link = Graph.Link(from, to); int fromNodeDefault; if(nodeDefaultLinks.TryGetValue(to,out fromNodeDefault) && fromNodeDefault==from) { var node = _graph.GetNode(to); node.DefaultLinkHere = link; } } } } }
public bool TryGetCharacter(string name, out DialogCharacter character) { character = DialogCharacters.FirstOrDefault(c => c.Name == name); return character != null; }
public bool IsActiveCharacter(DialogCharacter ch) { return Graph.AnyNode<PhraseDialogGraphNode>(node => node.Character == ch.Name); }
public void CallDialog(DialogCharacter tarChar, DialogCharacter recievingChar, int initalDialogState = 0) { Char1 = tarChar; Char2 = recievingChar; SetUpDialog(initalDialogState); }
private void ShowCharacterName(CharacterData data, DialogCharacter character) { _nameCharacterObject.SetActive(true); _nameCharacterObject.transform.position = GetNamePositiion(character); _nameCharacterText.text = _providerTexts[data.NameID]; }