Hello, I am currently using the following script in order to use a gamepad with the crafting menu.
`
public class ACCraftingHandler : MonoBehaviour
{
public UnityEngine.InputSystem.PlayerInput playerInput;
public int ingredientLimit = 4;
void OnEnable()
{
EventManager.OnMenuElementClick += OnMenuElementClick;
}
void OnDisable()
{
EventManager.OnMenuElementClick -= OnMenuElementClick;
}
private void OnMenuElementClick(AC.Menu menu, MenuElement element, int slot, int buttonPressed)
{
InputAction submitAction = playerInput.actions["Submit"];
if (menu.title == "Crafting")
{
InvCollection craftingInvCollection = (menu.GetElementWithName("Ingredients") as MenuCrafting).IngredientsInvCollection;
if (element.title == "PlayerItems")
{
int numIngredients = craftingInvCollection.GetCount(false);
if (numIngredients >= ingredientLimit)
{
return;
}
MenuInventoryBox inventoryBox = element as MenuInventoryBox;
InvInstance clickedInstance = inventoryBox.GetInstance(slot);
if (InvInstance.IsValid(clickedInstance))
{
craftingInvCollection.Add(clickedInstance);
//other things I've tried:
//craftingInvCollection.Add(clickedInstance,false);
//craftingInvCollection.AddToEnd(clickedInstance);
menu.Select(inventoryBox,slot);
}
}
else if (element.title == "Create")
{
MenuCrafting crafting = menu.GetElementWithName("Crafting") as MenuCrafting;
if (crafting.ActiveRecipe != null)
{
KickStarter.runtimeInventory.PerformCrafting(craftingInvCollection, crafting.ActiveRecipe, false);
}
}
}
}
}
`
Desired behavior
* When clicking on an inventory item stack, only 1 item is removed from inventory and added into the ingredient slot. If item already exists in ingredients, then add to the stack.
* When clicking on an ingredient slot that has stacked item, only 1 item is removed and placed back in inventory.
What is currently happening:
Sometimes when clicking an inventory item stack, instead of adding 1 item to the ingredient slot, it will add the entire stack. Here is a video:
https://drive.google.com/file/d/1E0O8opVHaY6KD8m_xWoUAScVBmbyb12I/view?usp=sharing
Settings
Unity 2022.3.61f1
AC 1.84.3
For the item that can stack, I’ve tried the different selection modes “single” and “stack” but neither of those yield the consistent desired behavior. The videos show the current setting of “single”. “Items can be re-ordered in Menus?” is also off. Here are my settings:
https://imgur.com/a/CzSdhrQ
How can I achieve the desired behavior?
Thanks!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
It may just be a case of setting the TransferCount value of the clickedInstance variable to 1. This property affects how many of a given item get moved.
The InvCollection class also a dedicated Transfer function.