/// <summary> /// Offers the trade, presenting the given text. Success delegate is called before the enumerator /// finishes but after the trade is performed. /// </summary> /// <returns>The trade.</returns> /// <param name="trade">Trade.</param> /// <param name="tradeText">Trade text.</param> /// <param name="success">Success.</param> public static IEnumerator OfferTrade(TradingOffer trade, string tradeText, System.Action <TradingResult> success) { var acceptOption = new DialogBox.Choice("Accept", () => { if (PerformTrade(trade)) { success(TradingResult.SUCCEED); PlayClip(instance.acceptSound); } else { success(TradingResult.FAILACCEPT); } }); var denyOption = new DialogBox.Choice("Deny", () => { success(TradingResult.FAILDENY); PlayClip(instance.declineSound); }); yield return(DialogSystem.Instance().DisplayMessageAndChoices(tradeText, acceptOption, denyOption)); }
/// <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); } }