Page 1 of 1

Customising Invalid Entries

Posted: Thu Jun 29, 2017 11:29 am
by astroimpossible
Hey, I've set up a project where invalid entries are shown, but wanted to customise them a bit. So far I've set up a script in ResponseButtonTemplate that runs as each button is created, and if the entry is invalid (it bases this on whether the Button is interactable or not), enables a small tooltip giving a message about why the response is disabled.

So far so good, but the next step is to only show certain invalid responses - there's some responses I never want to show if they fail the condition check. I was wondering if there's a way of retrieving the current ID of the response within my button script? This way I could base a check upon it - e.g. if ID = 15, set Button to inactive. Another option is to base the check upon a new dialogue field (e.g. a "NeverShowIfInvalid" bool), though I'd still need to access it as each button is created.

Hope this makes sense! If there's another way I haven't thought of, please let me know :)

Re: Customising Invalid Entries

Posted: Thu Jun 29, 2017 2:01 pm
by Tony Li
Hi,

If you're using Unity UI, every button has a UnityUIResponseButton component with a response property. The response has two useful properties:
  • enabled (bool): True if the response is valid, false if it's invalid.
  • destinationEntry (DialogueEntry): The dialogue entry that the response leads to. You can check its id property to get the ID, or use Field.LookupValue(destinationEntry.fields) to grab info from any fields you've defined in your dialogue entries.
Here's an example of one way you might set it up:

First, let's say you've defined two custom fields:
  • ShowIfInvalid (Boolean): Specifies whether to show or hide the button if invalid.
  • InvalidTooltip (Text): The tooltip text to show if the entry is invalid.
Then add a script like this to your button template:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ExtraResponseButtonStuff : MonoBehaviour
{
    void Start()
    {
        var response = GetComponent<UnityUIResponseButtonTemplate>().response;
        if (!response.enabled)
        {
            // Invalid response. Do special stuff:
            var entry = response.destinationEntry;
            var showIfInvalid = Field.LookupBool(entry.fields, "ShowIfInvalid");
            var tooltip = Field.LookupValue(entry.fields, "InvalidTooltip");
            if (showIfInvalid)
            {
                // Set tooltip text to value of the tooltip variable.
            }
            {
                gameObject.SetActive(false);
            }
        }
    }
}

Re: Customising Invalid Entries

Posted: Fri Jun 30, 2017 5:29 am
by astroimpossible
That's exactly what I was after. Works perfectly - thank you! :D

Re: Customising Invalid Entries

Posted: Fri Jun 30, 2017 9:07 am
by Tony Li
Glad I could help!