Forum rules - please read before posting.

Use inventory item with single click

Hi everyone, I set up the gameplay like this:

1) I click on the hotspot and the inventory menu opens.

2) If the designated object is present in the inventory, I must first click on the object and then again on the hotspot to start Inventory Interaction.

This method does not convince me very much for the gameplay I would like to create, I was wondering if it is possible, after the inventory has opened, to be able to start the Inventory Interaction with a simple click on the object, making AC understand that I am in range.

Note:

AC is set to context sensitive and I would like to always keep it that way.

Thanks a lot.

Comments

  • The act of clicking a Hotspot, then an Inventory item to combine it with, requires Choose Hotspot Then Interaction mode, with an InventoryBox element of type "Hotspot" present in the Interaction menu.

    This way of interacting is used in the 2D Demo. Other icons such as Use, Talk etc can be removed from the Interaction menu if desired.

    Are you looking to achieve this behaviour only for specific Hotspots? Try using Choose Hotspot Then Interaction mode to get the behaviour you describe - don't worry about other Hotspots / Context Sensitive for now.

    It's possible to have individual Hotspots revert back to Context Sensitive mode by checking Single 'Use' Interaction? in their Inspectors, but it's also possible to make use of a custom script that alters the interaction method dynamically.

    See about getting the intended behaviour as above first, though, and then share more details on how you need the rest of the interface to behave, and we'll see about how to mix it in with Context Sensitive mode.

  • I have probably some settings going in contrast each other so what you wrote doesn't work for me.

    I guess if managing everything via script could be easier at this moment, to avoid upsetting the settings(:D).

    In any case these are my settings (Context sensitive):

    https://ibb.co/0rQz8QY
    https://ibb.co/x70VNf3
    https://ibb.co/PW3v6f1
    https://ibb.co/LZZMCHK

    In practise, i'm using close up menus, after close up is open AC switch camera and hotspot detection switch from player vicinity to mouse over via action with parameters.
    The problem switching to hotspot than interaction is that, close up doesn't work anymore if i choose hotspot than interaction, if i chose instead context sensitive and open interaction menu manually, after i'm in close up menu appear a new Use icon over cursor added to the one present on hotspot while cursor is on it and i'm not able to one click use inventory object.

    I'm trying to standardize everything using custom actions or scripting. The gameplay i'm trying to replicate is from The medium.

  • Just an add:

  • To avoid having to change the interaction method, you'll need to make a modification to AC's code. Open up RuntimeInventory.cs, and find the following code block around line 961:

    case AC_InventoryBoxType.HotspotBased:
    {
        if (KickStarter.settingsManager.interactionMethod == AC_InteractionMethod.ChooseHotspotThenInteraction)
        {
            if (InvInstance.IsValid (_menu.TargetInvInstance))
            {
                _menu.TargetInvInstance.Combine (inventoryBox.GetInstance (_slot), true);
                clickConsumed = true;
            }
            else if (_menu.TargetHotspot)
            {
                InvInstance _invInstance = inventoryBox.GetInstance (_slot);
                if (InvInstance.IsValid (_invInstance))
                {
                    _menu.TurnOff ();
                    KickStarter.playerInteraction.UseInventoryOnHotspot (_menu.TargetHotspot, _invInstance);
                    KickStarter.playerCursor.ResetSelectedCursor ();
                    clickConsumed = true;
                }
            }
            else
            {
                ACDebug.LogWarning ("Cannot handle inventory click since there is no active Hotspot.");
            }
        }
        else
        {
            ACDebug.LogWarning ("This type of InventoryBox only works with the Choose Hotspot Then Interaction method of interaction.");
        }
    }
    break;
    

    Replace it with:

    case AC_InventoryBoxType.HotspotBased:
    {
        if (InvInstance.IsValid (_menu.TargetInvInstance))
        {
            _menu.TargetInvInstance.Combine (inventoryBox.GetInstance (_slot), true);
            clickConsumed = true;
        }
        else if (_menu.TargetHotspot)
        {
            InvInstance _invInstance = inventoryBox.GetInstance (_slot);
            if (InvInstance.IsValid (_invInstance))
            {
                _menu.TurnOff ();
                KickStarter.playerInteraction.UseInventoryOnHotspot (_menu.TargetHotspot, _invInstance);
                KickStarter.playerCursor.ResetSelectedCursor ();
                clickConsumed = true;
            }
        }
        else
        {
            ACDebug.LogWarning ("Cannot handle inventory click since there is no active Hotspot.");
        }
    }
    break;
    

    (I will consider making the same change to the official release)

    Next, make the following changes to your Inventory menu:

    • Appear type: During Gameplay
    • Start game locked off?: Checked
    • InventoryBox type: Hotspot Based

    Then, place the following script in your scene, and assign the relevant Hotspot(s) in its Inspector:

    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class CustomInventory : MonoBehaviour
    {
    
        [SerializeField] private List<Hotspot> hotspots = new List<Hotspot>();
        private Menu inventoryMenu;
    
    
        private void OnEnable ()
        {
            EventManager.OnHotspotInteract += OnHotspotInteract;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnHotspotInteract -= OnHotspotInteract;
        }
    
    
        private void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (hotspots.Contains (hotspot))
            {
                if (inventoryMenu == null) inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
    
                HotspotInteractionType interactionType = hotspot.GetButtonInteractionType (button);
                if (interactionType == HotspotInteractionType.Use)
                {
                    inventoryMenu.MatchInteractions (hotspot, true);
                    inventoryMenu.isLocked = false;
                }
                else if (interactionType == HotspotInteractionType.Inventory)
                {
                    inventoryMenu.isLocked = true;
                }
            }
        }
    
    }
    

    Finally, for each of those Hotspots, define a Use interaction but don't assign an ActionList. The above script will handle the click behaviour by unlocking the Inventory menu, and syncing the items with inventory interactions defined by the Hotspot. Clicking an item will then run the Hotspot interaction and lock the menu again.

  • I will consider making the same change to the official release:

    I am pleased to see that I have been useful in stimulating the progress of an already very complete add-on like AC.

    Thank you very much Chris, everything works perfectly, I just don't know how to thank you for all the help you give us. Passion pays off, and you are the example!

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.