public override bool inited() { SolaEngine engine = SolaEngine.getInstance(); HeroMgr hMgr = (HeroMgr)engine.getMgr(typeof(HeroMgr)); List <DialogueInfoConfig> infoCfgs = (List <DialogueInfoConfig>)engine.getCfg(DialogueInfoConfigData.NAME); for (int i = 0; i < infoCfgs.Count; i++) { DialogueInfoConfig infoCfg = infoCfgs[i]; DialogueInfoModel infoModel = new DialogueInfoModel(); infoModel.setCfg(infoCfg, hMgr); int id = infoModel.getId(); _dialogueInfoModels.Add(id, infoModel); } List <DialogueConfig> cfgs = (List <DialogueConfig>)engine.getCfg(DialogueConfigData.NAME); for (int i = 0; i < cfgs.Count; i++) { DialogueConfig cfg = cfgs[i]; DialogueModel model = new DialogueModel(); model.setCfg(cfg, this); int id = model.getId(); _dialogueModels.Add(id, model); } MissionMgr mMgr = (MissionMgr)engine.getMgr(typeof(MissionMgr)); mMgr.initDialogueInfo(this); return(true); }
//Slowly draws text on a screen. Skippable. IEnumerator DrawText(string text, string speakerName) { TMPro.TextMeshProUGUI storyText = Instantiate(textPrefab) as TMPro.TextMeshProUGUI; storyText.transform.SetParent(textArea.transform, false); storyText.maxVisibleCharacters = 0; Assert.IsTrue(speakersDic.ContainsKey(speakerName)); DialogueConfig speaker = speakersDic[speakerName]; string addColor = TagsUtility.AddColorTag(text, speaker.speaker_color); storyText.text += addColor; storyText.font = speaker.font; storyText.fontSize = textSize; for (int i = 0; i < text.Length; i++) { if (mouseKeyPressed) { mouseKeyPressed = false; storyText.maxVisibleCharacters += (text.Length - i); break; } storyText.maxVisibleCharacters++; yield return(new WaitForSeconds(speaker.time_between_characters)); } yield return(new WaitForSeconds(speaker.time_between_sentences)); RefreshView(); }
public void setCfg(DialogueConfig cfg, DialogueMgr dMgr) { _infoModelIndex = 0; _isEnded = false; _id = Convert.ToInt32(cfg.id); _models = new List <DialogueInfoModel> (); foreach (object contentId in cfg.content) { int id = Convert.ToInt32(contentId); DialogueInfoModel infoModel = dMgr.getInfoModel(id); _models.Add(infoModel); } }
//Displays the choices as text on a screen and adds listeners to the buttons. IEnumerator DisplayChoices() { TMPro.TextMeshProUGUI blank = Instantiate(textPrefab) as TMPro.TextMeshProUGUI; blank.transform.SetParent(textArea.transform, false); blank.text = " "; DialogueConfig choices = speakersDic["Choice"]; for (int i = 0; i < story.currentChoices.Count; i++) { Choice choice = story.currentChoices[i]; GameObject button = Instantiate(choicePrefab); button.transform.SetParent(textArea.transform); button.GetComponent <Button>().onClick.AddListener(() => { story.ChooseChoiceIndex(choice.index); pickingChoice = false; RefreshView(); }); TMPro.TextMeshProUGUI buttonCurrentText = button.GetComponent <TMPro.TextMeshProUGUI>(); buttonCurrentText.fontSize = choiceSize; buttonCurrentText.font = choices.font; buttonCurrentText.text = AddSpaces(choice.text); buttonCurrentText.maxVisibleCharacters = 0; button.transform.localScale = new Vector3(1, 1, 1); LayoutRebuilder.ForceRebuildLayoutImmediate(textAreaVertical.GetComponent <RectTransform>()); for (int j = 0; j < choice.text.Length + numSpaces; j++) { buttonCurrentText.maxVisibleCharacters++; yield return(new WaitForSeconds(choices.time_between_characters)); } yield return(new WaitForSeconds(choices.time_between_sentences)); } yield break; }
public DialogueConfigData() { _dataJson = SimpleJson.SimpleJson.DeserializeObject <JsonArray> (_data).ToArray(); foreach (object jsonObject in _dataJson) { JsonObject jo = (JsonObject)jsonObject; DialogueConfig config = new DialogueConfig(); _dataList.Add(config); foreach (string key in jo.Keys) { object value = jo[key]; System.Type type = typeof(DialogueConfig); System.Reflection.FieldInfo info = type.GetField(key); if (info == null) { continue; } if (value is JsonArray) { JsonArray jarr = (JsonArray)value; int jarrSize = jarr.Count; if (info.FieldType.FullName == "System.Int32[]") { int[] data = new int[jarrSize]; for (int i = 0; i < jarrSize; i++) { data[i] = (int)jarr[i]; } info.SetValue(config, data); } else { string[] data = new string[jarrSize]; for (int i = 0; i < jarrSize; i++) { data[i] = (string)jarr[i]; } info.SetValue(config, data); } } else { info.SetValue(config, value); } } } _dataJson = null; _data = null; }
// Use this for initialization void Start() { cameraController = Camera.main.GetComponent <CameraController>(); language = languages[0]; TextAsset data = Resources.Load(language) as TextAsset; string dataString = data.ToString(); config = JsonUtility.FromJson <DialogueConfig> (dataString); answers = new Answer[config.MaxLines]; for (int i = 0; i < answers.Length; ++i) { answers [i] = Answer.None; } narration.text = config.narration; localLine.gameObject.SetActive(false); // touristLine.gameObject.SetActive (false); statementLine.gameObject.SetActive(false); questionButton1.gameObject.SetActive(false); questionButton2.gameObject.SetActive(false); questionButton1.onClick.AddListener(delegate() { OnClick(questionButton1); }); questionButton2.onClick.AddListener(delegate() { OnClick(questionButton2); }); }