Unity-UI-Extensions / com.unity.uiextensions

https://unity-ui-extensions.github.io/
1.26k stars 135 forks source link

UILineRenderer events / eventsystem #147

Open SimonDarksideJ opened 2 years ago

SimonDarksideJ commented 2 years ago

Issue created by Martijn Dekker as Bitbucket Issue #​147 on 2017.06.07 11:20. Hi,

I would like to know of it's able to receive pointer events on the UILineRenderer. From what i can see is that this is not working atm,, ?

SimonDarksideJ commented 2 years ago

On 2017.06.10 13:12, @SimonDarksideJ commented: No that is currently not supported, however, I'll look in to it for the next update.

Probably look to doing something at the base primitive level so it works for all primitives. All it needs is a picker mask or ray cast text to the vertex array.

SimonDarksideJ commented 2 years ago

On 2017.06.12 08:21, Martijn Dekker commented: Hi Simon, i would like to contribute but i'm having a hard time figuring out why it is not working atm. Ik looks like a raycast is picked up at 0,0. my guess would be that the raycast mesh should be updated.. ??

Can you give a little explanation on this ?

SimonDarksideJ commented 2 years ago

On 2017.06.12 09:01, @SimonDarksideJ commented: :D Welcome to the project and thanks for the help.

Unity changed how the UI System handles raycasts and the event system, back in 5.3 I think. It now uses an interface called ICanvasRaycastFilter. You can see this in action in the IMAGE class in the Unity UI Source here: https://bitbucket.org/Unity-Technologies/ui/src/0155c39e05ca5d7dcc97d9974256ef83bc122586/UnityEngine.UI/UI/Core/Image.cs?at=5.2&fileviewer=file-view-default

Just check the IsRaycastLocationValid method, which determines if the mouse is over a valid location in the RectTransform.

I've implemented this same interface in the UIPrimitiveBase class, so that all Primitive controls retain the same behaviour: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/src/9ce211c5fc62033ae567f29bba101a2e78d95616/Scripts/Primitives/UIPrimitiveBase.cs?at=master&fileviewer=file-view-default

What needs to be updated is to change it from an Image / Alpha based lookup, to a vertex lookup. Or see if we can tweak the current alpha lookup to recognise only the drawn lines (which might be easier)

At the moment, I commented out the graphic lookup (only returns true if mouse is within the RT) only as a fallback.

If you need anything else, let me know. Just checking in some improvements to those classes from this weekend, so be sure to do a fresh pull. (going to have a look at the line antialiasing next)

SimonDarksideJ commented 2 years ago

On 2017.06.21 22:27, @SimonDarksideJ commented: OK, I admit defeat for now, been over and back over this far too many times now and currently it doesn't seem possible. Problem is the mesh behind the UI element when drawn through the UI system is stored without relative position, meaning the mesh is actually stored in worldspace from the origin. When it is rendered, it is then transformed to screenspace through the UI renderer. However, never the twain shall meet. SO there is no way to get the rendered coordinates for the mesh to test a mouse click against.

To make this work properly would take more time than I have currently. Here are my thoughts for anyone wanting to pick this up:

In just 3D this is fairly easy, with the UI system in the middle, it'll take a lot more thought.

may revisit in the future.

SimonDarksideJ commented 2 years ago

On 2017.06.23 13:52, Martijn Dekker commented: Ahh, just the very same problem i'm facing. i have tried allot but have not found an fix. currently the only fix would we to create allot of child objects to each segment that receive events .

Thanks for looking into it tho!

Regards, Martijn

SimonDarksideJ commented 2 years ago

On 2017.06.23 15:10, @SimonDarksideJ commented: I even tried that :D (like minds) it still wouldn't help as you need to evaluate between the points. I also tried experimenting by attaching an edgecollider with the Line Renderer (same way I do with the unity 3D Line Renderer component) with no joy. After this update is done, I'll have another go, thanks for also trying, maybe we'll meet in the middle with a possible solution.