示例#1
0
    public override IEnumerator RunOptions(Options optionsCollection, OptionChooser optionChooser)
    {
        // Do a little bit of safety checking
        if (optionsCollection.options.Count > optionButtons.Count)
        {
            Debug.LogWarning("There are more options to present than there are" +
                             "buttons to present them in. This will cause problems.");
        }

        // Display each option in a button, and make it visible
        int i = 0;

        foreach (var optionString in optionsCollection.options)
        {
            optionButtons[i].gameObject.SetActive(true);
            optionButtons[i].text = optionString;
            i++;
        }

        // Record that we're using it
        SetSelectedOption = optionChooser;

        // Wait until the chooser has been used and then removed (see SetOption below)
        while (SetSelectedOption != null)
        {
            yield return(null);
        }

        // Hide all the buttons
        foreach (var button in optionButtons)
        {
            button.gameObject.SetActive(false);
        }
    }
示例#2
0
    public void SetOption(int selectedOption)
    {
        // Call the delegate to tell the dialogue system that we've
        // selected an option.
        SetSelectedOption(selectedOption);

        // Now remove the delegate so that the loop in RunOptions will exit
        SetSelectedOption = null;
    }
示例#3
0
    /// Called by buttons to make a selection.
    public void SetOption(int selectedOption)
    {
        // Call the delegate to tell the dialogue system that we've
        // selected an option.
        SetSelectedOption(selectedOption);


        // Now remove the delegate so that the loop in RunOptions will exit
        SetSelectedOption = null;

        dialogueContainer.GetComponent <Image>().enabled = true;
    }
示例#4
0
    /// Called by buttons to make a selection.
    public void SetOption(int selectedOption)
    {
        //TO DO selectedOption is one of the randomnized options
        //if (nothing)
        //{
        //    var randomOption = UnityEngine.Random.Range(0, 3);
        //    selectedOption = randomOption;
        //    nothing = false;
        //}

        // Call the delegate to tell the dialogue system that we've
        // selected an option.
        SetSelectedOption(selectedOption);

        // Now remove the delegate so that the loop in RunOptions will exit
        SetSelectedOption = null;
    }
示例#5
0
    /// Show a list of options, and wait for the player to make a selection.
    public override IEnumerator RunOptions(Yarn.Options optionsCollection,
                                           Yarn.OptionChooser optionChooser)
    {
        // Do a little bit of safety checking
        if (optionsCollection.options.Count > optionButtons.Count)
        {
            Debug.LogWarning("There are more options to present than there are" +
                             "buttons to present them in. This will cause problems.");
        }

        // Display each option in a button, and make it visible
        int i = 0;

        foreach (var optionString in optionsCollection.options)
        {
            optionButtons[i].gameObject.SetActive(true);
            //TO DO animate the button
            optionButtons[i].GetComponentInChildren <TMP_Text>().text = optionString;
            i++;
        }

        //start the timer of how long the player takes to answer
        //count = true;
        //if (count == true)
        //{
        //    optionButtons[0].GetComponent<TimerDialogue>().StartCount();
        //    count = false;
        //}

        // Record that we're using it
        SetSelectedOption = optionChooser;

        // Wait until the chooser has been used and then removed (see SetOption below)
        while (SetSelectedOption != null)
        {
            yield return(null);
        }

        // Hide all the buttons
        foreach (var button in optionButtons)
        {
            button.gameObject.SetActive(false);
            //TO DO animate the button going away
        }
    }
