[Suggestion] Direct Partial Classes Support


photo

Recommended Posts

I'm finding partial classes useful in Unigine but they seem a little tricky to work with. It would be nice to have better direct support for them. My primary use case in exposing properties in the editor. I'm building component libraries, and some components are very configurable from the editor. It may be just me lol, but I don't like seeing all of my property declarations with many editor attributes cluttering my behavioral classes in a single file. I've taken to splitting the class into two files - e.g., Controller.cs and ControllerEditor.cs.  Both are "public partial class Controller : Component".

I start by creating a component "Controller" in the Editor and adding my properties and editor attributes as usual. To split them I can't just create a class/file for "ComponentEditor" in Visual Studio. It seems Unigine only shows editor properties when they are in a file with a meta file. To get my meta I create a component "ComponentEditor" in the Editor. I add "partial" in Controller.cs, and rename the class in ControllerEditor.cs to match. C# will complain about duplicate component declarations. I can just delete the component attribute in ComponentController.cs. Now everything works - I have my behaviors in one file and data selected for the editor in another. The there are few problems when doing things like renaming, but generally things work pretty well. I'm guessing the problems have to do with deleting the component line. When I rename, a new meta gets created, but the old one remains. It seems that is the one used, but I haven't looked into this in detail yet.

There are other cases where partials are useful. All of the pieces to work with partial classes are there and working, but things could be easier. One approach might use a more general  strategy by extending the Import capabilities. Maybe an `Import Class` feature. There are few limitations and "tricks required" situations when working with "loose files" that could be addressed under that feature.   

For the Unigine team: I've just started with Unigine and have to say I'm really impressed. My background is large scale C# business applications/frameworks, and engineering (EE). I just retired and I'm starting my second career in gaming. I looked at many game environments before I found Unigine. Coming from the programming and C# side Unigine "just made sense". The fact that you already have C#9/net5 support is amazing! Grats on a great system. Looking forward to seeing what comes next!

 

Link to post

Tessalator

Partial classes are not currently supported inside the C# Component System, but it looks like a good option to have. I've added this feature to the our internal bug tracker with low priority at this moment.

Thanks for the suggestion!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to post