Download Alpha Raycaster FREE Unity.
Alpha Raycaster is a custom raycaster for UI texture-based elements built upon default Graphic Raycaster. It checks texture transparency, before deciding whether to send input events for targeted object, which allows a precise interaction with objects that have a non-rect shapes (like circles, triangles, map regions, text, etc).
WEBGL DEMO • DOCUMENTATION • SUPPORT FORUM
• Make buttons and any other interactable UI objects of any shape
• Compatible with both mouse and touch input
• Handles any sprite transformations
• Supports all the sprite modes (including filled, tiled, sliced) and sprite atlases
• Works with orthographic and perspective camera modes
• Demo scene with examples included
Be aware, that the plugin only works with Image, RawImage and Text UnityEngine.UI (uGUI) components.
The default raycaster in Unity 4.6 GUI (Graphic Raycaster) uses just the canvas bounds to check for ray hits. That’s fine while the targets element texture is of a rectangular shape and mostly opaque. However, as soon as you want to make, say, a circle button, you will have a trouble: it will react to user input (like pointer hovering and clicks) even in transparent areas, which is obviously wrong.
Using Alpha Raycaster, you will be able to solve such problems with ease: custom raycaster component will check if alpha value of the target texture in a specific place is below certain threshold and will act accordingly, resulting in fine-tuned input handling.
Import the package from the asset store. The “AlphaRaycaster” directory will appear in the Assets folder of your project. You are free to move that folder to any place in the Assets hierarchy.
After that, there are two ways to setup the plugin:
Selective Mode: in case you want to alpha test specific UI objects, add an Alpha Check component to each;
Raycaster Mode: in case you want to alpha test all the UI objects inside a canvas (root of UI hierarchy), add an Alpha Raycaster component to that canvas. Be aware though, that this setup has more performance cost.
To perform alpha testing, target texture has to be readable. Alpha Check component will check for this and offer to automatically configure the texture, if needed.