I’m currently working on an AR project for Android and iOS and was looking into dynamically generating style classes and related properties on runtime.
More specifically am looking into an elegant way of calculating device specific data with regards to the safe area on mobile devices. And instead of calculating these values every time I need them, I thought it more elegant to calculate them all at once upon first startup and storing them to their own device specific .uss file. When I later need them on a scene change or orientation change or whatever, I can just assign the generated style class and let the new ui system handle the rest.
I got the IO part working, I’m able to write to and read from .uss files and I store them in the persistent data path. However when I was trying to convert this data into an actual Styleclass as defined by Unity I started running into issues. Since StyleClasses are internal scriptable objects, I can neither inherit from them nor edit them during runtime. I also can use things like Resource.Load, since that counts on those files being in a resource folder, which I can’t access during runtime. I was wondering if anyone else has any helpful thoughts on this. I’m not sure if I’m just trying to over engineer a solution here or whether I’m just running into an edge case the unity-dev team has not accounted for yet.