Forum rules - please read before posting.

Advice on menus and scripts interaction.

Hi,
I need to achieve the following:

  1. Click on a hotspot to zoom in a bunch of inventory items (done)
  2. Click on the inventory item to pop up a menu with details like a picture and a description of the item and a button to add it to the inventory (only if required, if not, a feedback message and substract a "penalty" amount to the score).
  3. Once finished picking up only required items, click a button to submit, handle scoring and if there is any missing equipment, substract from score and show feedback. Return to last gamplay and continue (return to last gamplay done).

The main issue is with the detail menu. The idea is to use a Unity UI prefab because it should be reusable between scenes but I don't know how to push the image and the data to it.

Also, the menu buttons let me run an actionlist asset which don't know which group of equipments is being "tested". I may be able to write a custom action that gets the "active group" being tested and handles the submission but how do I know which inventory items to add to the inventory after a successful submission?

As you see, this is more a "design" question. I think I could make a scene menu and tie together the scripts with the UI elements that need to be updated but it would mean I would need to copy and tie together the menu on every scene. What I was thinking is to get the elements by constant id but I don't find any documentation and don't know where to look on how to use it on my own scripts and maybe a custom editor. I did however use it on custom Actions though I don't know if it would work.

Any advice would be greatly appreciated.

Regards,
Peter








Comments

  • Welcome to the community, Peter.

    Have you made use of Inventory properties?  They allow you to assign strings and other value types to inventory items - see Section 5.6 of the Manual for more.  You could also assign a prefab to each item that contains the data you're looking to read.

    Either way, you can then get the API reference to that data by right-clicking the field's label in the Inventory Manager, and then use it in your own script.

    As for pushing data to your UI, you probably want to make use of custom events rather than custom Actions.  The OnMenuElementClick event is called whenver an element is clicked, and gives you information such as the slot that was clicked as well as the mouse state.  More on custom events can be found in this tutorial as well as Section 12.10 of the Manual.

    You can then cast the MenuElement variable into a MenuInventoryBox to get the inventory item that was clicked, i.e.:

    private void ElementClick (AC.Menu _menu, MenuElement _element, int _slot, int _buttonPressed)
    {
        Debug.Log ("Menu: " + _menu.title + ", Element: " + _element + ", Slot: " + _slot + ", MouseState: " + _buttonPressed);

        if (_element.title == "MyCustomInventory")
        {
            MenuInventoryBox menuInventoryBox = (MenuInventoryBox) _element;
            InvItem clickedItem = menuInventoryBox.GetItem (_slot);
        }
    }

  • Hi Chris, thank you for the tips!

    I didn't think about using inventory properties because I didn't know how to assign an image to it. Now I realize I could assign the image to the linked prefab. I just thought it was for the 3d model but it can be anything I guess. The "right-clicking" tip I had forgotten about it, thank you!

    The only thing I seem to be confused is the interaction with the Inventory UI because, well, that is the thing, there isn't any. Or at least not at first. The objects are laid on the scene.

    Thank you for the information though. I will figure something out.
  • Indeed - the linked prefab field is intended for whatever you may need it for, 3D model or otherwise.

    It may be worth sticking to completely AC-based Menus (i.e. no Unity UI) until the functionality is working correctly.  Unity UI adds another layer of complexity, so it's generally advisable to have things all work with AC before making things more complicated like that.
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.