Forum rules - please read before posting.

Highlight inventory item inside menu's inventoryBox

edited June 2017 in Technical Q&A
Hello to all!

I'm trying a little "animation" in which, whenever an item is picked up, the menu pops open, and the item appears in the menu, it highlights, and then the menu closes.

It all works flawlesly except the hightlight. 

Before delving into details, I'm using AC version 1.57 and Unity version 5.5.1f1 Personal 64bits.

My Inventory menu is an AC menu, and the items are displayed using a InventoryBox. every inventory item has both a main and an active graphic (the active graphic being a PNG with a modified saturation on photoshop)

My ActionList follows the following steps: It opens the menu (Menu: Change State), adds the item (Inventory: Add or Remove), makes the object invisible so that it doesn't show on the stage anymore (Object: Visibility), disables the hotspot (Hotspot: Enable or Disable), and finally, closes the menu (Menu: Change State).

I'm calling the hightlight right after making the object invisible on the stage. The item appears alright in the menu, but it never highlights.

I'm calling Object: Highlight: Enable (inventory item), making it pulse continously, then Engine: Wait for a few seconds, and then disabling the highlight. (I have also tried just making it pulse without calling enable first, but it did not work).

What could I be doing wrong?

Thanks in advance!

Comments

  • All sounds fine to me - and doing the same thing with the Demo managers causes it all to work for me.

    Try it with the Demo managers so we can see if it's an issue with your own.  Just assign the Managers and create a new scene with a simple OnStart Cutscene that adds the "Prop sword" item and highlights it.  Set the Cutscene's When running field to Run In Background so that you can access the Menu while it runs, and see if it works then.
  • I think I found the issue (kinda). I erased the reference to the main graphic in the inventory manager, and only left it with an active graphic. Then I went and added the item ingame, and it pulsed allright (between the active and nothing).

    I think the issue is that it is pulsing, but the highlight texture may be behind the main texture (they are the same texture, but one has higher luminosity values so as to fake it shining). 


    -------------------------------------------------


    Yes, that was the issue. I now placed as highlight a colored square and it worked alright. I had thought that, when pulsing, the two textures would switch from one another, that is why I had done the hightlight as an exact replica of the item texture.


    Thanks for the help!
  • Sorry don´t help for me, the difference i had with this is i use unity ui menu.
  • Highlighting inventory items does not currently work with Unity UI, you'll have to animate it with a custom script instead.  I shall add a function to the API that returns the UI Button instance of a given inventory item in the next release - that'll make it much easier to do so.
  • edited December 2017
    Has the function been added to get an Inventory Item's Unity UI element, preferably the RectTransform? I can't seem to find a way to return the RectTransform (or Image component) of an InvItem.

    For example, given Event OnInventorySelect(InvItem item), say I want to find out what UI Button is associated with the that item.

    The best I was able to do, is I found a GetRectTransform () in UISlot.cs, which will return the RectTransform of a UI Button.

    However, I'm having trouble linking my InvItem to a UISlot. So I edited InvItem.cs and added a:
    public RectTransform uiRectTransform;

    Now I can associate a RectTransform with my InvItem. The next part was to assign this automatically when a Inventory Item UI is updated. I found the best place for this was MenuInventoryBox.cs around line 505 where:
    tex = GetTexture (items [_slot+offset], isActive);

    I know my InvItem has a texture, so after this line I added the following code:
    RectTransform uiRectTransform;
    uiRectTransform = uiSlots[_slot].GetRectTransform();
    if (uiRectTransform != null) {
        items[_slot + offset].uiRectTransform = uiRectTransform;
    }

    So if the UI Image is getting updated, then it also assigns the matching RectTransform to the InvItem class. This way, I can always find the attached UI Element for an Inventory Item, regardless of where it happens to be placed.

    Now I can get the UI element by calling:
    KickStarter.runtimeInventory.SelectedItem.uiRectTransform

    Is there a better way to achieve this?
  • edited December 2017
    Is there a better way to achieve this?

    Yes - you can get the item's slot directly from the MenuInventoryBox element:

    MenuInventoryBox inventoryBox = AC.PlayerMenus.GetElementWithName ("MyInventoryMenu", "MyInventoryBox") as MenuInventoryBox;
    int slot = inventoryBox.GetItemSlot (KickStarter.runtimeInventory.SelectedItem.id);
    UISlot selectedSlot = inventoryBox.uiSlots [slot];
    RectTransform rectTransform = selectedSlot.GetRectTransform ();

  • Thank you, I wrapped that up in a function and now don't need to modify your scripts. Much cleaner!
  • Hey @Selzier can you help me with that function? I just don´t get something like that working.
    thanks
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.