SunBurn 2.0.11 was just released and now the new editor features are available. A more complex feature is custom type support for the editor. This blog covers how to get your custom types or components to show up in-editor and how to control how they are displayed.
Getting Started
To get a custom type into the editor, it should first have a default constructor and derive from SceneEntity/SceneObject or implement IEditorCreatedObject<SceneEntity>. Secondly, the class must have the EditorCreatedObject attribute applied to it, which tells the editor that the object can be created. Lastly, you must add the Serializable attribute and override GetObjectData/SetObjectData to serialize your type's properties when the editor saves/loads objects.
Types inheriting from SceneEntity do not have models and are not rendered (except for the editor gizmo), so they should be used for markers, waypoints, etc. Types inheriting from SceneObject do have models/meshes and will render if assigned one. The editor will automatically recognize this (and other types implementing the interface IEditorCreatedModelObject) and prompt the user to select a model when added to the scene.
To get a component into the editor, derive from BaseComponentAutoSerialization or BaseComponentManualSerialization and have a default constructor. Then add the Serializable attribute to the class and use SerializeMember attributes on the properties you want saved (AutoSerialization) or override GetObjectData/SetObjectData to serialize your component’s properties (ManualSerialization). An example of an AutoSerialization component can be found in the HDR example.
Controlling Properties
By default, any public properties for the type will be displayed in the editor but this can be controlled through the EditorProperty attribute. This attribute controls if a property is visible, its position in the editor's properties panel and the text description/tooltip
[EditorProperty(true, Description="Description Text", ToolTipText="Hover-Over ToolTip", MajorGrouping=3, MinorGrouping=2, HorizontalAlignment=true)]
Description sets the text that is displayed next to the control. MajorGrouping, MinorGrouping and HorizontalAlignment define the position and orientation of the property’s control. MajorGroups are for organizing related properties and all properties with the same MajorGroup number will go into the same divider panel. The MinorGrouping determines the order of properties within each MajorGroup. With these two options you can control the layout of your properties.
The last option, HorizontalAlignment, determines the position of the description text for a property control, either appearing next to the control (horizontal) or above the control (vertical).
Advanced Options
You can have more advanced options for specific controls through ControlOptions attributes. For example, you can use the EditorNumberPadOptions attribute to define how the numberpad control will behave for floats and integers. Supported control options and their properties are:
- EditorNumberPadOptions: sets decimal places to display, min value, max value and increment amount for a numberpad.
- EditorCheckboxOptions: sets return integer value to define whether a checkbox returns true/false or 1/0.
- EditorDropDownOptions: sets the width for a drop-down box.
- EditorTextBoxOptions: sets the width and error display for a textbox.
- EditorEnumDescription: used on enum values to define human-readable descriptions or to ignore the value altogether.
Custom Type Example
Here is an example type that will show up in the editor (in the Content Repository panel), that can be added to the scene (by dragging-dropping onto a Scene Group) and will have its property editable. Note that it has two properties but only one of them is visible to the editor.
[Serializable]
[EditorCreatedObject]
public class MyCustomEntity : SceneEntity
{
private float _MyValue;
[EditorProperty(true, Description="My Value", ToolTipText="This is the tooltip")]
public float MyValue { get { return _MyValue; } set { _MyValue = value; } }
//This Property will not be displayed in the editor.
[EditorProperty(false)]
public bool SomeBoolean { get; set; }
public override void SetObjectData( SerializationInfo info, StreamingContext c )
{
base.SetObjectData( info, c );
SerializationHelper.DeserializeField( ref _MyValue, info, "MyValue", true );
}
public override void GetObjectData( SerializationInfo info, StreamingContext c )
{
base.GetObjectData( info, c );
info.AddValue( "MyValue", _MyValue );
}
}

Create Your Own Custom Types
Check out these latest features in SunBurn 2.0.11 and we hope they give you the tools you need to expand the editor to suit your needs. As always, any questions are welcome (that's what we are here for). Now create your own custom types and make some amazing scenes!
Posted
02-04-2011 8:16 PM
by
Ross "FiveSidedBarrel"