Ejemplo n.º 1
0
    private void Start()
    {
        selectionsContainer = container.Find("selections");
        runtimeFactory      = (new RuntimeFactory(new EntityLoader(resourceLoadPath)))
                              .OnDialogueTreeBegin(DialogueTreeBegin)
                              .OnDialogueTreeFinished(DialogueTreeFinished)
                              .OnDialogueReady(DialogueUIUpdate)
                              .OnOptionContinuing(DialogueOptionSelected)
                              .SetVariables(new Dictionary <string, string>()
        {
            { "title", "captain" },
            { "gold", "100f" }
        });

        continueButton.onClick.AddListener(() => runtime.Continue());
        actorContainer = container.Find("actor");
    }
Ejemplo n.º 2
0
    protected void DialogueUIUpdate(DialogueRuntime runtime, CurrentDialogue dialogue)
    {
        text.text = dialogue.Text;

        selectionsContainer.gameObject.SetActive(false);

        continueButton.gameObject.SetActive(!dialogue.HasSelections);

        actorContainer.gameObject.SetActive(dialogue.Actor != null ? true : false);

        if (continueButton.gameObject.activeSelf)
        {
            continueButton.transform.Find("text").GetComponent <Text>().text = dialogue.IsEnding ? "Finish" : "Next";
        }

        if (actorContainer.gameObject.activeSelf)
        {
            actorContainer.Find("text").GetComponent <Text>().text = dialogue.Actor;
        }

        if (dialogue.HasSelections)
        {
            selectionsContainer.gameObject.SetActive(true);

            dialogue.Selections.ForEach(selection => {
                var option = GameObject.Instantiate(sampleOption);

                option.name = "row_selection";

                option.gameObject.SetActive(true);

                option.Find("text").GetComponent <Text>().text = selection.Text;

                option.GetComponent <Button>().onClick.AddListener(() => runtime.Continue(selection));

                option.SetParent(selectionsContainer);
            });
        }
    }