コード例 #1
0
ファイル: DialogSystem.cs プロジェクト: timoffex/Birdkeeper
 private DialogBox.ChoiceSelect CombineDelegates(DialogBox.ChoiceSelect c0, DialogBox.ChoiceSelect c1)
 {
     return(delegate() {
         c0();
         c1();
     });
 }
コード例 #2
0
ファイル: DialogSystem.cs プロジェクト: timoffex/Birdkeeper
    /// <summary>
    /// A coroutine that displays a message with some choices and stops when
    /// a choice is picked.
    /// </summary>
    /// <param name="text">The message to display.</param>
    /// <param name="choices">The choices to give to the user. If empty, the call
    /// is equivalent to DisplayMessage (text).</param>
    public IEnumerator DisplayMessageAndChoices(string text, params DialogBox.Choice[] choices)
    {
        if (choices.Length == 0)         // If no choices provided, just use the default display with the continue button.
        {
            yield return(DisplayMessage(text));
        }
        else
        {
            var dbox = MakeNewDialogBox();


            // This will be false until a choice is selected.
            bool choiceSelected = false;


            // Makes the provided choices set the "choiceSelected" variable to true.
            var wrappedChoices = new DialogBox.Choice[choices.Length];
            for (int i = 0; i < choices.Length; i++)
            {
                var num    = i;
                var choice = choices [num];

                string t = choice.text;
                DialogBox.ChoiceSelect del = CombineDelegates(() => {
                    choiceSelected = true;
                }, choice.choiceDelegate);

                wrappedChoices [i] = new DialogBox.Choice(t, del);
            }


            dbox.DisplayMessageAndChoices(text, wrappedChoices);


            yield return(new WaitUntil(() => choiceSelected));

            Destroy(dbox.gameObject);
        }
    }