Forum rules - please read before posting.

Left Click to Examine

Hi there,

I'm looking to assign the "Examine" action to the Left Click in the AC Game Editor. As of now, my configuration sets "Left Click" to "Use" and "Right Click" to "Examine item". I explored the "Drag and drop Inventory interface" in the editor, but couldn't find an option to set the Left Click to "Examine Item".

Is a custom script the solution?

I also found a 2018 post (here). While the OP's configuration differs slightly from mine—mine doesn't utilize a 'Monkey Island-like' interaction system—the link they provided (http://pasteall.org/896645/csharp) is unfortunately defunct.

Any guidance would be deeply appreciated. Thanks in advance!

Comments

  • edited August 2023

    There's no link to the post you mention - can you post the link again?

    You can disable the default click behaviour by unchecking Mouse clicks have default functionality? in the Settings Manager.

    You can then swap their behaviours around either by creating inputs named InteractionA and InteractionB, and mapping them to "mouse 1" and "mouse 0" respectively.

    To preserve left-clicking for Menus, you'll need to rely on Unity UI.

    The alternative approach would be to use scripting to swap the left/right clicks only at certain times - e.g. when dealing with Hotspots/Inventory. I can advise further, but I'll need more details about when exactly you'd be looking to swap inputs.

    I explored the "Drag and drop Inventory interface" in the editor, but couldn't find an option to set the Left Click to "Examine Item".

    It's possible to examine an item with a left-click when drag-and-drop mode is enabled - but it depends on your interaction settings. If your interaction method allows for it, the Can drop an Item onto itself to Examine it? option will appear to give you this functionality.

  • Thank you so much for your guidance, Chris!

    I realize I didn't provide some key clarifications, and I apologize for the oversight. When I mentioned "Examine," I was referring exclusively to inventory items. As of now, players can right-click an inventory item to view a larger image, open a book, etc. This mimics the behavior in the Chamber Demo (my game is 2D, by the way). I adapted your code, created a prefab, and integrated it into every scene.

    using UnityEngine;
    using AC;
    
    public class InvenItemCloseUp : MonoBehaviour
    {
        #region Variables
    
        private const string menuName = "InvenItemCloseUp";
        private const string inventoryMenuName = "Inventory";
        private const string nameElement = "ItemName";
        private const string graphicElement = "ItemGraphic";
        private const int examineIconID = 4;  
        [SerializeField] private ItemGraphic[] itemGraphics = new ItemGraphic[0];
    
        #endregion
    
        #region UnityStandards
    
        private void OnEnable()
        {
            EventManager.OnInventoryInteract += OnInventoryInteract;
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
            EventManager.OnMenuTurnOff += OnMenuTurnOff;
        }
    
        private void OnDisable()
        {
            EventManager.OnInventoryInteract -= OnInventoryInteract;
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
            EventManager.OnMenuTurnOff -= OnMenuTurnOff;
        }
    
        #endregion
    
        #region CustomEvents
    
        private void OnInventoryInteract(InvItem invItem, int iconID)
        {
            if (iconID == examineIconID)
            {
                Menu closeUpMenu = PlayerMenus.GetMenuWithName(menuName);
    
                MenuLabel itemNameLabel = closeUpMenu.GetElementWithName(nameElement) as MenuLabel;
                itemNameLabel.label = invItem.GetLabel(Options.GetLanguage());
                itemNameLabel.UpdateLabelText();
    
                Texture2D itemTexture = invItem.tex as Texture2D;  
                foreach (ItemGraphic itemGraphic in itemGraphics)
                {
                    if (itemGraphic.itemID == invItem.id && itemGraphic.graphic != null)
                    {
                        itemTexture = itemGraphic.graphic;  
                        break;
                    }
                }
    
                MenuGraphic menuGraphic = closeUpMenu.GetElementWithName(graphicElement) as MenuGraphic;
                menuGraphic.SetNormalGraphicTexture(itemTexture);
    
                closeUpMenu.TurnOn();
            }
        }
    
    
    
        private void OnMenuTurnOn(Menu menu, bool isInstant)
        {
            if (menu.title == menuName)
            {
                PlayerMenus.GetMenuWithName(inventoryMenuName).ignoreMouseClicks = true;
                KickStarter.playerInput.dragOverrideInput = "DragOverride";
                KickStarter.stateHandler.SetInteractionSystem(false);
            }
        }
    
        private void OnMenuTurnOff(Menu menu, bool isInstant)
        {
            if (menu.title == menuName)
            {
                PlayerMenus.GetMenuWithName(inventoryMenuName).ignoreMouseClicks = false;
                KickStarter.playerInput.dragOverrideInput = string.Empty;
                KickStarter.stateHandler.SetInteractionSystem(true);
            }
        }
    
        #endregion
    
        [System.Serializable]
        private class ItemGraphic
        {
            public int itemID;
            public Texture2D graphic;
        }
    }
    

    Interface & Inventory Settings
    https://imgur.com/ojroorA

    What I'm aiming for now is to allow players to "drag and drop the inventory item (using the left click)" to interact with hotspots and such. Moreover, a "single left click on the inventory item" should open the Examine menu or other menus like diary, objectives, etc., for more detailed information.

    Your advice regarding the "Drag and drop Inventory interface" and the "Can drop an item onto itself to Examine it?" settings worked precisely as I had hoped! The only hiccup is the inability to toggle (left-click to open the Examine Menu and another left-click to close it). How can I achieve this toggle functionality with a single left-click?

    Referring to your mention of an alternative approach:

    You can then swap their behaviours around either by creating inputs named InteractionA and InteractionB, and mapping them to "mouse 1" and "mouse 0" respectively.

    Could you clarify if I need to navigate to [Project Setting] > [Input Manager], then expand the "Axes" and create InteractionA and InteractionB?

    There's no link to the post you mention - can you post the link again?

    Regarding the missing link, my apologies again. Here's the link, in case you're curious:
    https://adventurecreator.org/forum/discussion/7345/examine-an-inventory-item-with-left-click

  • The only hiccup is the inability to toggle (left-click to open the Examine Menu and another left-click to close it). How can I achieve this toggle functionality with a single left-click?

    Specifically, the left-click to close?

    If you have a separate Examine menu, you could make the Menu itself span the full-screen, with (invisible) Buttons on each edge that close the Menu. That way, wherever you click, it'd react.

    Could you clarify if I need to navigate to [Project Setting] > [Input Manager], then expand the "Axes" and create InteractionA and InteractionB?

    Yes, that's what I was getting at - but it may not be necessary given the alternative.

  • Thanks a lot for your help!

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.