Forum rules - please read before posting.

carousel/wrap from first to last menu element when shifting

Is there currently a way to make offset element slot buttons wrap around? So for example if I have three dialog options, 1,2 & 3, shifting to next on 3 takes it to 1?

Comments

  • Are you only displaying one at a time?

    It should just take a simple custom script, but it may need a tweak to AC itself to make it possible. I'll look into it.

  • edited July 2020

    Thanks Chris!

    Edit: Yes, I am displaying just one option at a time; where the triangular brackets are UI buttons it looks like:

    < Ask about X? >

    So in the example above I'd like the left shift to take you to Ask about Z? and the right to Ask about Y?

  • Got it. I'll investigate.

  • This'll take a bit of work behind the scenes to fix an issue before it can be done. The following script will do it, but only once the update is out:

    using UnityEngine;
    using AC;
    
    public class CycleConversation : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnMenuElementClick += OnMenuElementClick; }
    
        private void OnDisable () { EventManager.OnMenuElementClick -= OnMenuElementClick; }
    
        private void OnMenuElementClick (Menu menu, MenuElement menuElement, int slot, int buttonPressed)
        {
            if (menu.title == "Conversation")
            {
                MenuDialogList dialogList = menu.GetElementWithName ("DialogueList") as MenuDialogList;
                int offset = dialogList.GetOffset ();
    
                if (menuElement.title == "ShiftDown")
                {
                    offset ++;
    
                    if (offset >= KickStarter.playerInput.activeConversation.GetNumEnabledOptions ())
                    {
                        offset = 0;
                    }
    
                    dialogList.SetOffset (offset);
                    menu.Recalculate ();
                }
                else if (menuElement.title == "ShiftUp")
                {
                    offset --;
    
                    if (offset < 0)
                    {
                        offset = KickStarter.playerInput.activeConversation.GetNumEnabledOptions () - 1;
                    }
    
                    dialogList.SetOffset (offset);
                    menu.Recalculate();
                }
            }
        }
    
    }
    
  • Great - eyes peeled for the update, thanks as always for your incredible support.

  • Hi Chris - I've added this script to my conversation menu, and I'm having no luck getting it to work - I've tinkered with it a bit, but to no avail.

    The menu I'm using has two buttons, named Left (click type: offset element slot, offset type: Shift Previous) and Right (click type: offset element slot, offset type: Shift Next) and I have a feeling I need to replace these names in the script where it shows "ShiftDown" and "ShiftUp", but my stabs in the dark haven't born fruit, to mix metaphors.

  • Yes, you'd need the names in the script to match with the element names in the Menu Manager.

    But set both their "Click types" to Custom Script - the script handles the click behaviour.

    Try also reverting your Menu's Source to Adventure Creator - Unity UI adds another layer of complexity, so it's best to check things work with AC alone before incorporating it.

  • Click type to custom script was the stumbling block - thanks Chris, this works great with Unity UI.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.