Hey Tony. I'm not sure if this is a correct behaviour or if I've missed something.
I have my response button transition set to Sprite Swap. The disabled sprite is supposed to show up on locked options where you don't have the required stat.
But when you choose a normal option, it switches to the disabled sprite upon pressing.
Is there a way to avoid this?
Response Button Disabled Sprite - shows up when button is pressed?
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Response Button Disabled Sprite - shows up when button is pressed?
When you click a response button, the StandardUIMenuPanel disables all response buttons so the player can't click more response buttons while the menu's Hide animation is playing.
To disable this, make a subclass of StandardUIMenuPanel. Something like:
MenuPanelNoDisable.cs
Then use the subclass in place of StandardUIMenuPanel. To replace a component in-place and retain UI element assignments, change the Inspector to Debug mode. (Use the triple-dot menu in the upper right of the Inspector.) Then drag the MenuPanelNoDisable script into the Standard UI Menu Panel component's Script field.
The drawback of the script above is that the response buttons will still be clickable until the response menu is turned off.
To address that, you could add a Canvas Group component to the menu panel. Then MakeButtonsNonclickable() can set the Canvas Group component's interactable property false. This will set the panel and all of its children (i.e., the response buttons) non-interactable. You'll want to set CanvasGroup.interactable back to true in ShowResponses():
MenuPanelNoDisable.cs
To disable this, make a subclass of StandardUIMenuPanel. Something like:
MenuPanelNoDisable.cs
Code: Select all
using PixelCrushers.DialogueSystem;
public class MenuPanelNoDisable : StandardUIMenuPanel
{
public override void MakeButtonsNonclickable()
{
// (Do nothing; don't disable buttons.)
}
}
The drawback of the script above is that the response buttons will still be clickable until the response menu is turned off.
To address that, you could add a Canvas Group component to the menu panel. Then MakeButtonsNonclickable() can set the Canvas Group component's interactable property false. This will set the panel and all of its children (i.e., the response buttons) non-interactable. You'll want to set CanvasGroup.interactable back to true in ShowResponses():
MenuPanelNoDisable.cs
Code: Select all
using PixelCrushers.DialogueSystem;
using UnityEngine;
public class MenuPanelNoDisable : StandardUIMenuPanel
{
public override void MakeButtonsNonclickable()
{
panel.GetComponent<CanvasGroup>().interactable = false;
}
public override void ShowResponses(Subtitle subtitle, Response[] responses, Transform target)
{
panel.GetComponent<CanvasGroup>().interactable = true;
base.ShowResponses(subtitle, responses, target);
}
}
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Response Button Disabled Sprite - shows up when button is pressed?
Ah I see, I wondered if it was that. I'll try that solution, thanks!
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Response Button Disabled Sprite - shows up when button is pressed?
Hey Tony, apologies if this is a dumb question but are these two different solutions, or should I be doing both?
I tried the first script and it worked as you said, disabled sprites weren't showing but buttons were still clickable.
I tried the second one but the disabled sprites were still showing up.
But when I use both together, I get this error.
I tried the first script and it worked as you said, disabled sprites weren't showing but buttons were still clickable.
I tried the second one but the disabled sprites were still showing up.
But when I use both together, I get this error.
Re: Response Button Disabled Sprite - shows up when button is pressed?
Hi,
Just use the second part. The first part was an illustration of the first step, which is to prevent the menu panel from disabling the buttons as soon as one button is clicked. The second part extends that script to disable clicking on other buttons as soon as one is clicked. I'll recap that step by itself here:
1. Add a Canvas Group component to the menu panel if it doesn't already have one.
2. Make sure the menu panel is assigned to your Standard UI Menu Panel component's Panel field.
3. Create this script:
4. Inspect the menu panel, and change the Inspector to Debug mode.
5. Drag the MenuPanelNoDisable script into the Standard UI Menu Panel component's Script field.
Just use the second part. The first part was an illustration of the first step, which is to prevent the menu panel from disabling the buttons as soon as one button is clicked. The second part extends that script to disable clicking on other buttons as soon as one is clicked. I'll recap that step by itself here:
1. Add a Canvas Group component to the menu panel if it doesn't already have one.
2. Make sure the menu panel is assigned to your Standard UI Menu Panel component's Panel field.
3. Create this script:
MenuPanelNoDisable.cs
Code: Select all
using PixelCrushers.DialogueSystem;
using UnityEngine;
public class MenuPanelNoDisable : StandardUIMenuPanel
{
public override void MakeButtonsNonclickable()
{
panel.GetComponent<CanvasGroup>().interactable = false;
}
public override void ShowResponses(Subtitle subtitle, Response[] responses, Transform target)
{
panel.GetComponent<CanvasGroup>().interactable = true;
base.ShowResponses(subtitle, responses, target);
}
}
5. Drag the MenuPanelNoDisable script into the Standard UI Menu Panel component's Script field.
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Response Button Disabled Sprite - shows up when button is pressed?
Awesome thanks for clarifying, it's working perfectly now
Re: Response Button Disabled Sprite - shows up when button is pressed?
Great! Glad I could help.