Forum rules - please read before posting.

Interactions menu shown, highlight not initially selected if mouse already hovering?

Repost:
Here's a slight UI issue with an interactions menu that is shown when a hotspot is clicked: https://gfycat.com/LongInfamousAsianporcupine
If the cursor is already overlapping, in this case the "mouth" button, the sprite swap isn't highlighted and requires the button to be re-hovered to chose the sprite swap highlight. This is a UnityUI issue, but since the highlight script is wired into AC (and I'm not sure how to work with that!) I was wondering if it could be sorted with OnPointerEnter?

public class CursorPreHoveringOverButton : MonoBehaviour, IPointerEnterHandler    {        public void OnPointerEnter(PointerEventData eventData)        {            Debug.Log("Hello");        }    }

If that's placed on the interactions UI, it prints Hello in debug. Could that method be tapped into to force an initial check for a hover over anything?

public class CursorPreHoveringOverButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    [SerializeField] private Image mouthOpen, mouthClose;

    public void OnPointerEnter(PointerEventData eventData)
    {
        GetComponent<Button>().image = mouthOpen;
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        GetComponent<Button>().image = mouthOpen;
    }
}

A slightly more convoluted version that requires each button to be defined, but the idea is similar. I'm not great with UI coding, so this is more just for suggestions in case anything could be integrated to force a menu update when it's loaded?

Comments

  • The PlayerMenus script includes a method to force-select a given UI GameObject:

    AC.KickStarter.playerMenus.SelectUIElement (gameObject);

    Whether that works or not is down to Unity, but it's worth a try.
  • edited August 2018
    Is that for select or highlight? It's just a hover issue, since if you release-click it still interacts , it just isn't highlighting the button if the menu appears whilst the cursor is already positioned over the same point as the button is.

    Also, whereabouts in the AC code is the highlight buttons taken care of? I'm trying to see if something can be initiated when the menu is turnedOn to trigger a cursor test for hovering to force a highlight if so.
  • It's for selecting it so far as Unity's EventSystem is aware - which should be highlighting.

    When using a Unity UI-based menu, the highlighting is handled completely within Unity UI - it's not covered by AC.
  • Yeah, I thought it was, I was asking around about detecting hovers for UnityUI's that are called up in front of the cursor, and someone mentioned looking in the code for the where highlighting is handled. I'll see if I can use that function in some way to make it aware... wish me luck! :p
  • Could this go into Awake/Start when on a script on the UI? I want to give it a shot, but I'm not 100% certain what to put in (gameobject), should that be the button or the root interactions menu? (In which case, would it need further tricks to differentiate between which button is hovered?)
  • It could go in OnEnable, but you could also hook into the OnMenuTurnOn custom event.
  • Ahh okay, and what is the gameobject reference, I couldn't put the interactions UI prefab in it, and I wasn't sure which object should go in there (since there's 5 interaction buttons off the main UI part)
  • I was assuming it would be the same GameObject it's attached to, and being called from OnPointerEnter - not Awake or anything else.  Otherwise, you'd have to check if the mouse pointer is within its boundary.
  • Yeah, it's only for fixing that issue in the video I posted, nothing else appears under a cursor that needs an immediate visual response. I'll have a play and see what I can do, shame Unity doesn't have a way of taking care of this itself.
  • Besides a slight amount of latency, this seems work, thanks @ChrisIceBox !

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.EventSystems;
    using UnityEngine.UI;

    public class CursorPreHoveringOverButtonTwo : MonoBehaviour, IPointerEnterHandler
    {

        public void OnPointerEnter(PointerEventData eventData)
        {
            AC.KickStarter.playerMenus.SelectUIElement(gameObject);
        }
    }

    Wonder why it doesn't highlight immediately, but rather a couple of nano-seconds late?
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.