示例#6
0
    public override IEnumerator RunOptions(Options optionsCollection, OptionChooser optionChooser)
    {
        ConversationBox.SetActive(true);
        int childCount = ConversationOptions.transform.childCount;

        for (int currentChild = childCount - 1; currentChild >= 0; currentChild--)
        {
            var childObject = ConversationOptions.transform.GetChild(currentChild).gameObject;
            if (childObject.name == "OptionPrefab")
            {
                continue;
            }
            Destroy(childObject);
        }

        for (int currentOption = 0; currentOption < optionsCollection.options.Count; currentOption++)
        {
            var option       = optionsCollection.options[currentOption];
            var optionButton = Instantiate(OptionPrefab);
            optionButton.gameObject.SetActive(true);
            optionButton.transform.SetParent(ConversationOptions.transform, false);
            optionButton.enabled = true;
            var optionText = optionButton.GetComponentInChildren <Text>();
            optionText.text    = option;
            optionText.enabled = true;
            var optionImage = optionButton.GetComponent <Image>();
            optionImage.enabled = true;
            SetSelectedOption   = optionChooser;

            int selectedOption = currentOption;
            optionButton.onClick.AddListener(() =>
            {
                ConversationBox.SetActive(false);
                optionChooser(selectedOption);
                SetSelectedOption = null;
            });
        }

        while (SetSelectedOption != null)
        {
            yield return(null);
        }
    }
    //Mostly stolen outright from the example
    public override IEnumerator RunOptions(Options optionsCollection, OptionChooser optionChooser)
    {
        if (optionsCollection.options.Count > optionButtons.Count)
        {
            Debug.LogWarning("There are more options to present than there are" +
                             "buttons to present them in. This will cause problems.");
        }

        if (choicePanel)
        {
            choicePanel.SetActive(true);
        }

        int i = 0;

        foreach (var optionString in optionsCollection.options)
        {
            optionButtons[i].gameObject.SetActive(true);
            optionButtons[i].GetComponentInChildren <Text>().text = optionString;
            i++;
        }

        // Set the delegate that this script uses to the one passed as an argument from Yarn
        optionChoiceDelegate = optionChooser;

        // Wait until the chooser has been used and then removed (see SetOption below)
        while (optionChoiceDelegate != null)
        {
            yield return(null);
        }

        // Hide all the buttons
        if (choicePanel)
        {
            choicePanel.SetActive(false);
        }
        foreach (var button in optionButtons)
        {
            button.gameObject.SetActive(false);
        }
    }
    /* This is called by buttons, menu choices, etc.
     * */
    public void SetOption(int selectedOption)
    {
        /* Does this need some sort of guarantee that the delegate isn't null?
         * This _should_ never happen, but as a "something absolutely wild has happened" guarantee?
         * */

        // Call the delegate to tell the dialogue system that we've
        // selected an option.
        try
        {
            optionChoiceDelegate(selectedOption);
        }
        catch (System.Exception)
        {
            throw;
        }
        finally
        {
            // Now remove the delegate so that the loop in RunOptions will exit
            optionChoiceDelegate = null;
        }
    }
    IEnumerator ShowOptions(Yarn.Options optionsCollection, Yarn.OptionChooser optionChooser)
    {
        contentField.enabled = false;
        if (optionsCollection.options.Count > optionButtons.Length)
        {
            Debug.LogWarning("There are more options to present than there are" +
                             "buttons to present them in. This will cause problems.");
        }

        showingOptions = true;

        for (int i = 0; i < Math.Min(optionButtons.Length, optionsCollection.options.Count); i++)
        {
            optionButtons[i].button.enabled    = true;
            optionButtons[i].buttonBG.enabled  = true;
            optionButtons[i].textField.enabled = true;
            optionButtons[i].textField.text    = optionsCollection.options[i];
            int index = i;
            optionButtons[i].button.onClick.AddListener(() =>
            {
                showingOptions = false;
                optionChooser(index);
            }
                                                        );
        }

        while (showingOptions)
        {
            yield return(null);
        }

        for (int i = 0; i < optionButtons.Length; i++)
        {
            optionButtons[i].button.enabled    = false;
            optionButtons[i].buttonBG.enabled  = false;
            optionButtons[i].textField.enabled = false;
            optionButtons[i].button.onClick.RemoveAllListeners();
        }
    }
示例#10
0
 private void SetOption(int selectedOption, OptionChooser optionChooser)
 {
     Debug.Log(selectedOption);
     optionChooser(selectedOption);
     SetSelectedOption = null;
 }