Adventure Creator Wikia
Advertisement

When using the default Container menu, the Player can transfer items from their own inventory into the Container by first clicking the item, and then the Container element.  This script reduces this down to just the first click, by automatically tranferring any clicked item into the Container element.

To use it, first bring up the default Container menu in the Menu Manager, select the PlayerInventory element, and set its Inventory box type field to Custom Script.

Next, attach the script below to a GameObject in the scene:

AutoTransferToContainer.cs

using UnityEngine;
using System.Collections;
using AC;

public class AutoTransferToContainer : MonoBehaviour
{

    private void OnEnable ()
    {
        EventManager.OnMenuElementClick += OnClickInventory;
    }

    private void OnDisable ()
    {
        EventManager.OnMenuElementClick -= OnClickInventory;
    }

    private void OnClickInventory (Menu menu, MenuElement menuElement, int slot, int buttonPressed)
    {
        if (menu.title == "Container" && menuElement.title == "PlayerInventory")
        {
            MenuInventoryBox inventory = menuElement as MenuInventoryBox;

            InvItem clickedItem = inventory.GetItem (slot);
            if (clickedItem != null)
            {
                if (KickStarter.playerInput.activeContainer.Add (clickedItem.id, clickedItem.count))
                {
                    KickStarter.runtimeInventory.Remove (clickedItem.id, clickedItem.count);
                }
            }
        }
    }

}
Advertisement