When the editor shows the Inspector window for a GameObject, it naturally queries the engine for a list of components on the GameObject. For each component type, the engine has registered a bunch of metadata about the data members of the component. This is used to serialize and deserialize the components from json without needing to write any code other than registering the members with the metadata system (one line of code per member), and having some free functions set up that take types (like ints, floats, strings, vector<T>s, Materials, etc) and serialize/deserialize them to json. For complex types like vector<T> and Material, the serialize/deserialize functions end up calling serialize/deserialize on the inner objects, which use the same metadata system, and so on.
So when the editor goes to build the UI for inspecting a component, we ask the engine to serialize each member of the component type to json. We also have a string representing the type of the component member, which is stored in the engine's metadata. So we might get back something like "translation", which is a "vec3", and a fragment of json that looks like "[0.99205, 0.0531423, -0.533324]".
Up until today I simply made a single textbox and pasted the json text directly into it. When you would edit the text, I would parse the json and feed it back through the whole system so that it would set the new data on the object.
Tonight I took advantage of the component type, the "vec3" information above, and stood up a little infrastructure so I can register C# control types with this type string (if there is nothing registered I fall back to the textbox-of-json). The only ones I managed to complete on the flight were handling "float", and "vec3". Float does the easy thing - a textbox with the value in it. For vec3 I do something barely more complicated - a WPF Grid with three textboxes, one for X, Y, and Z.
However this will finally let me get around to writing the gui for editing material properties, which is why I was laying this groundwork. "Material" is one of the types the system recognizes, and there will be a rich gui control for tweaking the material parameters for an object.
Below is a screenshot of the editor showing the improvement. It's not flashy right now, but it's really important. This image reminds me I still need to do something to get the property name column to be the same size.
No comments:
Post a Comment