Hi,
Here are two ways you could approach this:
1. Set up two response menu panels: one with two response buttons, one with four response buttons. Make a subclass of StandardDialogueUI and override ShowResponsesImmediate():
Code: Select all
public class MyDialogueUI : StandardDialogueUI
{
protected override void ShowResponsesImmediate(Subtitle subtitle, Response[] responses, float timeout)
{
// Use menu panel 0 for 1-2 responses, menu panel 1 for 3+ responses:
var menuPanelToUse = conversationUIElements.menuPanels[(responses.Length <= 2) ? 0 : 1];
conversationUIElements.standardMenuControls.ForceOverrideMenuPanel(menuPanelToUse);
base.ShowResponsesImmediate(subtitle, responses, timeout);
}
}
Then replace your dialogue UI's StandardDialogueUI component with the subclass
in place, and assign the menus panels to the Menu Panels list.
2. Or use a single menu panel. Don't make a subclass of StandardDialogueUI. Instead, make a subclass of StandardUIMenuPanel and replace the StandardUIMenuPanel component on the menu panel. Instead of a Vertical Layout Group as most of the built-in prefabs have, use a Grid Layout Group. Override the ShowResponses() method to configure the Grid Layout Group to use 2 columns or 4 columns depending on the number of responses:
Code: Select all
public class MyMenuPanel : StandardUIMenuPanel
{
public override void ShowResponses(Subtitle subtitle, Response[] responses, Transform target)
{
var rectTransform = GetComponent<RectTransform>();
var gridLayout = GetComponent<GridLayoutGroup>();
int numColumns = (responses.Length <= 2) ? 1 : 2;
gridLayout.constraintCount = numColumns;
gridLayout.cellSize = new Vector2(rectTransform.sizeDelta.x / numColumns, gridLayout.cellSize.y);
base.ShowResponses(subtitle, responses, target);
}
}