I’m trying to come up with a configurable and fool proof way to ensure that a specialized drag-item cursor can be rendered onto the screen at all times in all locations. To do this it seems I’d want to have some kind of VisualElement that is stretched to fill the whole screen and then make the cursor icon a child of that.
Now it is easy enough to create a dummy UIDocument asset, add a UIDocument component to a GameObject in the scene, and then pass that info to the cursor (or vice versa) so that it can be parented. But, since I’m working on a tool that for use by others I’d rather not force them to go through all that boilerplate. It would be better I think to just do all of that dynamically at runtime.That is to say, create the VisualTreeAsset at runtime, add the root visual element to it. Parent the cursor to that root visal element.
But it seems that creating a VisualTreeAsset from scratch is actually a rather complicated matter. I’ve been looking through the source code here on the github repo to get an idea of how the UIDocument monobehaviour does it but it also doesn’t show how the root VisualElements actually get registered for rendering. It seems like they are added to some kind of list but I have now idea where that information allows the UIToolkit to actually begin drawing the element.
Does anyone have some insight on how this could be accomplished dynamically without the use of linking assets and/or using the UIDocument monobehaviour?