I found myself using the GraphView experimental package for building some custom 2d map editor. It works as expected, but needs some workarounds to get GraphView and GridBackground to do what I need, so I am pretty much bending GraphView’s functionality in order to take a minimum of its features for my needs.
Therefore, I was wondering how to best grab the relevant parts and just build my own classes, so I can later also build a standalone without UnityEditor dependencies.
However I can’t seem to make out the relevant parts or understand the core elements I need for porting to my own clases. I tried some dirty/paste work or removing some parts for testing, but every approach just broke the rendering.
I am using the zoom function and added a “reflection jailbreak” for the GridBackground members so I can set the grid resolution dynamically. The editor view is attached to a custom class derived from GraphView drawn via ImmediateModeElement and GL instructions. Anything I don’t need (like the context menu) I “killed” in my class derived from GraphView. I haven’t even figured out, where the map is rendered on. Removing GridBackground removes the drawn map.
Some time ago i wanted my own GridBackground and i re-created it using the “generateVisualContent” callback, maybe this is usefull for you
(CustomStylePropertyDefault<> is a custom struct, you can replace it with CustomStyleProperty<>)
Im driving the style properties through a Uss attached to the GraphView, but you could replace them with csharp properties
So you switch from GL to painter2D. Did you perform any profiling on performance?
From what I’ve understood, my GL routines only draw because there’s a valid target already provided by GridBackground. I dug into it and it appears the internal call HandleUtility.ApplyWireMaterial() is where the juice is. I continued stepping into the code and found that it does apply some texture and some sampler of the scene editor:
Yes i traveled that very same path, but i didnt arrive at a solution that i liked. Had to use too much hacked reflection methods so i just decided to try Painter2D. I have not profiled it, but it should be much lighter than the default GridBackground, though it does not handle rotations