- Home /
Update custom editor based on choosen options
Hi all,
I'm stuck on getting a custom editor set up. My goal is to have a selection of properties (of components) editable at runtime by means of the UI elements. The runtime UI should be generated by a separate game object present in the scene. To achieve this I try the following:
Candidate properties are tagged by an attribute (in the code)
The game object with those properties is dragged into a field in the inspector for the game object that should generate the run time UI
That runtime UI generator has a custom editor that retrieves a list of components present on the item to configure
The editor shows a popup to allow selection of a single component of that list
Once a component is selected, I want to have check boxes (toggles) to select the tagged properties to configure
Runtime it should then display, for instance, a UI.Slider (values based on another custom attribute) which sets the value of the connected property.
The first four steps work OK, but I cannot figure out the following:
get the custom editor to display toggles for the properties of the selected component (see code below)
I think I should be able to store PropertyInfo's with a bool in a dictionary or something (Haven't gotten to that point yet) to store the selection made on the toggles.
Does anyone have any ideas, esp. on issue 1?
Thanks in advance, Manno
// works as expected
bool test = EditorGUILayout.Toggle("test", true, null);
// appears OK
_choiceIndex = EditorGUILayout.Popup("Components", someClass.ComponentIndex, componentNames);
// runs as expected
if(_choiceIndex != someClass.ComponentIndex) {
Debug.Log(string.Format("Now selected: {0}", behaviours[_choiceIndex]));
PropertyInfo[] pi = behaviours[_choiceIndex].GetProperties();
foreach (var item in pi)
{
if(item.GetCustomAttributes(typeof(PeekableProperty), false).Length != 0)
{
// both run OK
Debug.Log("- property name: " + item.Name);
item.SetValue(behaviours[_choiceIndex], 2, null);
// does not appear...
bool fieldSelected = EditorGUILayout.Toggle(item.Name, true, null);
}
}
someClass.ComponentIndex = _choiceIndex;
EditorUtility.SetDirty(target);
}