I've created a new inventory with Unity UI and I've integrated it into AC.
I do not know if I'm following the right path: I prefer not to have the ShiftLeft and ShiftRight buttons so I've built two inventory, one with the grid on one row and the other on two rows.
I open the inventory through a button and using the ActionList I check the number of carrying items and I show the correct one.
Could this be a right way?
Now, however, I need to check different aspects while the inventory is open, for example, disable the button that opened it (and re-enable it when the inventory is closed), close the inventory with a click out of it, eventually change the items icons on mouse over (I would like to extend the features provided by AC).
With Wintermute I was able to get all this with scripts but Unity is new to me and I have to figure out how to do it.
Where should i put the script that controls all this and how to run it?
In my trials and reading on the forum I experienced the creation of an Empty Object in the scene to which I attached a simple script that reads inventory items number and displays them in the console.
Then I created an ActionList on the button that opens the inventory and it works regularly.
I noticed however that I have to use Object -> Send message with Message to send = Custom and Method name = "my function name" because if I use Object -> Call event I can not set the correct parameters. Why?
Basically, when someone has some time, could tell me in detail what are the steps to run a script that stays active all the time when the inventory is open perhaps with a small example?
I just need to understand how to start, then with the Scripting Guide I should be able to walk alone.
Thanks.
Comments
Menus can be assigned ActionLists than run when turned on and off to help initialise other parts of your game - for example, to turn off other buttons etc. Just be sure to set their When running fields to Run In Background so that they don't interfere with the GameState.
For greater control through script, you can rely on custom events to run code when e.g. mouse-overing elements. Section 12.2 of the Manual, as well as this tutorial, covers their use, while Menu-specific events are listed in Section 11.4. Here's an example of OnMouseOverMenu:
using UnityEngine;
using System.Collections;
using AC;
public class MenuEventTest : MonoBehaviour
{
private void OnEnable ()
{
EventManager.OnMouseOverMenu += ElementOver;
}
private void OnDisable ()
{
EventManager.OnMouseOverMenu -= ElementOver;
}
private void ElementOver (AC.Menu _menu, MenuElement _element, int _slot)
{
if (_element != null)
{
if (_slot > 0)
{
Debug.Log ("Menu: " + _menu.title + ", Element: " + _element.title + ", Slot: " + _slot);
}
else
{
Debug.Log ("Menu: " + _menu.title + ", Element: " + _element.title);
}
}
else
{
Debug.Log ("Menu: " + _menu.title);
}
}
}
Menu inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory1_5");
if(inventoryMenu.IsEnabled()) {
if(!inventoryMenu.IsPointInside(KickStarter.playerInput.GetInvertedMouse())) {
if(Input.GetMouseButtonDown(1)) {
inventoryMenu.TurnOff();
}
else if(Input.GetMouseButtonDown(0)) {
if(KickStarter.runtimeInventory.SelectedItem == null) {
inventoryMenu.TurnOff();
}
}
}
}
}
You can make a private variable to move the Menu inventoryMenu out of the function:
Menu inventoryMenu;
void Start ()
{
Menu inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory1_5");
}
Did you try the event I suggested? It avoids the need for checks every Update.
Is your UI prefab or in-scene? You should find that, when the UI is off, the root Canvas GameObject is disabled - is that the case? I'll look to see if there's an issue, but you could try placing the script on the Canvas instead of a separate GameObject so that it too only runs when the Canvas is enabled.
I'm afraid not much advice can be given for a script error without any context - please post the full code you're using in e.g. pasteall.org
The event can't detect "off clicks", but you can check the mouse enters anything else (including a Menu area with no Elements).
inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory1_5");