Custom Editor creation
stefnotch opened this issue · comments
Issue description:
I have been trying to create a custom editor for an object and ran into an issue.
A NullReferenceException
is being thrown by this method:
Steps to reproduce:
Editor/MyScriptEditor.cs
public class Hi
{
public string test;
}
[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : GenericEditor
{
public override void Initialize(LayoutElementsContainer layout)
{
layout.Label("My Custom Editor", TextAlignment.Center);
var group = layout.Group("Inner group");
try
{
//Edit: As noted below, this should be a ReadOnlyValueContainer or CustomValueContainer
var n = new ValueContainer(typeof(Hi)) { new Hi() };
layout.Object(n); // NullReferenceException
}
catch (Exception e)
{
Debug.LogError(e);
}
base.Initialize(group);
}
}
Minimal reproduction project:
Flax version:
0.4.6181
For future reference, an alternative is using a custom editor manually with proxy object like here
var x = new CustomEditorPresenter(null);
x.Panel.Parent = layout.ContainerControl;
x.Select(new Hi());
You used the wrong values container implementation. For custom values access use ReadOnlyValueContainer
or CustomValueContainer
which gives even more flexibility.