void OnMultipleChoiceRequest(MultipleChoiceRequestInfo info) { optionsGroup.gameObject.SetActive(true); var buttonHeight = optionButton.GetComponent <RectTransform>().rect.height; optionsGroup.sizeDelta = new Vector2(optionsGroup.sizeDelta.x, (info.options.Values.Count * buttonHeight) + 20); cachedButtons = new Dictionary <Button, int>(); int i = 0; foreach (KeyValuePair <IStatement, int> pair in info.options) { var btn = (Button)Instantiate(optionButton); btn.gameObject.SetActive(true); btn.transform.SetParent(optionsGroup.transform, false); btn.transform.localPosition = (Vector2)optionButton.transform.localPosition - new Vector2(0, buttonHeight * i); btn.GetComponentInChildren <Text>().text = pair.Key.text; cachedButtons.Add(btn, pair.Value); btn.onClick.AddListener(() => { Finalize(info, cachedButtons[btn]); }); i++; } if (info.showLastStatement) { subtitlesGroup.gameObject.SetActive(true); var newY = optionsGroup.position.y + optionsGroup.sizeDelta.y + 1; subtitlesGroup.position = new Vector2(subtitlesGroup.position.x, newY); } if (info.availableTime > 0) { StartCoroutine(CountDown(info)); } }
//Countdown for the available time. Picking a choice is done by the graph when it ends. All we need to do is to show and stop //showing the UI IEnumerator GUICountDown(){ while (timer > 0){ timer -= Time.deltaTime; yield return null; } currentOptions = null; }
//Countdown for the available time. Picking a choice is done by the graph when it ends. All we need to do is to show and stop //showing the UI IEnumerator GUICountDown() { while (timer > 0) { timer -= Time.deltaTime; yield return(null); } currentOptions = null; }
//A function with the same name as the subscribed Event is called when the event is dispatched void OnMultipleChoiceRequest(MultipleChoiceRequestInfo optionsInfo){ enabled = true; currentOptions = optionsInfo; timer = optionsInfo.availableTime; StopCoroutine("GUICountDown"); if (timer > 0) StartCoroutine("GUICountDown"); }
//A function with the same name as the subscribed Event is called when the event is dispatched void OnMultipleChoiceRequest(MultipleChoiceRequestInfo optionsInfo) { enabled = true; currentOptions = optionsInfo; timer = optionsInfo.availableTime; StopCoroutine("GUICountDown"); if (timer > 0) { StartCoroutine("GUICountDown"); } }
void OnDialogueFinished(DialogueTree dialogue){ StopAllCoroutines(); displayText = null; if (currentActor != null) currentActor.speech = null; currentOptions = null; StopCoroutine("GUICountDown"); enabled = false; }
void OnDialogueFinished(DialogueTree dialogue) { StopAllCoroutines(); displayText = null; if (currentActor != null) { currentActor.speech = null; } currentOptions = null; StopCoroutine("GUICountDown"); enabled = false; }
void Finalize(MultipleChoiceRequestInfo info, int index) { isWaitingChoice = false; SetMassAlpha(optionsGroup, 1f); optionsGroup.gameObject.SetActive(false); if (info.showLastStatement) { subtitlesGroup.gameObject.SetActive(false); subtitlesGroup.transform.position = originalSubsPosition; } foreach (var tempBtn in cachedButtons.Keys) { Destroy(tempBtn.gameObject); } info.SelectOption(index); }
void DoMultipleChoiceGUI() { //Calculate the y size needed var neededHeight = timer > 0? 20f : 0f; foreach (var statement in currentOptions.options.Keys) { neededHeight += new GUIStyle("box").CalcSize(new GUIContent(statement.text)).y; } //show the choices which are within a Dictionary of Statement and the int whic is the Index we need to //callback when an option is selected var optionsRect = new Rect(10, Screen.height - neededHeight - 10, Screen.width - 20, neededHeight); GUILayout.BeginArea(optionsRect); foreach (var option in currentOptions.options) { //When a choice is selected we need to Callback with the index of the statement choice selected if (GUILayout.Button(option.Key.text, new GUIStyle("box"), GUILayout.ExpandWidth(true))) { StopCoroutine("GUICountDown"); //we do the following caching in case another multiple choice is requested DUE to the callback immediately var callback = currentOptions.SelectOption; currentOptions = null; callback(option.Value); return; } } //show the countdown UI if (timer > 0) { var blue = GUI.color.b; var green = GUI.color.g; blue = timer / currentOptions.availableTime * 0.5f; green = timer / currentOptions.availableTime * 0.5f; GUI.color = new Color(1f, green, blue); GUILayout.Box("...", GUILayout.Height(5), GUILayout.Width(timer / currentOptions.availableTime * optionsRect.width)); } GUILayout.EndArea(); }
void OnMultipleChoiceRequest(MultipleChoiceRequestInfo info) { infos = info; /*optionsGroup.gameObject.SetActive(true); * var buttonHeight = optionButton.GetComponent<RectTransform>().rect.height; * optionsGroup.sizeDelta = new Vector2(optionsGroup.sizeDelta.x, (info.options.Values.Count * buttonHeight) + 20); */ cachedButtons = new Dictionary <Button, int>(); int i = 0; foreach (KeyValuePair <IStatement, int> pair in info.options) { /*var btn = (Button)Instantiate(optionButton); * btn.gameObject.SetActive(true); * btn.transform.SetParent(optionsGroup.transform, false); * btn.transform.localPosition = (Vector2)optionButton.transform.localPosition - new Vector2(0, buttonHeight * i); * btn.GetComponentInChildren<Text>().text = pair.Key.text; * cachedButtons.Add(btn, pair.Value); * btn.onClick.AddListener( ()=> { Finalize(info, cachedButtons[btn]); }); */ var d = dialogues[i + 1]; d.gameObject.SetActive(true); d.GetComponentInChildren <Animator>().Play("fenetreApparait"); reponsestemps[i + 1] = pair.Value; TMP = d.GetComponentInChildren <TMPro.TextMeshPro>(); TMP.text = pair.Key.text; i++; } /*if (info.showLastStatement){ * subtitlesGroup.gameObject.SetActive(true); * var newY = optionsGroup.position.y + optionsGroup.sizeDelta.y + 1; * subtitlesGroup.position = new Vector2(subtitlesGroup.position.x, newY); * } * * if (info.availableTime > 0){ * StartCoroutine(CountDown(info)); * }*/ }
IEnumerator CountDown(MultipleChoiceRequestInfo info) { isWaitingChoice = true; var timer = 0f; while (timer < info.availableTime) { if (isWaitingChoice == false) { yield break; } timer += Time.deltaTime; SetMassAlpha(optionsGroup, Mathf.Lerp(1, 0, timer / info.availableTime)); yield return(null); } if (isWaitingChoice) { Finalize(info, info.options.Values.Last()); } }
void DoMultipleChoiceGUI() { //Calculate the y size needed var neededHeight = timer > 0? 20f : 0f; foreach (var statement in currentOptions.options.Keys) neededHeight += new GUIStyle("box").CalcSize(new GUIContent(statement.text)).y; //show the choices which are within a Dictionary of Statement and the int whic is the Index we need to //callback when an option is selected var optionsRect= new Rect(10, Screen.height - neededHeight - 10, Screen.width - 20, neededHeight); GUILayout.BeginArea(optionsRect); foreach (var option in currentOptions.options){ //When a choice is selected we need to Callback with the index of the statement choice selected if (GUILayout.Button(option.Key.text, new GUIStyle("box"), GUILayout.ExpandWidth(true))){ StopCoroutine("GUICountDown"); //we do the following caching in case another multiple choice is requested DUE to the callback immediately var callback = currentOptions.SelectOption; currentOptions = null; callback(option.Value); return; } } //show the countdown UI if (timer > 0){ var blue = GUI.color.b; var green = GUI.color.g; blue = timer / currentOptions.availableTime * 0.5f; green = timer / currentOptions.availableTime * 0.5f; GUI.color = new Color(1f, green, blue); GUILayout.Box("...", GUILayout.Height(5), GUILayout.Width(timer / currentOptions.availableTime * optionsRect.width)); } GUILayout.EndArea(); }