Forum rules - please read before posting.

One click/touch Inventory ?

edited March 2021 in Technical Q&A

Hello there
I have made a mini game, a quiz, where an object gets teleportet to a marker and a inventory pops up with one of the
items matching the object. Instead of dragging the object onto the hotspot - can I use the inventory as a "button" instead?
I'm using a random int to randomly choose between a serious of objects that will be spawned to the marker for each quiz and their respective inventory items (using add ) will be added to the inventory and the inventory will show up as something your answer from.

On a side note - as seen in many apps, on the main menu there is a button with a link to some other apps from the same developer - how is it possible to link externally to ie, the app store?

Any direction would be much appreciated.

Comments

  • Forgot to add: is there a way to "reset" the inventory, instead of removing each with the "remove" ? when items have been added and I test with play - these are being remembered and the new ones will be added behind those already there.
    Or do I need to add each item first and then when the turn is over remove each of the same items to get a clear inventory?

  • Instead of dragging the object onto the hotspot - can I use the inventory as a "button" instead?

    I may be misunderstanding your intent here, but it seems like a Conversation may be a better fit here.

    A Conversation's options can be presented as icons, and can also be linked to inventory items, so that a given option will only show if a specific item is held by the Player. That would give you a one-click interface.

    Otherwise, you'd probably have to look into custom scripting, to override the click behaviour of the inventory under certain conditions. Something like:

    using UnityEngine;
    using AC;
    
    public class QuizItem : MonoBehaviour
    {
    
        public Hotspot quizHotspot;
    
        private void OnEnable () { EventManager.OnMenuElementClick += ElementClick; }
        private void OnDisable () { EventManager.OnMenuElementClick -= ElementClick; }
    
        private void ElementClick (AC.Menu _menu, MenuElement _element, int _slot, int _buttonPressed)
        {
            MenuInventoryBox inventoryBox = _element as MenuInventoryBox;
            if (inventoryBox)
            {
                InvInstance clickedInstance = inventoryBox.GetInstance (_slot);
                if (InvInstance.IsValid (clickedInstance))
                {
                    if (quizHotspot)
                    {
                        quizHotspot.RunInventoryInteraction (clickedInstance);
                    }
                }
            }
        }
    
    }
    

    Where you'd have to set "quizHotspot" to the teleported object at the time it is shown.

    how is it possible to link externally to ie, the app store?

    AC wouldn't be involved here, but you can use Unity's Application.OpenURL command to open external links.

    A custom script with a public function that opens the URL could be triggered by AC via the Object: Send message or Object: Call event Action.

    is there a way to "reset" the inventory, instead of removing each with the "remove" ?

    Through scripting, you can do so with:

    AC.KickStarter.runtimeInventory.RemoveAll ();
    

    As with the above, this can be triggered via an AC ActionList when placed in a public function.

  • Ahh, ofcourse. Using conversation makes so much sense for a one-click solution.
    It now spawn the object and a conversation menu with answers(presented as icons appears).
    I'm trying to figure out:
    1. You mention dialogue can be linked to inventory items - right now I just have the icon for the dialogue - can I use the ones from the inventory so I don't need to also add in the dialogue?
    2. When the dialogue menu appears, I have set it to "run in background", but the UI on the screen disappears - can it remain on the screen?
    The menu also disappears during the time the "reply" is being giving and then the menu appears again (ie if wrong answer is chosen). Can it be visible during the reply also?
    3. I will need a new conversation actions for each quiz question? (could result in 100s)

    Thank you much for the help - always much more than I hoped for!
    Having so much fun with this asset!
    Best, Dan

  • right now I just have the icon for the dialogue - can I use the ones from the inventory so I don't need to also add in the dialogue?

    No, but that's a great suggestion - I'll look into having this be automatic in the next release.

    In the meantime, attaching the following script to your Conversation ought to do it:

    using UnityEngine;
    using AC;
    
    public class AutoSetItemOptionTextures : MonoBehaviour
    {
    
        void Start ()
        {
            Conversation conversation = GetComponent <Conversation>();
            foreach (ButtonDialog option in conversation.options)
            {
                if (option.cursorIcon.texture == null && option.linkToInventory)
                {
                    InvItem item = KickStarter.inventoryManager.GetItem (option.linkedInventoryID);
                    if (item != null)
                    {
                        option.cursorIcon.ReplaceTexture (item.tex);
                    }
                }
            }
        }
    
    }
    

    When the dialogue menu appears, I have set it to "run in background", but the UI on the screen disappears - can it remain on the screen?

    It depends on your Menu's Appear type. When set to During Conversation, it'll only display during the time that the Player can actually choose an option.

    You can set it to something else, e.g. Manual, but you'll also have to use a custom script to manually attach the Conversation to the menu. Something like this (replacing the names of your menu / element):

    using UnityEngine;
    using AC;
    
    public class ManualConversation : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStartConversation += OnStartConversation; }
        private void OnDisable () { EventManager.OnStartConversation -= OnStartConversation; }
    
        private void OnStartConversation (Conversation conversation)
        {
            (PlayerMenus.GetElementWithName ("Conversation", "DialogList") as MenuDialogList).OverrideConversation = conversation;
            PlayerMenus.GetMenuWithName ("Conversation").TurnOn ();
        }
    
    }
    

    I will need a new conversation actions for each quiz question?

    You can use a "GameObject" parameter to override the Conversation referenced in a Dialogue: Start conversation Action, which can help you re-purpose your ActionList for different Conversations.

    A tutorial on ActionList parameters can be found here.

  • Thank you so much Chris! Much much appreciated.
    Best, Dan

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.