protected override Status OnExecute(Component agent, IBlackboard bb) { if (outConnections.Count == 0) { return(Error("There are no connections to the Multiple Choice Node!")); } var finalOptions = new Dictionary <IStatement, int>(); for (var i = 0; i < availableChoices.Count; i++) { var condition = availableChoices[i].condition; if (condition == null || condition.CheckOnce(finalActor.transform, bb)) { var tempStatement = availableChoices[i].statement.BlackboardReplace(bb); finalOptions[tempStatement] = i; } } if (finalOptions.Count == 0) { ParadoxNotion.Services.Logger.Log("Multiple Choice Node has no available options. Dialogue Ends.", LogTag.EXECUTION, this); DLGTree.Stop(false); return(Status.Failure); } var optionsInfo = new MultipleChoiceRequestInfo(finalActor, finalOptions, availableTime, OnOptionSelected); optionsInfo.showLastStatement = inConnections.Count > 0 && inConnections[0].sourceNode is StatementNode; DialogueTree.RequestMultipleChoices(optionsInfo); return(Status.Running); }
protected override Status OnExecute(Component agent, IBlackboard bb){ if (outConnections.Count == 0) return Error("There are no connections to the Multiple Choice Node!"); var finalOptions = new Dictionary<IStatement, int>(); for (var i = 0; i < availableChoices.Count; i++){ var condition = availableChoices[i].condition; if (condition == null || condition.CheckCondition(finalActor.transform, bb)){ var tempStatement = availableChoices[i].statement.BlackboardReplace(bb); finalOptions[tempStatement] = i; } } if (finalOptions.Count == 0){ Debug.Log("Multiple Choice Node has no available options. Dialogue Ends"); DLGTree.Stop(); return Status.Failure; } if (availableTime > 0) StartCoroutine(CountDown()); var optionsInfo = new MultipleChoiceRequestInfo(finalOptions, availableTime, OnOptionSelected); DialogueTree.RequestMultipleChoices( optionsInfo ); return Status.Running; }
///Raise the OnMultipleChoiceRequest event public static void RequestMultipleChoices(MultipleChoiceRequestInfo info) { if (OnMultipleChoiceRequest != null) { OnMultipleChoiceRequest(info); } else { Logger.LogWarning("Multiple Choice Request event has no subscribers. Make sure to add the default '@DialogueGUI' prefab or create your own GUI.", "Dialogue Tree"); } }
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); }
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()); } }
protected override Status OnExecute(Component agent, IBlackboard bb) { if (outConnections.Count == 0) { return(Error("There are no connections to the Multiple Choice Node!")); } var finalOptions = new Dictionary <IStatement, int>(); for (var i = 0; i < availableChoices.Count; i++) { var condition = availableChoices[i].condition; if (condition == null || condition.CheckCondition(finalActor.transform, bb)) { var tempStatement = availableChoices[i].statement.BlackboardReplace(bb); finalOptions[tempStatement] = i; } } if (finalOptions.Count == 0) { Debug.Log("Multiple Choice Node has no available options. Dialogue Ends"); DLGTree.Stop(); return(Status.Failure); } if (availableTime > 0) { StartCoroutine(CountDown()); } var optionsInfo = new MultipleChoiceRequestInfo(finalOptions, availableTime, OnOptionSelected); DialogueTree.RequestMultipleChoices(optionsInfo); return(Status.Running); }
///Raise the OnMultipleChoiceRequest event public static void RequestMultipleChoices(MultipleChoiceRequestInfo info){ if (OnMultipleChoiceRequest != null) OnMultipleChoiceRequest(info); else Debug.LogWarning("<b>DialogueTree:</b> Multiple Choice Request event has no subscribers. Make sure to add the default '@DialogueGUI' prefab or create your own GUI."); }
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)); } }