Search Unity

Showing UI on hover

Discussion in 'UGUI & TextMesh Pro' started by NoiseFloorDev, Aug 30, 2017.

  1. NoiseFloorDev

    NoiseFloorDev

    Joined:
    May 13, 2017
    Posts:
    104
    I want to scale a canvas UI when the user hovers the mouse near it. It's a basic UI effect, but how do I do this with a canvas?

    I'd expect to just put a transparent UI element over the part of the screen that triggers the UI elements in that area to be shown, and use enter/exit events on that to animate the UI. But, then that UI element either blocks the other elements (if it's in front), or it gets covered up by the other elements (if it's underneath). I don't see how to make a canvas element active, but still pass events through to things underneath it.

    CanvasGroup doesn't seem to help: turning off "Blocks Raycasts" sounds like the right thing, but that doesn't just make it not block raycasts, it makes it not receive them either, so it's basically the same as disabling it.

    I tried making a VisualElement subclass to override HandleEvent (though hopefully you don't actually need to use "experimental" APIs for something this simple), but I don't see any way to attach it to the object, since VisualElement is a Component and not a MonoBehavior. I don't know how to make a Component subclass usable in the editor (it allows adding the builtin ones like Button, but not your own).

    I'm also trying to put a custom shaded element in the canvas that reacts to clicks over opaque pixels. That seems like its own big chain of problems: it looks like I'd have to reimplement GraphicsRaycaster entirely to even get access to UVs, since RaycastHit's UV info doesn't get passed along anywhere; RaycastResult is a sealed struct, so I can't subclass it to have somewhere to put the data (C#: Struct Considered Harmful); and RaycastResult then isn't passed along to HandleEvent to be able to use it.

    Banging my head on too many problems, so I'll probably look for a solution other than Canvas for my UI (it just doesn't seem to be ready yet), but any pointers welcome.