Forum rules - please read before posting.

Offset the Icon when Drag Inventory (Mobile Unity UI)

Hi!,I would like the icon have an offset on Y so the user finger does not cover it when doing an item drag from the Inventory.
How could I configure that? Thanks in advance!

Comments

  • Assign the same icon in the item's Cursor (optional) property in the Inventory Manager. When this field is filled, you'll then get a new Click offset (from centre) field. If you set a positive Y value, the icon will be shifted upwards by that amount.

  • edited February 2023

    I recently had the same query and although this is a feasible solution it doesn't scale particularly well given the number of inventory items one is likely to have in their game. I've made the following minor additions to the AC source code (v 1.76.3) to ease the process and I wondered whether you'd consider incorporating them in to AC, Chris? Thanks.

    CursorManager.cs
    79:

    public Vector2 inventoryCursorOffset = Vector2.zero;
    

    265-271:

    if (cursorRendering != CursorRendering.UnityUI)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Click offset (from " + ((cursorRendering == CursorRendering.Software) ? "centre):" : "top left):"), GUILayout.Width(150f));
        inventoryCursorOffset = CustomGUILayout.Vector2Field(string.Empty, inventoryCursorOffset, "AC.KickStarter.cursorManager.inventoryCursorOffset");
        EditorGUILayout.EndHorizontal();
    }
    

    InvItem.cs
    63:

    public bool useInventoryCursorSettings;
    

    358:

    useInventoryCursorSettings = CustomGUILayout.ToggleLeft("Use cursor settings?", useInventoryCursorSettings);
    

    378:

    cursorIcon.ShowGUI (..., useInventoryCursorSettings ? tex : null);
    

    CursorIcon.cs
    810:

    public void ShowGUI (..., Texture mainGraphic = null)
    

    817-830:

    if (mainGraphic != null)
    {
        texture = mainGraphic;
        if (cursorRendering == CursorRendering.Software)
        {
            size = KickStarter.cursorManager.inventoryCursorSize;
        }
        if (cursorRendering != CursorRendering.UnityUI)
        {
            clickOffset = KickStarter.cursorManager.inventoryCursorOffset;
        }
    }
    
    if (texture == null) return;
    

  • Is the underlying intent here to provide a global click offset to all items, that can then be optionally overridden on a per-item basis? I can certainly consider that.

    I would also mention, however, that the use of Unity UI for cursor rendering should be able to provide this - since the position of the RawImage's RectTransform (which displays the cursor) could be offset through animation when an item is selected.

  • Is the underlying intent here to provide a global click offset to all items, that can then be optionally overridden on a per-item basis? I can certainly consider that.

    Hi, yes, that's exactly it. If you could it'd be great, thanks. I thought this approach would be the cleanest as it adds functionality without changing anything existing.

  • Understood - though editing CursorIcon in that way isn't possible as it's used more widely than just for inventory.

    Though it's a little different to the above, the most robust approach would be to provide a default offset that gets overridden if a separate Cursor texture is assigned for a given Inventory item. I'll see about implementing this in the next release - thanks for the suggestion.

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.