Page 1 of 1

Scroll down responses using keys

Posted: Thu Dec 17, 2015 3:05 pm
by nishant
Hi,
I have a custom dialogue UI to handle with auto focus of responses and it works great . Only issue that I need to address is that incase a response option is below the canvas and user needs to scroll down to access that option, navigating options using keys wont select that option. Well it seems I can only select an option if its visible. Maybe someway to scroll down and select the bottom most option ??

Code: Select all

public class CustomUIDialogueUI : UnityUIDialogueUI {

	[SerializeField]
	List<string> conversationWithDisabledResponses = new List<string> ();

    [SerializeField]
    Canvas RootCanvas = null;

	public override void Awake ()
	{
		base.Awake ();

		if (VRSettings.enabled)
		{
			transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
		}
    }

    public override void Update()
    {
        base.Update();

        //Ugly hack by Trevor to make sure the camera is always mapped
        if(RootCanvas != null && RootCanvas.worldCamera == null)
        {
            PlayerController PC = World.Get().GetGameMode().GetPlayer();
            if(PC != null && PC.GetCameraManager() != null && PC.GetCameraManager().GetCameraComponent() != null)
            {
                RootCanvas.worldCamera = PC.GetCameraManager().GetCameraComponent();
            }
        }
    }

    #region Response
    public override void ShowResponses (Subtitle subtitle, Response[] responses, float timeout)
	{
		base.ShowResponses(subtitle, responses, timeout);
		

		// Then disable the buttons for already-clicked responses:
		foreach (var buttonObject in dialogue.responseMenu.instantiatedButtons) {
			var responseButton = buttonObject.GetComponent<UnityUIResponseButton>();
			var entry = responseButton.response.destinationEntry;

			//Only work for this conversation
			if(conversationWithDisabledResponses.Contains(DialogueManager.LastConversationStarted))
			{
				var alreadyClicked = Lua.IsTrue("Dialog[" + entry.id + "].SimStatus == 'WasDisplayed'");
				
				responseButton.button.interactable = !alreadyClicked;
			}

		}

        if (responses.Length > 0)
            SetButtonsNav();

    }

    public override void HideResponses()
    {
        dialogue.responseMenu.DestroyInstantiatedButtons();
        base.HideResponses();
    }

    void SetButtonsNav()
    {
        List<GameObject> buttons = dialogue.responseMenu.instantiatedButtons;
        int totals = buttons.Count;
        for (int i = 0; i < totals; i++)
        {
            Navigation n = new Navigation();
            n.mode = Navigation.Mode.Explicit;
            n.selectOnUp = (i == 0) ? buttons[totals - 1].GetComponent<Button>() : buttons[i - 1].GetComponent<Button>();
            n.selectOnDown = (i == totals - 1) ? buttons[0].GetComponent<Button>() : buttons[i + 1].GetComponent<Button>();
            buttons[i].GetComponent<Button>().navigation = n;
        }
        StartCoroutine(SetSelectedGameObject(buttons[0]));
    }

    IEnumerator SetSelectedGameObject(GameObject o)
    {
        //we need to wait to the next cicle :( otherwise we go into the same 
        //update how call the response and get the effect of autoselect.
        yield return null;
        UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(o);
    }
    #endregion

}
Am also attaching a reference of the custom class that am using to handle responses

Thanks.
Nishant

Re: Scroll down responses using keys

Posted: Fri Dec 18, 2015 7:55 am
by Tony Li
Hi Nishant,

Another Dialogue System user wrote a script do this. You can get it here.